Native VHD Boot to Windows 7

25

Now we have native supported VHD in Windows 7, so what are we going to do about it? One use I found very useful is to native boot to a Windows 7 installed VHD. Why? because it allows me to have multiple Windows systems installed on my computer without using addition hard drives, playing around disk partitions, etc. So how? Here is a 1-2-3.

Step 1 – Create and Attach a VHD

You can simply follow my previous post how to create attach a VHD in windows 7, in which it describes two options to create a VHD natively in Windows 7.

Step 2 – Apply a Windows 7 image to the VHD volume

In order to natively boot to Window 7 image in the VHD file, you have to apply an image to the partition in the VHD. Running Setup from the install DVD and selecting a partition in a VHD for installation is NOT supported. You can simply use Install-WindowsImage Powershell script to apply the Windows 7 image for VHD boot. There is a step-by-step instructions on the site that describes in detail. Here is how in short.

First, have a Windows 7 distribution DVD ready, which contains two WIM files that this script needs to apply the image.

  • \sources\boot.wim, the WinPE image used for RAM disk boot to run Windows setup.
  • \sources\install.wim, the actual Windows 7 image file.

and, download the script from the MSDN code gallery, and save it in a location that you can use later.

Then, launch Powershell in administrator mode by right-clicking Powershell and choosing Run as administrator.

Then, using the following command to list the available images included in the \sources\install.wim image file.

PS >install-windowsimage.ps1 –wim d:\sources\install.wim (assuming the DVD media is in drive D:)

If you get an error that tells you unsigned scripts cannot be executed, see below.

image6 - Native VHD Boot to Windows 7

Run the following while you are still in Powershell to enable running unsigned local scripts.

PS > set-executionpolicy remotesigned

And, once you located the index number for the edition of Windows 7, run the following command to start applying the image to the VHD file. Change the index number and the destination drive letter to reflect your settings.

image7 - Native VHD Boot to Windows 7

Now you have a bootable Windows 7 installed VHD ready. It looks pretty complicated but believe me, it’s very straightforward. Just follow the instruction and you will be fine. Let’s move to the next step.

Step 3 – Configure the VHD for native boot

In order to natively boot to Windows 7 installed VHD, you need to update the boot configuration on your computer that hosts the VHD to add a new entry to the Windows Boot Loader.

Assuming you have VHD saved in D:\VHD folder, here is two steps to make it work.

First, generating a new entry by copying the current boot loader as following, which will also print out a new generated GUID which you will be using in the next command:

bcdedit /copy {current} /d “Boot Description“

And, update the entry by specifying the VHD path for OS to use.

bcdedit /set {GUID from last step} osdevice vhd=[DriveLetter:]\PathToVHD\VHD_File
bcdedit /set {GUID from last step} device vhd=[DriveLetter:]\PathToVHD\VHD_File

Once it’s done, type bcdedit and you will see something like this below:

image8 - Native VHD Boot to Windows 7

And you all set, reboot your computer and you will see two boot entries for you to choose. Select the VHD one and hit enter, and you will be seeing glowing Windows Logo in a few seconds.

If you have any question or are running into any trouble getting this set properly, feel free to leave in the comments below.

