Less Virtual, More Machine - Windows 7 and the magic of Boot to VHD
NOTE: This is some advanced stuff and you may lose a finger. No warranty express or implied. There's always workarounds somewhere on the 'tubes, but this stuff works only in Win7 or Windows Server 2008 R2. Be afraid.
I use a lot of Virtual Machines. I've used VMWare, VirtualBox, HyperV and Virtual PC. Recently, since all my machines have been updated to Windows 7 RC, I've downloaded Windows Virtual PC so I could use "Virtual XP." I've got a lot of VHD (Virtual Hard Drive Files) around now.
You can see here where I've got a VM called "Dev10onVista" because I can use not just Windows XP, but also Vista. However, it's still a VM and it's slower than I'd like.
Dan has a great post on the pros and cons of Virtualization vs. Dual Booting. He points out:
- Multiboot:
- Good performance (runs natively on the machine, no extra abstraction layers)
- Good hardware integration (everything that is built into or attached to the machine is visible to the running OS)
- Clunky setup (different boot loaders overwriting each other, partitions cannot easily be resized or moved around)
- Virtualisation
- Very flexible (only takes up as much hard disk space as the solution requires)
- Can run virtually any Operating System
- Non-Optimal performance (running piggyback off another Operating System, consuming resource in both)
- Marginal hardware integration (all major system components are virtual only; depending on the virtualisation solution, SOME components might be surfaced inside the virtual machine)
This is right on. I'm always afraid to multi-boot, concerned that one OS will some how make one of the others angry, as they are all sharing disks.
I'm just not willing to install VS2010 Beta 1 on bare hardware just now, as I know I'll want to put the Next Beta on a clean machine. I *could* sacrifice an extra machine, but I'd rather use the main machine I always use. I want less virtual, more machine.
Mounting/Attaching VHDs like Hard Drives
With Windows 7 I can mount VHD and use them like regular hard drives. Just type in "Disk Management" from your start menu. From the Action menu I can select "Create VHD" or "Attach VHD." Below I'd just attached a 7 GIG VHD file that thinks it's a 40 gig hard drive. Notice that the disk icon is blue. This is a really convenient way to just "pass a hard drive around as a file" as well as a nice way to get files on and off VMs that aren't running.
The best part is that I can make one of these during Windows 7 setup (NOTE: This is advanced and may hurt you, your computer, or your cat.) and install Win7 directly to it.
Install Windows 7 to a new, fresh VHD
Assuming you already have a Windows 7 installation, you can boot off the Windows 7 DVD, and when it gets to "Install Now" click "Repair Your Computer." Don't select an installation, then select Command Prompt. (You can also press Shift-F10) to open a command prompt.
From the Command Prompt, run "diskpart."
Make a new VHD on an internal fixed disk:
create vdisk file="C:\win7\win7.vhd" type=expandable maximum=50000
This will make an expandable VHD with a 50Gig max, for example. Now select it and attach/mount it:
select vdisk file="c:\win7\win7.vhd"
attach vdisk
Type "exit" and go back to the setup window and install Win7. Make sure you select the correct disk - the new virtual one!
Setting up your Windows Boot Menu to boot to an Existing VHD
If you have an existing Win 7 VHD already, or perhaps you've taking your Windows 7 installation Disc and "syspreped" a VHD image. Now, from an Administrator Command Prompt, you need to tell the Windows Boot Manager that there's another option. You go:
C:\>bcdedit /copy {current} /d "My New VHD Option"
This will return a GUID. Select it using the Mark command by right-clicking in the Command Prompt and copy it to the clipboard.
Now, using that {guid}, type these commands:
C:\>bcdedit /set {guid} device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set {guid} osdevice vhd=[driverletter:]\<directory>\<vhd filename>
C:\>bcdedit /set {guid} detecthal on
See the [driveletter:] stuff in brackets? It's NOT obvious, but you need to include those, so:
bcdedit /set {guid} device vhd=[C:]\win7\win7.vhd
You can confirm it's setup with bcdedit /v:. You'll see something like this. The interesting part is at the bottom.
Windows Boot Manager
--------------------
identifier {9dea862c-5cdd-4e70-acc1-f32b344d4795}
device partition=C:
description Windows Boot Manager
locale en-US
inherit {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}
default {34433bb7-628f-11dc-a941-001a6bcd5d3a}
resumeobject {34433bb8-628f-11dc-a941-001a6bcd5d3a}
displayorder {34433bb7-628f-11dc-a941-001a6bcd5d3a}
{280ffa1e-f8a9-11dd-b0a9-001c26fdc6b4}
toolsdisplayorder {b2721d73-1db4-4c62-bf78-c548a880142d}
timeout 30
custom:45000001 1
Windows Boot Loader
-------------------
identifier {34433bb7-628f-11dc-a941-001a6bcd5d3a}
device partition=C:
path \Windows\system32\winload.exe
description Windows 7
locale en-US
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {280ffa1b-f8a9-11dd-b0a9-001c26fdc6b4}
recoveryenabled Yes
testsigning Yes
osdevice partition=C:
systemroot \Windows
resumeobject {34433bb8-628f-11dc-a941-001a6bcd5d3a}
nx OptIn
custom:42000002 \system32\winload.exe
custom:45000001 2
custom:47000005 301989892
3
Windows Boot Loader
-------------------
identifier {280ffa1e-f8a9-11dd-b0a9-001c26fdc6b4}
device vhd=[C:]\VMs\Win7\Win7.vhd,locate=custom:12000002
path \Windows\system32\winload.exe
description Win 7 VHD - Dev10
locale en-US
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {280ffa1b-f8a9-11dd-b0a9-001c26fdc6b4}
recoveryenabled Yes
testsigning Yes
osdevice vhd=[C:]\VMs\Win7\Win7.vhd,locate=custom:22000002
systemroot \Windows
resumeobject {34433bb8-628f-11dc-a941-001a6bcd5d3a}
nx OptIn
detecthal Yes
custom:42000002 \system32\winload.exe
custom:45000001 2
custom:47000005 301989892
3
If it doesn't work, you can always run bcdedit /delete {guid} /cleanup and try again.
Here's what my Boot Manager (pressing F8 when I start up my machine) looks like now:
Now, I can boot up with my VHD mounted. Am I running a Virtual machine? No. I'm running Windows, on the hardware, with only the DISK Virtualized. I don't work for that team, but I'm guessing I'm losing 3-5% (that number came out of my butt) on the disk side - and nothing anywhere else. How do I know? Well, Windows Experience is smart enough to keep me from checking (although I could use another disk tester tool, but I'll leave that as an exercise to the Reader.).
I notice that Disk Management still gives me access to my was-C: drive, even though the VHD is now my C. My hardware C: drive got moved down, and it's E: now. Nice than I can still see it!
What does the Device Manager say? It says the Msft Virtual Disk SCSI Disk Drive is there! That's the only "virtual" thing going on here. Notice I've still got my actual Video Drivers (running multiple monitors across multiple display drivers). All my stuff is there, because I've got, forgive me, less virtual and more machine.
Hey, are those my four processors and my 8 gigs or RAM? Ah, yes, they are.
Love it. I'm going to use the hell out of it.
A few caveats. One, I haven't figured out how boot off a VHD that is on USB or External Drive. I'm looking into it. It may be because there's no drive letter assigned yet, or that I'm an idiot. We'll see. Second, doing this makes your VHD less portable, because if you move it inside Virtual PC or to another machine, all the devices will freak out and try to reinstall (or maybe just not work) so be aware of that.
That said, I'm running Visual Studio 2010 Beta 1 without fear on my awesome hardware with hardware-speeds. Shiny.
Related Links
- Using DISM if your VHD won't boot because of a storage driver requirement
- Video on Channel 9 - Boot from VHD
- Video with Mark Russinovich on Booting from VHD
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
This look amazingly useful!
Will definitely try this on my work laptop. The lack of noticeable performance drop is quite attractive. It's worth a reboot for legacy dev environments I rarely use.
Something for a future article: is is possible to easily do physical to virtual on Virtual PC? I've thought this could be handy to keep a copy of the installation when I rebuild my PC. If I leave behind some important file on the old machine, I can boot it up in Virtual PC to check.
The version of Windows 7 that does double duty as a Virtual machine and a real machine will almost undoubtedly run afoul of Activation and Genuine Advantage.
People do this right now using Windows XP under VMWare:
http://ubuntuforums.org/showthread.php?t=526207
If you can use your pull to get THAT problem solved without a headache, then you have really accomplished something. :)
Great post! I really like the bcdedit details you shared.
I have been dying to try Windows 7 RC on real hardware. Been playing with the Windows 7 Beta for a while in Virtual PC 2007 sessions but I know I wasn't getting a true test of it's capabilities.
I had seem some posts about the VHD boot support in Win 7 and some methods to dual boot with that method. However both my laptops are Vista and I really didn't want to pave them to make room for Win 7.
Eventually enough material was posted to allow me to hobble together swapping the vista boot loader file with the updated one in Windows 7 (which supports VHD booting).
GSD How To: Dual Boot Windows 7 on Vista via VHD file- shameless blog post self promotion.
I swapped them out, then created my VHD file and set it to be a boot option. Then I installed Windows 7 RC...but this time the 64-bit version for grins.
Worked absolutely fine on both our systems. What amazed me most was that I didn't have to find a single driver for either laptop. Period. And our systems are originally running Vista 32-bit. I was concerned that (as laptops often have specialized OEM drivers) would be a deal-breaker jumping to 64-bit Windows 7 but it wasn't. Go figure.
So now I can dual-boot both laptops. My original 32-bit Vista installs are still in place and I can go back and forth. Also, as you pointed out, because the "real" drive is still listed, I just made shortcuts to my portable apps, docs, etc. on that system and can still access and run them without "installing" them in the Windows 7 64-bit system. Amazing!
Subjectively, like you observe, I can't tell any performance hit at all by operating off the VHD disk in Windows 7. But then Windows 7 RC seems soooo much smoother and consistent than my Vista installation ever did. Even after Vista SP1 got installed, I'm still getting stutters and freezes under Vista when I copy/transfer files and even delete the recycle bin contents. None of that happens under Windows 7.
I've got my teen-daughter's third laptop to go and here is my "project". I'm welcome to any thoughts on it.
It is XP Home, with 512 MB RAM and a 64-bit supported processor. Because it is XP and not Vista, I can't do the Windows 7/Vista bootloader file swap like I did before. Instead, I'm going to capture a WIM image of the primary partition that has the XP system. Then format it, and install the Vista 64-bit system on it.
Then I'm going to create the VHD file and attach to it in Windows 7.
Then with one of my handy Win PE 3.0 boot disks, I will dump the WIM image containing the original XP system into it.
This should allow me to then boot the original XP system as an option.
Because all the hardware is the "same" I shouldn't need to do any sysprep on it.
I know, it's madness, madness...but it's just so darn geeky fun to do!
Windows 7 is really impressing me with the additional "tricks". Most average consumers probably won't care, but to a sysadmin/geek, this is pure bliss.
Also, the free EasyBCD 1.7.2 utility seems to be working fine for Windows 7 as well since it is Vista compatible. Some folks might find the GUI interface it provides helpful for tweaking the boot loader options rather than the command-line bcdedit method. However...some care should be used as Windows 7 does not appeart to be officially supported by this tool..yet.
Cheers!
--Claus V.
I almost prefer building a new bootable VM image and have something that is more portable.
The thing I hate about Virtual XP and the VPC that's installed is that I have not found a way to turn off hardware assisted virtualization. You cannot have VPC and VMWorkstation running at the same time. As soon as a VM Workstation VM starts up, it dumps with a CPU error. I was able to get around this on VPC 2007 by just making sure hardware assistant was turned off and turned on under VM Workstation (since I used that the most).
If the both can co-exist nicely under Win7, I'd be even more enclined to use the Virtual XP for routine things.
Oh well --
When you install Windows 7 to your virtual disk, Windows still refuses to calculate your experience score. Were you able to run the Aero interface (with Aero Peek), or did you get the toned down UI?
From within the booted VHD (in Virtual PC), open:
C:\Windows\System32\sysprep\sysprep.exe
Select OOBE, Generalize and Shutdown.
Remember, this will erase all of your user preferences!
Sysprep failed with an error for me the first time, but when I killed a process related to windows media player, it worked (just kill anything starting with wmp in your processes, remember to show processes from all users).
If we could only figure out how to still have the VHDs be portable, we would be dangerously close to Utopia. As you mention, there are device "issues" at the moment. Maybe this could be solved using multiple hardware profiles some how? Last time I used that stuff was on Windows XP, and I'm not even sure Windows 7 has that concept anymore.
I can think of 4 that I need right now...
Or is it just Windows OS's that can be booted this way (or in fact, is it just Windows 7 images that can be booted).
Now i can mount all my winsdows (95- todate) and i am about to run out of drive letters :(
any work around for that?
K
Second, doing this makes your VHD less portable, because if you move it inside Virtual PC or to another machine, all the devices will freak out and try to reinstall (or maybe just not work) so be aware of that.
Probably very obvious question incoming. If I made a backup of the VHD to say an external drive in case I corrupt it by installing VS2010, is it possible to overwrite the original VHD with the backup and have a "fresh" install of windows without actually installing windows again?
One question though, is there any way (supported or unsupported) to mount a VHD and boot from it like that when my PC runs Windows Vista? I've really been wanting to play around with the Windows 7 RC, but I don't want to use Virtual PC because I lose my video card and I really don't want to attempt a dual-boot with a pre-release OS.
One more caveat: the medium on which the VHD is stored needs enough free space to fully expand the VHD to the size the drive is created with (default 127GB) if you're using a dynamically expanding hard disk. If this space isn't available, you're treated with a BSOD on booting the VHD.
http://www.wrox.com/WileyCDA/Section/Editing-XML-and-XML-Schema-in-Visual-Studio-2008.id-320326.html
ok, it was only a book you wrote for wrox, and I've always been a bit suspect about wrox content, but... it DOES have your name and picture on it! ;).
GL with the fund raising!
--woody
PS - I did try your "email" link but that failed with a "CAPTCHA not read" whatever that means - I think it means your tool is broken tho.
Have spent much of the Saturday morning trying to complete my "project" on dumping an XP system into a VHD file then setting the Windows 7 boot loader to present that as an option to "dual boot" from.
Got it all set up and had to do some extra bcdedit work to get it to pick up.
Add a Native-Boot Virtual Hard Disk to the Boot Menu - MS TechNet
I was actually able to get it to pass off from the Windows 7 boot loader to the NTLDR within my XP VHD file...but then it consistently errored out.
Turns out (big DOH! to self) that XP doesn't seem to offer the needed VHD drivers/support that Windows 7 brings to the table. And I'm not aware that there is any currently known method to swap the XP NTLDR config with Windows 7 loader.
Yes, you can boot and XP system from within a VHD by using Virtual PC...however the Virtual PC application wraps the VHD around it's hardware abstraction so the XP NTLDR doesn't actually realize it is operating in a VHD. It still thinks it is a physical drive.
Windows 7 boot loader is more sophisticated and can handle this internally just fine without any assistance.
Vista can be "tricked" into working by swapping out it's boot-loader version with the kissing-cousin version in Windows 7. Doesn't seem to be any issue.
At least that's the way it seems to me.
I'm open to suggestions or corrections by anyone....
Cheers.
--Claus V.
This excellent VHD FAQ has lots more detail as does this post from the team.
Has anyone seen this error before and have some insight into what might cause it? Here's my "bcdedit /v" output on the relevant entry.
Windows Boot Loader
-------------------
identifier {e8684c5d-37ee-11de-a04f-aced438f3deb}
device vhd=[D:]\vhd\my.vhd,locate=custom:12000
002
path \Windows\system32\winload.exe
description VHD-20090615
locale en-US
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {e8684c5a-37ee-11de-a04f-aced438f3deb}
recoveryenabled Yes
osdevice vhd=[D:]\vhd\my.vhd,locate=custom:22000
002
systemroot \Windows
resumeobject {e8684c56-37ee-11de-a04f-aced438f3deb}
nx OptIn
detecthal Yes
Problem I have is with the Windows Experience Index (WEI). Whilst it runs and fails, but gets enough of the way through to get Areo working - it doesn't provide a score that other apps might call in order to work.
For example - if you run Windows Live picture gallery, and want to use it for a screensaver with themes turned on - it's impossible without a WEI. The Themes relies on the WEI to work.
So the question is - can you fake out the WEI? I understand there's an XML file in \Windows\Performance\WinSat\Datastore that you could edit to apply a WEI - but I don't think the file needed is generated unless you can complete at least one successful WEI.
Any way to hack in a WEI on a VHD??
That seems like a lot of really powerful and significant reasons.
The powerful feature for me was building a VM using Virtual PC (which meant I can keep working and not be stuck in setup mode) and then booting to that VM with mostly real hardware. Very cool!
I didn't notice the VM seemed to be weird when I booted it up as a VM again, but I haven't looked too much into it yet. Overall through, a cool feature to add for developers.
Thanks for convincing me! :)
Thanks!
Louis
"Configuring native VHD boot if the host volume is protected by Bitlockerâ„¢. You can save a VHD file on a file system that is protected by BitLocker, but you cannot use the VHD for native boot or enable Bitlocker on the volume(s) that are contained inside a VHD."
I'm in the process of turning off BitLocker to test whether that will allow me to boot to the VHD, and I'll report back with the results.
Thanks for the posts detailing how to get this set up, Scott!
is it possible to re-mount a simple disk vhd during boot? I have a vhd that is simply used for extra drive space, but I need to remount it after each restart.
i try to run a Windows server 2003 as a VM without the main OS windows 7 loaded but every time fails
can anyone help me i'd really really appreciate it.
http://technet.microsoft.com/en-us/library/dd799282(WS.10).aspx#BKMK_whatIsVHD
The way I read that, is , if you create a new system partition on the external, it will work
Comments are closed.
works pretty well so far!