Create a VHD file from a Linux disk

12,515

You wrote that "QEMU is a Linux package", but is not fully true anymore. One example of build of QEMU for Windows is as part of WinSetupFromUSB 1.8 program.

The other build of QEMU is in qemu-img for Windows.

The third build of QEMU is as mingw-w64-x86_64-qemu package.

Convert in Windows a RAW PhysicalDrive2 to VHD

qemu-img.exe convert -f raw -O vpc \\.\PhysicalDrive2 CentOS-5-8.vhd

Convert in Linux a RAW sdb to QCOW2

qemu-img convert -f raw -O qcow2 /dev/sdb fitsu_MKB3021LT.qcow2

Convert a QCOW2, RAW, VMDK or VDI image to VHDX

qemu-img.exe convert source.img -O vhdx -o subformat=dynamic dest.vhdx

Convert a QCOW2, RAW, VMDK or VDI image to VHD

qemu-img.exe convert source.img -O vpc -o subformat=dynamic dest.vhd
Share:
12,515

Related videos on Youtube

JezB
Author by

JezB

Updated on September 18, 2022

Comments

  • JezB
    JezB almost 2 years

    I have a disk containing CentOS 5.8 that was removed from a dead box. I would like to make a VHD file from this disk so I can run a virtual machine (instead of a new physical machine).

    The Virtual Machine host is a Windows 2008 Server running VM Virtual Box.

    I can't use disk2vhd (because this is a Windows program & Windows cannot 'see' the volume (it's attached by a USB adapter & the disk is visible in Disk Management)

    I've tried the dd method specified in https://superuser.com/questions/410940/how-to-create-vhd-disk-image-from-a-linux-live-system, but the VHD's don't boot once created.

    Does anyone have any ideas?

    Thanks

    • Dmitry Grigoryev
      Dmitry Grigoryev about 9 years
      I have done a similar thing with QEMU, and it worked. Do you still have the raw image file? If you have a machine with QEMU, you could try to boot your image in QEMU, and if that works, convert the image to vhd using qemu-img.
    • JezB
      JezB about 9 years
      I don't have the image file yet...
    • Dmitry Grigoryev
      Dmitry Grigoryev about 9 years
      You've tried the dd method, right? What are the results? Did you manage to get myfile.dd or myfile.vhd?
    • JezB
      JezB about 9 years
      I got a myfile.dd which I converted to myfile.vhd - but it wouldn't book in VirtualBox...
    • Dmitry Grigoryev
      Dmitry Grigoryev about 9 years
      That's why I ask if you can install QEMU. QEMU is able to boot from a device file (qemu -hda /dev/sda) or from a raw image (qemu -hda myfile.dd). This way you could see at which point your system loses the ability to boot.
    • JezB
      JezB about 9 years
      QEMU is a Linux package - I need a Windows program...
    • Dmitry Grigoryev
      Dmitry Grigoryev about 9 years
      You won't have to run your virtual machine in QEMU all the time. Once you get it booting you will export the image to VHD format using qemu-img and (hopefully) run it in Virtual box on your Windows machine.
  • Dimitrios Desyllas
    Dimitrios Desyllas over 3 years
    If I zerofill first the disk via dd will the process go bit faster? I mean if disk is 40G it will take some time
  • md2k7
    md2k7 about 3 years
    Tip: Convert to qcow2 first, then convert from qcow2 -> vhdx to compress away zeros. Before that, use zerofree to explicitly write zeros into an ext* filesystem.
  • felixyadomi
    felixyadomi about 3 years
    How do I know on windows that my raw drive is PhysicalDrive2 ?
  • wbkang
    wbkang about 3 years
    @felixyadomi you can use Get-PhysicalDisk on powershell to get the number.
  • W.Prins
    W.Prins over 2 years
    On Ubuntu (and presumably Debian), the linux package containing "qemu-img" is "qemu-utils" and therefore can be installed with the command "apt install qemu-utils".