Create & Populate a VHD with Data from a Host Folder

virtual machineWell, hey there! It’s been a while since my last post. I was promoted a few months ago to Infrastructure and lately find myself dealing with less SharePoint and more Virtualization. (Hooray for me!) So, I thought we would go all Tarantino on this edition of Steve Writes a Blog and start with the ending first.

‘Your new Virtual Hard Disk, which has already been populated with the necessary data, is ready to be mounted in the VM.’

Wow, that doesn’t make any sense without context… (Tarantino, take a hint!) So, let me back up a bit here.

I found myself needing to move data that resided on SAN drives in a VM to a local VHD on a different Hyper-V Host. There are multiple tools and methods for this, but I just wanted to keep it simple and copy the files. I could see these steps being useful for new builds as well, when data is needed on a VM before networking might be configured, or on Test VM (as was my case) with no networking at all.

The solution I came up with is below. Steps have been tested on:

    • Windows 7 | Windows Server 2008 / R2
    • Windows 8 / 8.1 | Windows Server 2012 / R2

1. In the Microsoft world, they would like you to use Server Manager to go to Tools to go to Computer Management to click Disk Management.

  • Luckily there is an easier method via shortcuts (Learn’em and love’em, kids!) to open this. Press WinKey+R (opens a run Dialog), and type diskmgmt.msc. Tada!

2. Under Action, click Create VHD.

Create VHD

3. Fill out your VHD Properties

VHD Properties

  • Choose a location. Since I’m creating a VHD to copy SAN data to local Disks, I will choose the Virtual Hard Disks Path of my Virtual Machine.
  • Choose a VHD Size. That is a fairly straightforward request. Choose whatever is appropriate for you.
  • Select your VHD Format. Whenever 2012 or higher is in use and your other management tools don’t have conflicts with the VHDX format (Curse you outdated Virtualization Backup Platform!), do yourself a favor and use VHDX. For Microsoft’s oh so thrilling documentation on the matter, you can read this MSDN article for each major revision of Windows Server.
  • (Or I can save you the trouble…) Page 124 of the Performance Tuning Guidelines for Windows Server 2012 states, and I quote:

“The VHDX format also provides the following performance benefits (each of these is detailed later in this guide):

  • Improved alignment of the virtual hard disk format to work well on large sector disks.
  • Larger block sizes for dynamic and differential disks, which allows these disks to attune to the needs of the workload.
  • KB logical sector virtual disk that allows for increased performance when used by applications and workloads that are designed for 4 KB sectors.
  • Efficiency in representing data, which results in smaller file size and allows the underlying physical storage device to reclaim unused space. (Trim requires pass-through or SCSI disks and trim-compatible hardware.)

When you upgrade to Windows Server 2012, we recommend that you convert all VHD files to the VHDX format due to these benefits. The only scenario where it would make sense to keep the files in the VHD format is when a virtual machine has the potential to be moved to a previous release of the Windows Server operating system that supports Hyper-V.”

Not only does Microsoft recommend it, but it has proven in multiple Companies Lab tests to provide better performance, including our own Lab, but that’s for another blog…

    • Choose your VHD Type. Since this drive will be in use on a SQL Server Virtual Machine, I am using Fixed to provide better performance.

4. Once you click OK, you’ll see the progress of the VHD Creation in the lower right of the Disk Management Windows. Go grab some coffee – this will be a few minutes depending on how large you chose to create your VHDX.

progress of the VHD Creation

5. After the Creation is complete, your new VHD will automatically appear in the Disk Management Window as an Unknown, Unallocated Disk. To become acquainted, select the disk – right click – Initialize Disk.

Initialize Disk

  • Choose your Partition Style (MBR is a good choice), and click OK.
    Partition Style

 

6. To assign a Drive Letter, right click the Unallocated Volume, click new simple volume, set the Volume Size (all available is default), and assign the Drive letter.

  • It’s going to ask you to format this shiny new Volume. Choose your settings, and click Next and Finish. (The Volume is already empty, so quick format will be fine.)
    New Simple Volume Wizard

7. Your VHD is now attached to your Host and ready for files to be copied into it. At this point, you can do the needful. Once your files are copied, take the disk Offline to stop all activity to it and then Detatch VHD.

Detatch VHD

Your new Virtual Hard Disk which has already been populated with the necessary data is ready to be mounted in the VM.

Thanks as always for reading! If you enjoyed this blog, make sure you Link IT. Like IT. Subscribe IT!

2015-04-20T09:16:57+00:00 April 20th, 2015|

Leave A Comment