17

It's quite easy to backup a real drive to VHD, e.g. with Sysinternal's Disk2VHD on XP or with Windows Image Backup on Windows 7. But how do I copy that file back?

It's possible by booting a recovery CD or the Windows installation DVD. But can it also be done from a running operation system? Can it be scripted?

We want to clone a drive to another drive daily using this.

Christian
  • 1,033
  • 5
  • 16
  • 24
  • 1
    You just want to use the VHD as an exchange format? Without ever running it in a virtual machine? Then use imaging software like Clonezilla, Norton Ghost or Acronis True Image. – mailq Aug 02 '11 at 15:57
  • 4
    Microsoft chose VHD as it's image format for any kind of activity: They use it for backups and in Win 7 you can mount them directly. The question how to RESTORE a backup is surely okay! – Christian Aug 04 '11 at 06:35

12 Answers12

9

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
mwfearnley
  • 757
  • 9
  • 21
Mehmet Sahin
  • 91
  • 1
  • 2
6

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.

mailq
  • 16,882
  • 2
  • 36
  • 66
3

Use HDDGuru Raw Copy Tool

  1. Mount the VHD(X) using explorer on Windows 8/10
  2. Plug in the target disk
  3. 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.

Adarsha
  • 274
  • 2
  • 5
  • 1
    Can single partition be selected in Raw Copy Tool as target? I see it allows only overwriting the whole disk – Suncatcher Apr 21 '19 at 17:18
2

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.

rmil
  • 27
  • 1
1

I once achieved this using a rather long way. Created a Hyper-v vm using existing vhd file and when it booted up ran a Windows Image Backup to create a bootable Image and copied the output folder to an external USB hdd. Then on target computer plugin the external usb Hdd, but boot from an ISO on DVD or Stick and choose "Restore from image" and point to the image folder location on the external USB hdd. The image will be restored.

Sibs
  • 11
  • 1
1

qemu-img command which is part of the QEMU emulator package supports VHD. I do not know if this works on Windows but on Linux at least it does (I suppose it does not matter as you did not tag your desired platform?).

To restore image.vhd to /dev/sda, run:

qemu-img convert -f vpc image.vhd /dev/sda
snap
  • 1,201
  • 9
  • 17
1

I have used vmdk2phys to successfully accomplish this.

There's another tool called Disk Image Tools or DITOOLS, which purports to do the same.

As others have stated, acronis true image can do this. Western Digital has a version of acronis true image that works on any computer with at least one WD hard drive installed called Acronis True Image WD Edition, however I am unsure if it supports Virtual Machine Hard Disk Images such as VHD/VMDK.

Another option is to mount the vhd in the Disk Management MMC, and then use a tool such as Roadkil RawCopy.

1

There is a program called VHD2disk that will do this but as earlier posts mentioned it needs to be run from within windows. I have successfully used HIRENS PE10 which boots a windows 10 environment off flash drive or DVD. I have also successfully cloned and imaged using this approach.

The VHD2disk utility unlike DISk2VHD is not produced by sysinternals, but still works well. (BTW I was having trouble finding it on Google last I just checked - that is how I ended up here)

0

Not aware of a free way but I know one of Acronis's products ('True Image'?) can do this.

Chopper3
  • 100,240
  • 9
  • 106
  • 238
0

Convert the disk using the plethora of vhd to vmdk convertors, such as this one: https://sourceforge.net/projects/vboxhdtools/

Then use this tool to convert to a physical drive (in windows): https://sourceforge.net/projects/vmdk2phys/

-1

If you are running win vista, 7, 8... You can use bcdedit. Paste your vhd file on c: Generate a new sid for your new machine Give the path to the vhd Activate the os Reboot and you ll have a dual boot with your new system. You re goin to work directly on your vhd image

-1

yes to summarise the best way is to use qemu-img like

  1. apt install qemu-utils

  2. qemu-img convert -f vpc image.vhd /dev/sda

  3. and mount the block device to file created.. mount /dev/sda /path/to/new_file_created

Now you can access the data new_file_created

dev/sda is your block device available and might need to be changed depending on your setup.

Dennis Nolte
  • 2,848
  • 4
  • 26
  • 36