{"id":663,"date":"2009-10-13T18:51:20","date_gmt":"2009-10-13T18:51:20","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/heaths\/2009\/10\/13\/booting-windows-to-a-differencing-virtual-hard-disk\/"},"modified":"2019-02-17T15:29:48","modified_gmt":"2019-02-17T22:29:48","slug":"booting-windows-to-a-differencing-virtual-hard-disk","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/setup\/booting-windows-to-a-differencing-virtual-hard-disk\/","title":{"rendered":"Booting Windows to a Differencing Virtual Hard Disk"},"content":{"rendered":"<p>Testing software can be fun and rewarding. You get to see new, upcoming features and provide valuable feedback to the developer. But as with most pre-release software, we recommend that you don\u2019t install it on production machines. You could dedicate extra machines for testing, or even test in a virtual machine. Virtual machines are great for testing operating systems and applications, and maximizing system resource usage. You can even take snapshots of the system disk and memory states and roll back to previous states.<\/p>\n<p>Besides requiring additional memory and processor time, another problem with virtual machines is that they run under a standard configuration of a basic display driver and no sound driver in Hyper-V. All your other devices attached to your machine are not always accessible, including your graphics card that provides a nice Aero glass experience in Windows Vista and Windows 7.<\/p>\n<p>But by installing Windows to a <a href=\"http:\/\/technet.microsoft.com\/bb738373.aspx\">virtual hard disk<\/a> (VHD) \u2013 the same format used by virtual machines \u2013 and creating a differencing disk on top of that you can test multiple configurations on the same base platform. You can choose with physical or virtual hard disk to boot and also take advantage of all the system devices your machine has to offer.<\/p>\n<h3>Step 1 (Optional): Partition your hard disk to store your VHD files<\/h3>\n<p>If you already have installed Windows Vista or Windows 7 and have plenty of free space on your system partition or in another partition \u2013 almost twice the amount of the virtual partitions you want to create \u2013 you may proceed to step 2. This step is useful if you want to install only to VHD files on your machine.<\/p>\n<p>You\u2019ll need to create a partition to store the <a href=\"http:\/\/technet.microsoft.com\/library\/cc770770.aspx\">boot configuration data<\/a> (BCD) as well as the virtual hard disk (VHD) files. These can exist in the same partition, but Windows will typically create separate partitions as you see in the screenshot below. This also allow you to encrypt the system partition with <a href=\"http:\/\/technet.microsoft.com\/windows\/aa905065.aspx\">BitLocker drive encryption<\/a> (BDE) while maintaining a boot-readable partition.<\/p>\n<ol>\n<li>Insert your Windows Vista or Windows 7 installation disk. <\/li>\n<li>Proceed through the installation wizard until you see the installation type selection dialog which reads, \u201cWhich type of installation do you want?\u201d Click <b>Custom (advanced)<\/b>. <\/li>\n<li>Select the unallocated space and click the <b>New<\/b> button. Windows installation will warn you that it will create another partition. This will appear as \u201cSystem Reserved\u201d. <\/li>\n<li>Select the other partition and click the <b>Format<\/b> button. <\/li>\n<li>Press Shift+F10 to bring up a command prompt. <\/li>\n<\/ol>\n<p><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot05.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image002\" border=\"0\" alt=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/heaths\/wp-content\/uploads\/sites\/13\/2009\/10\/clip_image002_d57d9876-528b-4903-a4ce-2f3fccd6caac.jpg\" width=\"244\" height=\"184\" \/><\/a><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot06.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image004\" border=\"0\" alt=\"clip_image004\" src=\"https:\/\/devblogs.microsoft.com\/heaths\/wp-content\/uploads\/sites\/13\/2009\/10\/clip_image004_0b15b71f-11ed-4c7d-8236-0a234319c58e.jpg\" width=\"244\" height=\"184\" \/><\/a><\/p>\n<h3>Step 2: Create the VHD file<\/h3>\n<p>You\u2019ll create a base virtual hard disk (VHD) in a partition with enough space available to hold the base installation and the differencing disk. This should be roughly twice the amount of space you pass to the \u201cmaximum\u201d argument in the steps below. The number you pass to the \u201cmaximum\u201d argument is in MB. A typical Windows 7 (x86) installation with a half-dozen or so driver updates and <a href=\"http:\/\/www.microsoft.com\/forefront\">Microsoft ForeFront<\/a> took a little over 6GB before being compressed.<\/p>\n<p>You\u2019ll create an expandable VHD as the base since it won\u2019t be modified when booting to a differencing VHD. The installation will take a little longer since the VHD will be expanded as necessary, but this will result in a small base VHD instead of wasting unused space for a fixed VHD.<\/p>\n<p>For the following steps, if you\u2019re already logged into Windows Vista or Windows 7 you\u2019ll need to open an elevated command prompt. If you\u2019ve completed step 1, you continue in the command prompt you already opened.<\/p>\n<ol>\n<li>In the command prompt, type the following commands. Substitute the path to the VHD with a path of your choosing. You may also specify a different size (in MB), but make sure the partition you create them in contains about twice the space you specify. <\/li>\n<\/ol>\n<blockquote>\n<p><code>diskpart      <br \/>create vdisk file=C:Win7-base.vhd maximum=65536 type=expandable       <br \/>select vdisk file=C:Win7-base.vhd       <br \/>attach vdisk       <br \/>exit<\/code><\/p>\n<\/blockquote>\n<ol start=\"2\">\n<li>Switch back to the installation wizard and click the <b>Refresh<\/b> button. <\/li>\n<li>Select the new unallocated partition and click <b>Next<\/b>. You may see a warning that reads, \u201cWindows cannot be installed to this disk. (Show details)\u201d but can often safely ignore this. <\/li>\n<\/ol>\n<p><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot11.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image006\" border=\"0\" alt=\"clip_image006\" src=\"https:\/\/devblogs.microsoft.com\/heaths\/wp-content\/uploads\/sites\/13\/2009\/10\/clip_image006_baadb585-6f22-43bb-8de7-8509804767b6.jpg\" width=\"244\" height=\"184\" \/><\/a><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot13.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image008\" border=\"0\" alt=\"clip_image008\" src=\"https:\/\/devblogs.microsoft.com\/heaths\/wp-content\/uploads\/sites\/13\/2009\/10\/clip_image008_093560bc-79a5-4552-a45d-239b9d40401b.jpg\" width=\"244\" height=\"184\" \/><\/a><\/p>\n<h3>Step 3 (Optional): Update drivers and install minimal software<\/h3>\n<p>After the installation has finished and you have logged in, you may want to update or install additional drivers for your hardware. You might also consider installing a minimal amount of software like a virus scanner. This will yield a smaller differencing disk.<\/p>\n<p>For example, with virus software there are program files that need to be installed. Incremental updates may be provided for virus definitions. By installing the virus software first before creating the differencing disk, o\nnly definition updates will be contained within the differencing disk.<\/p>\n<p>If you have installed the same Windows version that was already installed on another partition (if any) you may also have duplicate boot entry descriptions. You can rename the VHD boot entry to be unique.<\/p>\n<ol>\n<li>Type the following in an elevated command prompt.<\/li>\n<\/ol>\n<blockquote>\n<p><code>bcdedit \/v<\/code><\/p>\n<\/blockquote>\n<ol start=\"2\">\n<li>Find the boot entry where the value of the \u201cdevice\u201d data type reads \u201cvhd=C:Win7-base.vhd\u201d. Copy the GUID value of the \u201cidentifier\u201d data type. If quick edit isn\u2019t enabled for the command prompt, right click and select <b>Mark<\/b>. Highlight the GUID \u2013 including the curly braces \u2013 and press <b>Enter<\/b>. An example GUID looks like {f7bc2aa7-8ca2-11dc-936e-edd86d023230}.<\/li>\n<li>Type the following commands into the command prompt. Replace <i>{guid}<\/i> below with the GUID you copied above.<\/li>\n<\/ol>\n<blockquote>\n<p><code>bcdedit \/set <i>{guid}<\/i> description \u201cWindows 7 (VHD)\u201d<\/code><\/p>\n<\/blockquote>\n<p>Finally, you may wish to run Windows Update one last time before attempting to reduce the VHD file size. Be sure to reboot so that any changes made to disk after the reboot are contained within the base VHD.<\/p>\n<h3>Step 4 (Optional): Reduce the base VHD file size<\/h3>\n<p>If you wish to reduce the amount of physical disk space consumed by the base VHD, you can attempt to reduce space within the VHD and then compress it from another Windows installation. It\u2019s interesting to note that if you are viewing the VHD file on a separate partition while booted into the VHD file, the file size will appear to be the maximum size of the VHD. If you created an expandable disk as described in these instructions that is not accurate. You will see the correct file size when booted into a different partition.<\/p>\n<p>You might also wish to <a href=\"http:\/\/support.microsoft.com\/kb\/307886\/\">relocate the paging file<\/a> to the physical hard disk to reduce space consumed in the base VHD and reduce changes in the differencing VHD.<\/p>\n<ol>\n<li>While booted to the VHD, click the <b>Start<\/b> button.<\/li>\n<li>Type \u201cDisk Cleanup\u201d (without quotes), right click on program shortcut, and click <b>Run as administrator<\/b>.<\/li>\n<li>Select the VHD drive letter and click the <b>OK<\/b> button.<\/li>\n<li>Check all the options under \u201cFiles to delete\u201d and click the <b>OK<\/b> button.<\/li>\n<li>Click the <b>Start<\/b> button again.<\/li>\n<li>Type \u201cDisk Defragmenter\u201d (without quotes) and select the program shortcut.<\/li>\n<li>(Optional) You might want to click the <b>Configure schedule<\/b> button and disable automatic defragmentation. While booted into a differencing VHD, defragmenting the disk can lead to a big increase in the differencing disk size.<\/li>\n<li>Click the <b>Defragment disk<\/b> button and wait for defragmentation to complete.<\/li>\n<\/ol>\n<p>If you have formatted the VHD as NTFS (default for Windows Vista and Windows 7) you do not need to run the Virtual Disk Precompactor that ships with Virtual Server and Virtual PC. This may help for FAT-formatted partitions, though.<\/p>\n<p>After you have defragmented, reboot into a different partition. You may boot into Windows and open an elevated command prompt, or start Windows installation and open a command prompt as described in step 1. Type the following commands.<\/p>\n<blockquote>\n<p><code>diskpart      <br \/>select vdisk file=C:Win7-base.vhd       <br \/>compact vdisk<\/code><\/p>\n<\/blockquote>\n<p>This may take some time to complete, but you should notice a decrease in file size of C:Win7-base.vhd.<\/p>\n<h4>Step 5: Create the differencing VHD and configure the boot entry<\/h4>\n<p>Next you\u2019ll create a differencing VHD that will store all the differences between what you write to the disk and the base VHD. When you install software, it\u2019s all contained within the differencing VHD and the base VHD is not modified. You can even create multiple differencing VHDs and boot to each of them separately, or create a chain of differencing VHDs.<\/p>\n<p>In the following example you\u2019ll create a differencing VHD for installing Visual Studio 2010 Beta 2, but you could use any file name and path or install any software you like instead.<\/p>\n<p>You cannot be booted into the base VHD when creating the differencing VHD. If you have rebooted into another partition with Windows Vista or Windows 7, or into a Windows installation, do so now. Open an elevated command prompt as described in previous steps.<\/p>\n<ol>\n<li>Type the following into the command prompt. Substitute the path to the differencing VHD with a path of your choosing.<\/li>\n<\/ol>\n<blockquote>\n<p><code>diskpart      <br \/>create vdisk file=C:Dev10-Beta2.vhd parent=C:Win7-base.vhd       <br \/>exit<\/code><\/p>\n<\/blockquote>\n<ol start=\"2\">\n<li>Enumerate the existing boot entries. Find the boot entry where the value of the \u201cdevice\u201d data type reads \u201cvhd=C:Win7-base.vhd\u201d. This is the same GUID as the one you may have copied in optional step 3.<\/li>\n<li>Type the following into the command prompt. Replace <i>{guid}<\/i> below with the GUID you copied.<\/li>\n<\/ol>\n<blockquote>\n<p><code>bcdedit \/v      <br \/>bcdedit \/copy <i>{guid}<\/i> \/d \u201cDev10\u201d<\/code><\/p>\n<\/blockquote>\n<ol start=\"4\">\n<li>You\u2019ll see a message printed like, \u201cThe entry was successfully copied to {f7bc2aaa-8ca2-11dc-936e-edd86d023230}.\u201d Copy this new GUID and replace <i>{guid}<\/i> below with this new GUID when typing the following commands. The last command will set this boot entry as the default. You should not boot to the base VHD again or you will invalid the differencing VHD.<\/li>\n<\/ol>\n<blockquote>\n<p><code>bcdedit \/set <i>{guid<\/i>} device vhd=[locate]Dev10-Beta2.vhd       <br \/>bcdedit \/set <i>{guid}<\/i> osdevice vhd=[locate]Dev10-Beta2.vhd       <br \/>bcdedit \/default <i>{guid}<\/i><\/code><\/p>\n<\/blockquote>\n<p><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot21.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image010\" border=\"0\" alt=\"clip_image010\" src=\"https:\/\/devblogs.microsoft.com\/heaths\/wp-content\/uploads\/sites\/13\/2009\/10\/clip_image010_80393514-1743-407f-8009-69271ebddd82.jpg\" width=\"244\" height=\"184\" \/><\/a><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot23.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image012\" border=\"0\" alt=\"clip_image012\" src=\"https:\/\/devblogs.microsoft.com\/heaths\/wp-content\/uploads\/sites\/13\/2009\/10\/clip_image012_e9aa2e13-a03f-41d5-9b74-79bec536c578.jpg\" width=\"244\" height=\"184\" \/><\/a><\/p>\n<h3>Step 6: Install Visual Studio 2010<\/h3>\n<p>After you have rebooted the machine into the new differencing VHD you can begin installing software. In this example you\u2019ll install Visual Studio 2010. Download and run the web installer or insert your installation media and run setup.exe.<\/p>\n<p>Follow the installation wizard choosing either the default installation or a custom installation. After the install is completed explore the new features of Visual Studio 2010 and enjoy.<\/p>\n<p><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot25.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image014\" border=\"0\" alt=\"clip_image014\" src=\"\" width=\"244\" height=\"184\" \/><\/a><a href=\"http:\/\/cid-9415f61cbb1a8030.skydrive.live.com\/self.aspx\/Boot%20to%20VHD\/Screenshot32.jpg\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"clip_image016\" border=\"0\" alt=\"clip_image016\" src=\"https:\/\/devblogs.microsoft.com\/heaths\/wp-content\/uploads\/sites\/13\/2009\/10\/clip_image016_b7df365d-b984-44d6-87d1-a397b5c3857a.jpg\" width=\"244\" height=\"184\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Virtual hard disks are an integral part of virtual machines, but if you want to test on real hardware booting to a VHD is a good alternative. <a href=\"http:\/\/technet.microsoft.com\">Microsoft TechNet<\/a> has a lot of details about preparing, deploying, and booting to <a href=\"http:\/\/social.technet.microsoft.com\/search\/en-US?query=vhd\">VHDs<\/a>; and the <a href=\"http:\/\/blogs.technet.com\/virtualization\">Microsoft Virtualization team blog<\/a> has <a href=\"http:\/\/blogs.technet.com\/virtualization\/archive\/2009\/05\/14\/native-vhd-support-in-windows-7.aspx\">more great information<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Testing software can be fun and rewarding. You get to see new, upcoming features and provide valuable feedback to the developer. But as with most pre-release software, we recommend that you don\u2019t install it on production machines. You could dedicate extra machines for testing, or even test in a virtual machine. Virtual machines are great [&hellip;]<\/p>\n","protected":false},"author":389,"featured_media":3843,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[39,43,44,45,63],"class_list":["post-663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-tip","tag-virtualization","tag-vista","tag-visual-studio","tag-windows-7"],"acf":[],"blog_post_summary":"<p>Testing software can be fun and rewarding. You get to see new, upcoming features and provide valuable feedback to the developer. But as with most pre-release software, we recommend that you don\u2019t install it on production machines. You could dedicate extra machines for testing, or even test in a virtual machine. Virtual machines are great [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/users\/389"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media\/3843"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}