Installing a Fresh Windows OS to a New Bootable VHD with no Host OS for Boot to VHD | John Papa

John Papa

Evangelist on the loose

Installing a Fresh Windows OS to a New Bootable VHD with no Host OS for Boot to VHD

posted by John with 27 comments

I love the performance gains I get by using bootable VHDs. I’ve always enjoyed using VHDs but I generally had a host OS first, then installed a bunch of VHDs that I made bootable. Recently I’ve changed all of this on my laptop after a coworker took the time to show me a way with more flexibility (thanks Paul Stubbs!). The idea is simple: take a clean drive with no host OS and add or remove bootable VHDs as needed.

These steps describe steps that enable a few scenarios for me that allow me to:

  1. Install a fresh OS to a new bootable VHD with no host OS on the computer already
  2. Copy existing VHDs to my physical drive and make them bootable
  3. Boot to any of my VHDs and copy others on, or take some off

To be very clear, these steps are for taking a brand new hard drive or wiping a hard drive clean, and then installing a series of OS’s on VHDs that will boot from disk. The advantage of this is there is no host OS, you can have as many bootable VHDs that fit on disk, and they can be copied on and off the disk at will. I also use create differencing disks (I’ll get into that in another post).

I like this technique so I don’t have to rely on a base OS. This allows me to copy VHDs on my hard disk, add them to the boot record and run. Or I can install a new OS to a brand new VHD from a DVD, USB or network install. It’s very flexible and since the VHDs boot from the metal they are run very fast!

This creates a VHD on the metal, on you hard drive without needing a host OS.

NOTE: This post contains a lot of command line operations that are if typed incorrectly can wipe a hard drive, lose its data, and make it unrecoverable. Use these steps at your own risk, I am not responsible for the outcome. I am simply sharing what works for me.

I recommend using an SSD if you can. I have found that the performance differences of running off a traditional drive vs. a SSD are tremendous. They are pricey, but I’ve been able to upgrade to an SSD and give my laptop new life.

Install Windows 7 On a Completely Clean Drive, with No Existing OS

This cleans my hard drive and sets it up for my 1st VHD that will boot off the metal. These steps only need to be done once to clean the drive fresh. In fact, I don’t ever want to do this again to the drive because it wipes it completely clean (have I repeated that enough times yet? Can you tell I am very careful?)

  1. First, I need to have an OS to install.
    1. If installing from DVD/CD, I make sure the media is in the drive and the bios is set to boot from the optical drive. Then reboot
    2. If installing Windows 7 from USB, I make sure the USB is plugged in and the bios is set to enable USB boot. Then reboot
    3. If installing from the network, after reboot press F12 (if that’s my shortcut key to LAN install) and select the boot OS option.
  2. Once Windows Setup begins and prompts me to begin the installation, I press SHIFT-F10 to get to a command prompt. This is where I will create a VHD and then install the OS onto it.
  3. In the command windows, I enter the disk partitioning utility
    DISKPART
  4. Now I list the disks and take note of the disk number for the physical hard drive.
    list disk
  5. Assuming the disk was number 0, I select that disk.
    select disk 0
  6. Now I wipe the drive clean (all of my data on this drive will disappear). I do this so I can start fresh.
    clean
  7. Now my drive is clean and ready to be set up. Next I created a partition and formatted it with NTFS file system using quick format. I labeled it “256 GB SSD” so I would always know where the physical drive was. Then I marked it as an active system drive and assigned it a drive letter of C.
    create part primary
    format fs=ntfs label="256 GB SSD" quick
    active
    assign letter=c
  8. At this point I have a fresh drive ready for some VHDs! The next step could be to continue the install of the OS (see next section).

Install a Fresh Copy of Windows 7 on the Metal, in a Bootable VHD

If I followed the previous steps, I am still in DISKPART. If not, I would follow steps 1-3 in the section above first.

