Backing Up an SD Card or Hard Drive to A VHD File (Virtual Hard Disk)

 

The Microsoft Virtual Hard Disk – An Ideal Backup Image Format

Microsoft’s Virtual Hard Disks (VHD) are files that look like hard drives to a computer’s operating system. They are typically used for installing file systems on when working with virtual machines (including Microsoft’s own Hyper-V or Oracle’s Virtualbox) but can also be attached and used on a physical Windows 10 box so the Windows machine treats the file as a hard drive. As such, they are ideal to clone physical hard drives to as a method of backup. They work particularly well with multi-partitioned drives or SD cards, such as those used with Raspberry Pis. A full clone image works well over just copying files as it preserves the partitions and bootable formatting.

Backing Up A Raspberry Pi Drive to A VHD Image – Step By Step

If you have a Windows 10 computer, here’s a relatively simple way you can backup SD cards to a browserable VHD disk image that is not proprietary to your backup software.

  1. Attach the hard drive you are duplicating to your Windows computer. In my case I have a 150 GB external USB hard drive which serves as my Pi’s bootable drive. I detach that from the PI and insert the USB connection to my Windows computer.

    If you have an SD card you would need to attach the SD Card to you Windows computer using an SD Card reader.

  2. Open up Disk Management (right click on the Windows Icon in lower left corner->Disk Management). Alternatively press Windows Key-R, then type “diskmgmt.msc” and press enter.
  3.  

  4. Select “Action” in the menu, then “Create VHD”. If the Action menu items are grey, click first on something in the Disk Management window and then try again.

  5. When the “Create and Attach Virtual Hard Disk” window opens, click “Browse” to name your Virtual Hard Drive file and select the folder where it will be located. In addition, select the options shown below (VHD hard disk format, Dynamic/Expanding). The Dynamic disk option will save space on your physical hard drive . Fill in the “Virtual Hard Disk Size” with the size of the drive you are duplicating. Below I am duplicating my Raspberry PI’s 149.05 GB external USB drive that has a 256 MB bootable Fat 32 partition along with a 148.80 GB linux partition. If you are duplicating your PI’s SD card it will look similar but will be sized differently – it will have a FAT32 partition, as well as “Healthy (Primary Partition”) that is your Linux partition. Below is my example – the drive on the left is the source drive. The new Virtual Hard Disk we are creating will be the target cloned drive.

  6. When done select “OK”. You will see new drive in your Disk Management showing an “Unallocated” partition. On my system it shows up as Disk 8:

  7. Now open up your drive cloning software. I use the free MiniTool ShadowMaker Free 3.5. It is an excellent free backup tool for windows and includes a cloning tool.
  8. In Shadowmaker, I open the program and select Tools->Clone.

  9. I then select the Source (USB drive) and the target Destination (the unallocated Virtual Disk):

  10. Then Press “Ok” and confirm that the target Disk will be destroyed:

  11. ShadowMaker will then start cloning the disk (my clone took about an hour and a half):

  12. When done, ShadowMaker will ask if you want to shutdown, say “NO”:

  13. Now open up Disk Management again and confirm that the Virtual Drive is now correctly formatted and shows the partitions:

  14. Now, right click on the disk number (i.e., in the example, “Disk 7”) and select “Detach Virtual Drive”.

  15. You are done. The virtual drive file is now on your backup media having the extension “VHD”.

Restoring Entire Drive or Retrieving Backed Up Files

Anytime you need to restore it you just need to re-attach it and repeat the process, but reverse the cloning so the VHD is cloned to the physical hard disk. If you just need to copy some files off the VHD image, you can attach it and use it like any other hard drive, copying files off using Explorer. As an additional bonus, you can also attach the virtual drive to most virtual machines, including Oracle’s Virtual Box. You can also attach to a WSL session (at least WSL2) by attaching the disk in Disk Manager, assigning a letter to the Linux partition using Ext2 Filesystem Driver for Windows, and then opening WSL and typing “cd /mnt/[drive letter]”.

close

Leave a Reply

Your email address will not be published. Required fields are marked *

*******************************************************