How can I copy a VHD image back to a physical disc?
You can use qemu-nbd
in Linux to access a disk image as if it were a block device.
Here are some examples of operations that can be performed from a live Knoppix terminal.
su
modprobe nbd
qemu-nbd --read-only --connect=/dev/nbd0 --format=vpc <vhd_file_name>
If VHDX format:
qemu-nbd --connect=/dev/nbd0 --format=VHDX <vhdx_file_name>
ddrescue --verbose --force /dev/nbd0 /dev/sda # write image to /dev/sda
Write one partition:
qemu-nbd --partition=2 --read-only --connect=/dev/nbd2 --format=vpc <vhd_file_name>
ddrescue --verbose --force /dev/nbd2 /dev/sda2 # write partition 2 of image to /dev/sda2
Mount partition:
qemu-nbd --partition=2 --read-only --connect=/dev/nbd2 --format=vpc <vhd_file_name>
mount /dev/nbd2 /mnt
Unmount and disconnect image file:
unmount /mnt
qemu-nbd --disconnect /dev/nbd2
There are at least two similar questions that got accepted answers:
https://superuser.com/questions/40294/copying-a-vhd-to-a-physical-disk
Vdisk (vhd) to physical
But you can't do it from a running OS.
It would be a hard thing to script this. Following the Linux dd
aproach one could say that everything is possible. Boot from PXE, locate the VHD, locate the physical disc, dd from V to P, when finished reboot.
Use HDDGuru Raw Copy Tool
- Mount the VHD(X) using explorer on Windows 8/10
- Plug in the target disk
- Use the Raw Copy tool to copy the mounted disk to target physical disk
This can be used for any of the mountable formats on Windows, iso, vhd, vhdx etc.
It is possible to use Virtualbox to attach a physical device as a virtual device inside the VM
Windows method
VBoxManage internalcommands createrawvmdk -filename "C:\Users\vhudson\VirtualBox VMs\usb.vmdk" -rawdisk \\.\PhysicalDrive1
Linux method
VBoxManage internalcommands createrawvmdk -filename usb.vmdk -rawdisk /deb/sdb
Using an additional iso as live CD something like hirens boot or some linux rescue image, it is also possible to do image copying from one virtual device to a physical device that is virtually present inside the virtual machine.