Subscribe in a reader OR Subscribe to ComputerWorld by Email

Recently Posts

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.

Virtual Machines

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.

Disk Management (3)

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:



My Win 7 Boot Manager



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.).



Performance Information and Tools



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!



Disk Management (2)



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.



Computer Management



Hey, are those my four processors and my 8 gigs or RAM? Ah, yes, they are.



Windows Task Manager



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.




From: http://www.hanselman.com/blog/LessVirtualMoreMachineWindows7AndTheMagicOfBootToVHD.aspx

DiggIt! Del.icio.us Reddit

Related Posts by Categories



Widget by Hoctro | Jack Book
0 comments