1

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

JezB
  • 233
  • 2
  • 6
  • 11
  • 1
    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`. – Dmitry Grigoryev Apr 13 '15 at 12:45
  • I don't have the image file yet... – JezB Apr 13 '15 at 12:48
  • You've tried the [dd method](http://superuser.com/questions/410940/how-to-create-vhd-disk-image-from-a-linux-live-system), right? What are the results? Did you manage to get `myfile.dd` or `myfile.vhd`? – Dmitry Grigoryev Apr 13 '15 at 12:53
  • I got a myfile.dd which I converted to myfile.vhd - but it wouldn't book in VirtualBox... – JezB Apr 13 '15 at 13:06
  • 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. – Dmitry Grigoryev Apr 13 '15 at 13:14
  • QEMU is a Linux package - I need a Windows program... – JezB Apr 13 '15 at 13:43
  • 1
    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. – Dmitry Grigoryev Apr 13 '15 at 13:52

1 Answers1

4

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
user1742529
  • 101
  • 7
  • 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 – Dimitrios Desyllas Dec 31 '20 at 17:13
  • 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. – md2k7 Apr 02 '21 at 13:36
  • How do I know on windows that my raw drive is PhysicalDrive2 ? – felixyadomi Jun 13 '21 at 22:00
  • 1
    @felixyadomi you can use `Get-PhysicalDisk` on powershell to get the number. – wbkang Jun 27 '21 at 16:39
  • 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". – W.Prins Dec 13 '21 at 04:44