I repeat these steps whenever I need to install a new fresh OS. I can have as many as my drives fits.

  1. I start by creating a new VHD on the metal where the OS will be installed. It allows me to choose a fixed size or expandable virtual disk file.The advantage of using fixed is that it will always consume X amount of space and be able to boot. Expandable VHDs take up much less space when not used, but they need to have room to expand when they are booted into. I generally use expandable.
    create vdisk file=c:\win7.vhd maximum=50000 type=expandable
  2. Now I select the VHD, attach to it, create a partition on it, and format it. Then I marked it as an active system drive and assigned it a drive letter.

    select vdisk file=c:\win7.vhd
    attach vdisk
    create part primary
    format fs=ntfs label="Win7" quick

    active

    assign

  3. Then I exit from DISKPART and exit from the command prompt by typing exit,and exit. This brings me back to the Windows 7 install screen which is waiting for me.
  4. I can now proceed with installation, making sure I choose a custom installation when promoted. Of course, I have to choose the partition I just created. The installation of Windows 7 will happen on the VHD I just created and boot right off the metal. This process creates boot records for me, so I don’t need to create entries using BCDEDIT in the boot record manually which is nice.

Add an Existing VHD to Boot off the Metal

Sometimes I have an existing VHD that is ready to go and I want to copy it to my computer and run it off the metal. Here are the steps I use to do that. For these steps, I’ll assume I have a Windows 7 VHD with some cool demos on it called Win7MIX11.vhd.

  1. Boot into Windows 7 (for example, one of my bootable VHDs of Win 7)
  2. I copy the Win7MIX11.vhd file to the physical hard drive (might take a few minutes)
  3. Open a Command prompt using Run as Administrator
  4. I run the DISKPART utility
    DISKPART
  5. I attach to the VHD and exit the DISKPART utility
    select vdisk file=c:\Win7Mix11.vhd
    attach vdisk
    exit
  6. Now I make it bootable, making sure I use the drive letter that the VHD is attached to (I assume X here).
    BCDBOOT x:\Windows
  7. Next I create the boot records so this VHD will be in the list of boot options when I reboot the computer. First I copy a record and give it a name.
    bcdedit /copy {current} /d "MIX11 Demos"
  8. Then I take the GUID that the previous command created and I copy it to the clipboard. I will use this a few times in the next statements.
  9. I enter the follow commands in order, replacing the {myguid} with the GUID I copied to my clipboard a moment ago.
    bcdedit /set {myguid} device vhd=[locate]\Win7Mix11.vhd
    bcdedit /set {myguid} osdevice vhd=[locate]\Win7Mix11.vhd
    bcdedit /set {myguid} detecthal on
  10. Now I can reboot and my Windows 7 VHD for Mix11 demos should show up in my boot options as “MIX1 Demos”

Verification

Here is a screen capture of my Windows Explorer when I am booted into one of my Win7 VHDs. The D: drive is my physical hard drive, my SSD. Now that I see this I realize I should have made that the C drive letter. Oops. Not a big deal obviously.Smile

Capture1

The C: drive is the VHD I am booted into. The total size of my 256 GB SSD is actually 238 GB of usable space. The “Win7 Papa” VHD is booted and is expanded to 50GB. That file exists on the physical SSD. Any other VHDs are also on the SSD. here is the SSD in Windows Explorer. Notice that my file Win7Personal.vhd is expanded to 50GB … this is the VHD I am currently running (which is why its expanded). The other file, win7-01.vhd, is another VHD that I can boot into. It currently takes up 11GB, tho it will also expand to 50GB when I boot to it (and if I do boot to it, the other VHD will no longer be expanded).

image

Here is what the Disk Management window shows for my laptop. Notice the SSD and the currently booted VHD show up here too.

image

Wrap Up

This has worked very well for me recently. In addition to Paul Stubb’s help, there are plenty of other resources on the web that I used to help me along, so I wanted to include some of them here too:

None of this is earth shattering, its all been done before. I was hesitant at first due to the nature of DISKPART and how a mistake can mean I wiped the drive clean. But recently I decided to upgrade to a new SSD and I had little risk because it was already a new drive. I f you intend on going this route, I recommend researching it first using some f the links I suggested above as well as my experience in this post. But also, make sure you only try this on a drive that is clean or you are OK with wiping clean.