25 COMMENTS

  1. I followed your procedure (under windows 7), but I got:

    Windows Boot Loader
    ——————-
    identifier {96ffc112-8b7c-11de-ba40-8dcd7e725f2c}
    device vhd=[E:]7.vhd
    path Windowssystem32winload.exe
    description vhd
    locale en-US
    inherit {bootloadersettings}
    osdevice vhd=[E:]7.vhd
    systemroot Windows
    resumeobject {96ffc110-8b7c-11de-ba40-8dcd7e725f2c}
    nx AlwaysOff

    Which is not only different than your example, but worse, it doesn't work (I get an error message about an illegal entry in the bootloader of some sorts at boot time)

    • @wazzup, which version of Windows 7 are you running? It seems like that only ultimate and enterprise version of Windows 7 support native boot VHD.

      Cheers.

  2. Hello,

    I am getting an error while i am running de script…

    I have got : “… Unable to open/create .wim file … Error = 13” At C:/install-windows.ps1 : 805 char 27

    If you can help me would be great.

  3. I have been measuring the AC adapter with analog multitester, there indicate approximately 21vdc while behind the laptop shows 19vdc. is it normal? Besides the AC adapter, what I should check next ..?

  4. WOW. Intimidating, for the PS-noob. I have a question, re native vhd’s on bare-metal.

    I want to backup my vhd. I had win7 ultimate running, then my SSD died. Whist awaiting replacement, I installed a VHD on bare-metal. It died!

    So I’m copying dell drivers over to (hopefully) install in the right order, as I don’t know how to slipstream.

    My question is this: can a vhd be copied, on a certain day, and have it’s status preserved?

    I’d like to install all my drivers (and the very useful driver booster to get them updated) and install any “OS-management software” (AV, chrome, tune-up etc) then BACK UP.

    Any links / (ideally) steps (DO unmount or bcd/easybcd/visual bcd…) VERY welcome.

    Many thanks, Jonny ‘burnt fingers

    • The quick answer is yes. But in order to do so, you will need to boot into another OS, such as VHD-boot #2, and back up the first VHD disk. After all, it’s just a huge file on your hard drive.

      I also recommend referring to this article (http://www.nextofwindows.com/native-vhd-boot-to-windows-8-1-preview-dual-boot-with-windows-8-or-7/) when setting up VHD boot. It’s much easier and doesn’t need to deal with the BCD. It works in both Windows 8 and 7.

      • Perfect. I guessed the file couldn’t be in use (attached/mounted), my method (clean install) has been (win7installUSB) boot to (shift+f10) cmd to run diskpart, to

        1) clean the physical drive and format it’s primary partition (the same partition that the VHD is sitting on: is this a problem? ie can several VHD inhabit the same bootable partition? http://i.imgur.com/NdJH1JI.png)

        2) exit diskpart to make a directory on the new drive (ie, on C:md vhd,
        3) run diskpart again, to create and attach the vdisk to install (windows) to…

        I have one more question, before reading your link (thank you): it’s a hypothetical… picture the scene, if you will…

        You have multiple (bcd?)boot entries, pertaining to various vhd files, or virtual operating systems…

        One of these boot options is for a setup (win 7). You’re about to venture into the unknown, and there’s a strong chance you won’t be coming back…

        Is is possible to copy the VHD (perhaps outside the OS/VHD in question) and then simply rename the VHDs, essentially swapping them, to undo any changes made?

        Just an idea(one of many ! 🙂

          • SUPER cool. I’m posting back here because… I love plain English, and am digging the answers I’m getting…

            OK, in the past I ran into problems with my native VHD (with the old-school setup, http://i.imgur.com/fedGAkH.png)

            I tried to defrag, but the VHD consumed ~90% of the partition’s capacity, so I thought I’d have to detach and shrink and vhdresize the VHD. Lots of time spent trying to find a bootable tool (UBCD defraggler?) that would aid me in my quest to debug OUTSIDE the OS (VHD)… I failed, the VHD ceased being bootable, and now I’m on my third strike, hence my “treading with caution”

            I mention the above because again I’m in a similar position (about to resize a VHD so there’s room to fit a copy of it on. Original’s 100gig, on a 200gig partition, but the VHD has 78.5 gig free)

            MY QUESTION IS THIS!!!!

            Is it safe/adviseable to shrink the (NATIVE VHD) volume (containing OS IN USE) via diskmgmt.msc?

            http://i.imgur.com/MEjouBh.png

            (I imagine some time would be save if shrinking can be done ‘on the fly’, as oppose to reboot OUTSIDE vhd, detach, shrink, reboot, VHD resize…)

            T H A K Y O U (for ANY opinions/advice/etc)

          • I don’t recommend shrinking any of the disk volumes. Having a bigger space in HD just always sounds a better option. For creating VHD though, I always recommend starting low because it’s just so easy to expand the size later on.

          • Copying the vhd didn’t work. I thought I’d be able to robocopy it from cmd outside VM, reboot, and attach the (copied) VHD, but it asks to initialise the disk…

            Is there a way to copy the VHD? Do I need to copy in binary mode?

            Thanks again

          • I think the problem was that I was trying to attach the copy while the original was also attached and in use. The result was the (unallocated space) msg when attaching. The same happens if you boot into another vhd, mount the copy and try and mount the source.

            I deleted the robocopied vhd before knowing whether or not it was good, but I assume it was good (the windows explorer copy didn’t take as long as I feared)

            The free space reportedly available on the volume containing (expandable) VHDs will be

            capacity – contents, where (current) vhd is expanded.

          • I agree with EVERYTHING Kent says 🙂

            VHD Resizing is finnecky. I’ve made resized VHD, ready to delete the original (fat) VHD – moving towards differencing (hopefully!!) so smaller base (parent) is the way to go. Extending seems like a one-step process (maybe? please confirm is known, ie diskmgmt context on volume or is diskpart is needed)

            Thanks Kent. so pleased to learn that VHDs CAN be copied (as expected!)

            Updating BCD is easy to point to new:

            bcdedit /copy {id} /d “new description for copy”

            (This generates a {newID} for the new entry. copy it!)

            bcdedit /set {newID} device VHD=[drive:]path
            bcdedit /set {newID} OSdevice VHD=[drive:]path

            (press up before the last command, to edit the penultimate, append ‘device’ with ‘OS’)

          • Thanks. I finally completed the VHD-resize (my issues were due to signature collisions with the copy)

            Reading this, trying to “recover native VHD” (make bootable again) http://reboot.pro/topic/16141-troubleshooting-os-boot-from-vhd/) to try and understand what I need to do to make unbootable “Win7VHD” bootable again (like new “VHD (Win 7)”, in http://i.imgur.com/KXU0QWi.png, both attached VHDs)

            The first troubleshoot step is “install VPC and try and mount…”

            I thought that “native VHDs don’t boot in ‘hosts'” like Hyper, VBox + VPC, and vice-versa

            Re ‘missing bootmgrs’, the inverse is true –

            “Win7VHD” (recovered, full install, currently no ‘boot flag’):

            HAS hidden boot folder and bootmgr…

            NEW working “VHD (Win 7)” volume (using now)

            DOES NOT have boot folder in root, OR bootmgr

            (these are both present on the partition where the VHDs live, http://i.imgur.com/VHgXjhx.png)

            I’ve (manually) created BCD entries, I’ve read the ‘allow repair to run a couple of times’ advice … I don’t want to install VPC (unless I HAVE to) and I REALLY don’t want to run bcdboot (until I understand what it’s doing)

            As always, thoughts welcome

          • SYSTEM REPAIR = BEWARE

            again thwarted by ‘bad boot data’. RE the above, I tried to boot into my recovered VHD, I allowed system repair to try and … repair the system. It restored the system to it’s state PRIOR to

            cleaning disk 1
            fixing partitions (using Partition MAgic boot cD)

            essentially, it (apparently) wiped my new BCD data (rebooting gave me none of my newly configured BCD options to natively boot to VHD, the only installs I had)

            It reverted to fixing partitions to show a 700g HD as having > 1tb data (including unallocated space etc)

            I removed all this (only one, 300 g partition, containing VHDs) and have ‘system can’t boot’
            ******************************************************************
            by booting windows7Install and going to cmd, I can attach the vdisk(s) and assign.

            How can I make them bootable?!

            Tried BCD from scratch
            http://windowsitpro.com/systems-management/build-bootable-bcd-scratch-bcdedit

            tried fix with bootsect
            http://windowsitpro.com/systems-management/fix-unbootable-systems-bootsect

            nothing’s working.

            I’m now an expert at installing win7 to clean vhds on a clean disk.
            What I can’t work out is how to boot from a vhd on a ‘clean disk’

            how to fix bootmgr and bootloader and bootsect and MBR to make it work like it was… yesterday 🙁

            I tried “BCD from scratch” (http://windowsitpro.com/systems-management/build-bootable-bcd-scratch-bcdedit) but didn’t get any boot options on reboot.

            I tried fixing with bootsect (http://windowsitpro.com/systems-management/fix-unbootable-systems-bootsect) and, to my surprise, after attaching the vdisk, the commands

            bootsect /nt60 v: /mbr
            and
            bcdboot

            resulted in selectable boot entries… but still ‘windows can’t start’.

            is anyone very familiar with native boot from vhd (process/requirements/troubleshooting) that can suggest where to start to fix this?

          • re bootable VHDs, the ‘boot’ flag only shows on the active OS. I mounted vhds referenced and working in bcd, but they only have a ‘boot’ flag in diskmgmt if they are currently in use. very misleading, very red herring!!!!

            re unable to boot messages on all ‘fully installed native VHDs’, I found the problem, and the solution 😀

            Bcdedit.exe –set nointegritychecks ON didn’t work, but f8>disable enforcement fixed….

            On all (but my original) VHDs, booting once with noenforcement was enough to fix ‘unable to boot’… with the original VHD (now in use!!!) I have a corrupt user account (working on it) and another admin account (fresh), still working. from here I ran “sfc /scannow” and that fixed my bad ntoskrnl..

            Found MS Defender offline (think I may be infected, given my weird experiences) now working on a BCDboot from local IMG (tried using a 512mb SD card with bootsect’s and WinImage, but no go)

            Thanks again, will condense newly gleaned knowledge into helpful KB for future native VHD pioneers!!

LEAVE A REPLY

Please enter your comment!
Please enter your name here