tags: boot vhd windows

27 comments Hide comments

Laurent Bugnion on said:

Hey John,
AFAICS you have a typo in “create vdisk file=c:\win7.vhd maximum=50000, type=expandable”. There should not be a “,” after the 50000.
Cheers,
Laurent

Chris on said:

If I am reading this right, I can create a VHD, install my OS and setup my environment the way I want it. If I had to change machines all I would need to do is copy my VHD over to the new hard drive (after provisioning it)? That is very helpful if true. What would I lose in performance? Are there any other drawbacks? Great article!

KR on said:

Great post, great idea.
Could you install other OSes into VHDs and boot them as well, or does it have to be Win7?

Brian on said:

This sounds like something that one would want to practice a few times in a virtual machine using Virtual PC, VirtualBox, VMWare or whichever virtual machine manager that you prefer. That should help to prevent mistakes, and if you do make one while practicing, you can learn from it, instead of pulling your hair out or somesuch. Just my two cents, keep the change.

Jim on said:

The first thing you created on the disk was the 256 gig ntfs to which you assigned “C” which, after step 10, displayed as “D”. In “Verification” you stated that you “should have made that the C drive letter”. I’m a little confused as you DID make this the C drive letter. Can you please clarify?

john on said:

Chris wrote “If I am reading this right, I can create a VHD, install my OS and setup my environment the way I want it. If I had to change machines all I would need to do is copy my VHD over to the new hard drive (after provisioning it)? That is very helpful if true. What would I lose in performance? Are there any other drawbacks? Great article!”
Chris … You can copy the VHD elsewhere, but obviousyl if you’re drivers are different then you’ll have to account for that. What I generally do is keep a base OS handy and then use a differencing disk option. So yes, you can.
Drawbacks? I’ve heard there is like a 3% perf hit, but really, I have not seen anything noticable. Its been awesome for me.

john on said:

KR wrote “Could you install other OSes into VHDs and boot them as well, or does it have to be Win7?”
KR – You can do this with windows OS’s, though I have only done it personally with the popular flavors of Win 7 and Win 2008 Server too.

john on said:

Jim wrote “The first thing you created on the disk was the 256 gig ntfs to which you assigned “C” which, after step 10, displayed as “D”. In “Verification” you stated that you “should have made that the C drive letter”. I’m a little confused as you DID make this the C drive letter. Can you please clarify?”
Jim … sorry about that. When I ran my script originally I assigned the wrong letter. Thus my screencap shows D. But in the instructions in this post I assigned C. So i was just pointing out that my screen cap was wrong. Follow the instructions and you should be fine.

john on said:

Jaime wrote “What about bootable vhd and bitlocker ?”
Jaime … I run bitlocker on some of mine and not on others. So yes, you can run bitlocker on them. What I do is boot into the VHD I want bitlockered, then run bitocker on it. The net result is that when I get to my boot menu and choose a bitlockered VHD to boot, it prompts me for the pin. If I choose a non bitlockered VHD to boot, it wont prompt me. So yes, you can mix and match.

Henry on said:

This is all very nice. I’ve been using bootable vhd’s for a couple of years now. Recently I discovered there is a tool called VBoot, that lets you boot several operating systems, including windows, with the same modified GRUB bootloader. It’s not free for windows, but that can partly be mitigated by chainloading.

Matt Davidson on said:

Just wondering whether this is restricted to specific edition of Windows 7? I’ve just tried with Professional to receive a Licence error – boot from VHD not supported

john on said:

Matt — I believe boot from VHD is inly supported for Ult or Ent versions of Win 7, though I am not 100% positive.

BJ on said:

What about concerns that TRIM will not work on an SSD booted to a VHD? Within a booted VHD, the OS disk device type shows up as something like “Msft Virtualized SCSI Disk Device.” Several posts out there indicate that TRIM commands are not issued. Is this a concern? Is there a workaround?

Joe on said:

Hi John, this does not appear to work. I get a “Setup was unable to create a new system partition or locate an existing system partition” error. Any ideas?

Doug R on said:

This all worked great until I logged on for the first time. I got a license error – This system does not support booting fron VHD. Is this a Win 7 version problem? I installed windows 7 pro.

Sammy on said:

Very nice and helpfull post thank you for that! All the info to get it running :)

Les on said:

Well, the first time I played around with windows 7 , I did boot it from A USB HD/Flash Drive and created a VHD on the C drive. Worked fine for me.
What you describe here is called a”Native Boot” using VHD. Microsoft Explains this on their site. What you forgot to mention is that it can only be done on the upper versions of windows, like Windows 7 Enterprise, Ultimate, Windows Server 2008 R2, and Windows 7 Embedded Standard. Oh, and BitLocker doesn’t work on the VHD, MS says so, and I recall they listed some other things.
Check out Easy BCD Editor (GUI) .. It is a great tool.. for Booting IMAGES.. I boot ISO, IMG, VHD with it on Windows.
I used GRUB, Booted it from a FLOPPY DISK, had a USB Sniffer on it, located the USB Flash Drive and booted VMLINUX image (Damn Small Linux) on an Emachines 633ids that didn’t not SUPPORT USB booting in it’s BIOS.
That is why you should check out Easy BCD, it has a BIOS OVER-LAY (Extension) to boot from USB. It will boot MS VHD, RAW HD image, RAW Partition Image, ISO, floppy image. It does Windows, Linux, MAC OS Booting, and has NEOGRUB for Linux or Legacy Windows OS.
It has Various Linux Boot Loaders, 6, I counted.
Remember back in the day, Ontrack DiskManager had a BIOS Overlay to allow booting to Drives Larger than what the BIOS could Support? Well then, That is why I know Booting certain ways is doable, especially if you got the LINUX Software Supporters writing it and putting it out on the web. This is why many people who use Windows™ and then get exposed to LINUX™ will then say, MS. SUCKS, cause LINUX is like a cure for computer user who are functionally handicapped by using Windows. I know Linux doesn’t give you statements like, “Uh Oh!!!, This version doesn’t support installing on External USB Drive. Etc.. ” Ok, it doesn’t say Uh OH..
I don’t use Linux that much, I know the Live CD’s on 700MB CDs offer more than Windows does, and things are easier to find on the System and Categorized nicely and Linux finds software you may want on the web for you by offering you a list of Installed and not-Installed software for downloading, all in one list. And check it out, starting at Ubuntu 11, how they Made the taskbar better than windows 7, by scrolling it, instead of the way windows 7 does by doubling up the items in the taskbar..

Lee Pattison on said:

Hi i have Windows 8 RP installed as host but i have windows 7 as a VHD
Problem is Windows 8 will not boot no more but Windows 7 VHD does still work.
I want to keep the Win 7 VHD the new refresh feature will not work on Windows 8
I would like to know if i do a clean install of windows 8 will i lose my VHD if not can i just point the boot manager back to the Windows 7 VHD. How would i do that Thanks for any help.

Hardeep Johal on said:

Hi, using this method how can you run several o/s concurrently as i would need that for real world development.

Murat Ulubay on said:

Thanks John, a short question:

For the 3 commands “bcdedit /set {myguid}…” I used my own GUID and vhd filename but I get an error message for the name “MIX11 Demos” before booting, it seems that the system is confused about this name as an inconsistent thing. I used directly the same command in this page “bcdedit /copy {current} /d “MIX11 Demos” since I thought that it was just for displaying GUID of my Windows. But it seems that it has written that name there, before trying it I just want to ask, it seems to be the description of the OS in the VHD file is “Windows Server 2008 R2″ so using “bcdedit /copy {current} /d “Windows Server 2008 R2″ and then the “bcdedit /set {myguid}…” commands with my Guid, will fix the problem, what do you think?

Leave a Reply


(required)


(required)



*