다음을 통해 공유


Dual Boot from VHD Using Windows 7 and Windows Server 2008 R2

windows7rc_bloglogo

Executive Summary

Boot from VHD is a new technique for installing and maintaining operating system environments.  Unlike virtual machines, the operating system that is running from a “boot from VHD” environment is using the actual hardware instead of emulated hardware.  This means a developer could easily use WPF and the full GPU processing power of a high end graphics card.  In another scenario, this technology makes it easy to setup and run Windows Server 2008 R2 with the Hyper-V role, thus supporting 64 bit virtualization workloads.

The Virtual Hard Disk (VHD) is the container for the installed operating system.  Because everything is inside a single file, there are a number of benefits that can be realized for data center server environments, as well as managed desktop environments.  The following article dives into the technical details of implementing two operating systems.  Both are installed in a VHD file and can easily be booted by selecting the preferred environment at power on.  This could easily be scripted and automated.

The Installation Foundation – Windows PE

The Windows Preinstallation Environment (WinPE) has been updated for Windows 7 and Windows Server 2008 R2.  One of those improvements is the ability to use a Virtual Hard Disk (VHD) file as the target for an installation of the operating system (OS).

This has some interesting implications.  Booting from a .VHD file that contains an entire OS seems rather magical.  I mean think about it.  You go to look at a hard drive and there’s a single file but Windows Server 2008 R2 is installed inside it.  This would certainly simplify the ability to boot your servers on a completely new environment with little effort.  This is going to turn change management on its ear.

The same is true for the desktop OS, Windows 7.  You can install Windows 7 inside a .VHD file.  Again, the OS is installed inside a single file and thus makes it rather easy to move or change out and bring up a completely different version of the environment.  This will make test environments for developers super easy to construct and test discrete sets of applications or components.

One thing that is not well known is how easy it is to create the initial .VHD file and install the operating system into it.  The supported and documented ways are geared towards very well defined support scenarios.  You can see the supported scenarios in the Windows Automated Installation Kit (WAIK).  Most people have been reluctant to take the time to learn this because it involves the use of imagex captures and applies.

What if you could install with just the DVD?

You can.  All you need is a hard drive with disk space and the DVD for Windows 7 RC or Windows Server 2008 R2 RC.  In fact, when I was investigating the tools for this article I used a brand spanking new Hitachi 2.5” 320GB 7200rpm hard drive and both DVDs to create a dual boot environment.  Nothing more.  And it’s much simpler than I thought.  The key is WinPE and DISKPART.  Here is the screencast demonstration of the tools in action.

The Screencast Video – 23 minutes – Win7 and R2 Dual Boot via VHD

Get Microsoft Silverlight

The Command Sequence Used in the Video

  1. Boot your machine with a blank hard drive using the Windows 7 DVD.
  2. Click next on the language screen if English is appropriate.
  3. SHIFT+F10 to launch a WinPE command console.  Although the commands below are in upper case, the commands are not case sensitive.  I am only using upper case for readability here.
  4. Enter DISKPART to run the utility.
  5. LIST DISK to see the available disks in your system.  I am assuming a single raw disk.
  6. SEL DISK 0
  7. CREATE PARTITION PRIMARY
  8. FORMAT FS=NTFS QUICK
  9. LIST VOL
  10. ASSIGN
  11. LIST VOL
  12. CREATE VDISK FILE=c:\windows7rc.vhd MAXIMUM=200000 TYPE=EXPANDABLE
  13. SELECT VDISK FILE=c:\windows7rc.vhd
  14. ATTACH VDISK
  15. CRE PART PRI
  16. FORMAT FS=NTFS QUICK
  17. ASSIGN LETTER=V:
  18. LIST VOL
  19. LIST VDISK
  20. exit DISPART
  21. exit WinPE command console
  22. Install to the newly created 200GB (fuzzy math) virtual hard disk which looks just like a partition to Windows Setup
  23. Repeat steps 11-18 for the Windows Server 2008 R2 VHD but with the obvious changes for the vdisk filename, size, etc.

Other References and Articles

Windows Automated Installation Kit (WAIK) for Windows 7 and Windows Server 2008 R2 RC – get it @ https://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=60a07e71-0acb-453a-8035-d30ead27ef72.  This is the bible for the supported methods of using “Boot from VHD”. 

Windows Virtualization Blog – see their VHD boot post at https://blogs.technet.com/virtualization/archive/2009/05/14/native-vhd-support-in-windows-7.aspx.  Particularly interesting is the performance area of the post.

Knom’s Developer Corner – another nice post at https://blogs.msdn.com/knom/archive/2009/04/07/windows-7-vhd-boot-setup-guideline.aspx.

So What’s Next ???

Tomorrow I am going to backup my existing Windows 7 production hard drive.  Windows 7 is installed in the traditional fashion on a 200GB drive right now.  I am going to restore the backup to a larger disk then install Windows Server 2008 R2 RC into a .VHD and test mixing them.  That’s a bit of a hybrid and one I think a lot of developers might be interested in.  It would certainly demonstrate you can have a traditional implementation of your production OS, but flip to any other Windows Server 2008 R2 or Windows 7 testbed very easily.  I’ll follow-up here or another post when I get that implemented.  Enjoy.

[UPDATE for 5/23/2009] As I indicated just above, I wanted to run an extension of the test I recorded.  I backed up my 200GB Windows 7 RC environment then restored it to a 320GB drive.  After that, I booted from the Windows Server 2008 R2 RC DVD and created a bootable VHD with R2 inside.  The VHD is stored in a folder at the root of my 320GB disk.  The R2 setup program fixed up the bcdstore area and I now have a dual boot hybrid.  Windows 7 is installed in the traditional manner.  R2 is booting from the VHD.  Both are available on the selection menu at power up. Interesting stuff for sure.

[UPDATE for 5/25/2009] Since I received a couple of questions out of band on how I captured the demo, let me explain.  The demo was captured using Camtasia v6.0.2.  The demo was a Hyper-V virtual machine, not native hardware.  I had mentioned that in some of the preliminary takes but I guess I didn't make that clear in the final take.  Therefore, the booted OS in the screencast is actually using the emulated hardware of the virtual machine.  Everything you see in the demo works on my native hardware, a Lenovo ThinkPad T61p.

One other thing, the VHD that is being booted from will expand to the maximum size specified at creation.  It will revert to the used size when you shut it down.  Keep this in mind because that buffer must exist at boot time or else.

[UPDATE for 6/14/2009]   Although this article was originally written using a blank hard drive, I have received a few suggestions for adds, so here they are. 

  1. Backup your machine first.  Yep, this is a good idea as always if you are messing with a drive you care about.
  2. Decrypt the drive if using BitLocker.

Comments

  • Anonymous
    May 22, 2009
    I foud that if you install Windows 7 AND Server 2008 R2 in VHD and run them on the same Machine: you only have to install the Apps to either a third VHD OR to the fysical disk, that 20 GB is quite enough for the OS and app registrations. ( I am running this since build 7000) like this. If you use this large a vhd, when running from the VHD, it will expand the disk to the above mentioned size and 200GB of diskspace will fill up your disks very fast. Please keep that in mind. I am running both on my laptop ( even dualboot the server 2008 R2 With and without Hyper-V.) from a 160 GB harddrive. and I have room to spare.

  • Anonymous
    May 22, 2009
    Is it possible to use this to run other OSes ? (besides Win7 and W2k8 r2)

  • Anonymous
    May 22, 2009
    I just twittered that question above...if you can do it in Win7, why not in Vista? What changes in the Windows Boot Loader have been made? Obviously Vista would have to know about how to interact with the storage controller to find itself once it initializes but after that what would prevent it? -Michael http://twitter.com/michaelsainz

  • Anonymous
    May 22, 2009
    Can you backup your current system to a VHD and boot that?

  • Anonymous
    May 22, 2009
    As far as I understood the bootloader in this case is the one that comes with W2K8R2, right? Is it possible to boot from the VHD file using any other bootloader, like GRUB for example? I would suspect so, I believe something along the lines of http://www.geocities.com/epark/linux/grub-w2k-HOWTO.html Also, I have heard that you will be able to use the same VHD files on the Hyper-V servers as well. How is the boot organized here? Thanks a lot for a very interesting post and screencast. You are bookmarked :)

  • Anonymous
    May 22, 2009
    Regarding other boot managers, they would need to understand the .VHD file format which is published.  They would also need to understand the BCD store, how to modify it, etc.  I have no doubt some bright programmer will do something interesting but at the moment this technology is designed for Windows 7 and Windows Server 2008 R2 only. As for booting the resulting .VHD using Hyper-V, it doesn't work for me and it doesn't appear SR will recognize how to fix matters so you can. The scope of this technology is pretty narrow at the moment and I rather doubt you'll see support for Windows XP and Windows Vista boot scenarios.   On the other hand, if you used imagex to create a WIM of your current physical machine, then used that for the imagex apply into the VHD, you might get lucky and have it work with the RC version of WinPE.  I would imagine some of you will be doing a little research over the three day weekend.  Have fun and let me know what you come up with.  

  • Anonymous
    May 22, 2009
    How can I have Win7 install on drive V as you did and not rename it to C is it did for you? All my systems have a drive C and I put shared 'greenware' programs with links to C: so that all multi-boot operating systems can have access to these programs without installing and setting up the menu. I've had to create junction points to get my folders to look like they are on C, not a nice way to do it. Also, could I take my native install of Win7, back it up and restore to a newly installed .vhd install of win7?

  • Anonymous
    May 26, 2009
    Can these .VHD files be "migrated" or "copied" for use/deployment on another machine or in Hyper-V?

  • Anonymous
    May 27, 2009
    Hi Keith, i have the experience that the vhd doesn´t have the name "windows" inside. source: http://www.windowsblog.at/post/2009/01/12/34765.aspx Kind regards Joerg

  • Anonymous
    May 27, 2009
    Here is what I have done with this technology: Use Windows System Image Manager to create an autounattend.xml file to include partition information, driver folder locations and license key information. Boot to WinPE 3.0 (with scripting installed) and run diskpart script to create partitions including virtual.  Install to virtual disk... My experience is that setup always puts the bootloader files in the root of the first partition of the physical disk, even with clean installs from DVD.  The boot loader loads the driver to support the OS in the .vhd file.  Use "bcdedit /enum all" to examine the entries.  Also, the OS installed to a .vhd actually does not appear to use virtualized hardware as in Virtual PC... My installs detect the physical hardware and require the drivers. To make your .vhd files portable I think you would have to boot the target machine with PE, create the physical and virtual partitions, create the bcd store with information about booting to the .vhd file, then apply a sysprep'd .wim file to the .vhd.  If your .wim capture process is good and includes all of your out of band drivers and apps then your image should be fairly portable. As far as booting older OS's... look to TechNet Magazine about dual booting Vista and XP with the BCD store. Apply an XP image to the .vhd (add Ghost to your WinPE 3.0 disk) and modify the Windows 7 BCD.

  • Anonymous
    June 02, 2009
    The comment has been removed

  • Anonymous
    June 09, 2009
    If I follow this step by step, installing Windows 7 or Windows 2008 R2 to an expandable vhd on a Dell Latitude D830 causes a blue screen after the first reboot following the "Installing updates" section of the install.  If I duplicate the process step by step using a fixed size vhd then the install is successful.  Any suggestions?

  • Anonymous
    June 09, 2009
    Sorry Darryl, I don't know why that would fail, and a fixed disk would work.

  • Anonymous
    June 11, 2009
    There's a very useful scenario here that I just verified works (on my machine) ... multi-booting Vista as the base install (not in a VHD) with Windows 7 (and presumably WS08R2) in VHD's. I have one machine that I can't convert to Windows 7 until I complete a specific project ... well, I had enough free space on the C: drive that I simply followed Keith's process above to boot the Win7 install disk, create/attach a VHD file on the C: drive and install Win7 to that VHD. It modified the boot manager appropriately, and I now can use Vista until I'm done with the project, but I can also use the machine for Win7 ... and the best part is, when I'm ready to cut over, I can just copy off the VHD to my 1.5 TB external USB backup drive, wipe the internal hard drive, install a minimal win7 on the metal (or to a separate VHD), copy the new VHD over, and modify the boot record to point to it again. Going forward, I assume I will always install to a VHD because it makes it so easy to restore my machine and switch between profiles. But for right now, it gives me a great hybrid solution with Vista and Win7.

  • Anonymous
    June 13, 2009
    From looking at this, I surmise that I can probably transplant the Windows 7 boot loader into Vista, and use that to boot VHD's to test Windows 7 in, also should be able to clone my existing XP to a VHD and boot that too. Gonna have to give this a try later :)

  • Anonymous
    June 22, 2009
    I have a brand new laptop coming in this week and love this setup. I would like to follow it exactly as I will be using Windows 7 and Server 2008. I may do one thing differently and that's to partitiion my drive into two. On one side I want to install Vista for apps I use that are not supporting Windows 7. On the other primary partition I want to replicate what you have shown here. From the comments I do not beleive this will be an issue as I will have a primary Windows Vista (non vhd) partitiion and then a second partition with the bootable vhd files on it. (My laptop is also upgradable to have 2 hard drives, but for now i'll have one. Dell Precision M4400) I think I may give the following space allocations per your : Partition #1: 175GB (C: Drive) Vista 64 (Native) -Everyday applications & tools, possibly a game or two Partition #2: Windows 7 - 50GB (W: Drive)

  • Just for fun, for now Server 2008 - ~95GB (S: Drive)
  • Will have SharePoint 2007 installed and related tools How does this sound, any feedback?
  • Anonymous
    June 26, 2009
    sir, i am interesting your screencast video win7 to win2008 vhd how can i download your blog video for my tutorial installation. thanks ed

  • Anonymous
    June 26, 2009
    When the VHD is booted it has full access to all of the hardware on the machine.  Does this include the disk/partition it resides on?  How is security managed on the NTFS partition under the VHDs?

  • Anonymous
    June 29, 2009
    Excellent video, maybe if someone have a way to make this native vhd with the drivers installed also run using virtual server or virtual pc. as you can fairley predict the kind of emulated hardware virtual pc creates for you, maybe there is a way to also support it. This way you will have a vhd on a portable hard drive which runs natively on your laptop, but also can run in a virtual enviroment on someone else's computer. That would be pretty usefull

  • Anonymous
    July 04, 2009
    I just read your blog entry today, and not a moment too soon. Earlier I ran WinPE on my XP Home Edition PC and shrunk my partition so I could create a second partition to install Windows 7. Instead, when I booted the Seven DVD, I launched a PE command prompt, extended the partition back to the full size of the disk, created a VHD, and installed Seven to the VHD. Everything went smoothly and now I'm booting XP Home and Windows 7. This is a phenomenal technology; my mind reels at the possibilities. Thanks Keith!

  • Anonymous
    July 04, 2009
    The possibilities in the data center are mind blowing.   Or using all of the idle machines in an enterprise for coordinated computing.  Push a .VHD, reboot, run a specific task, revert when done.  Simple.

  • Anonymous
    July 09, 2009
    How do I duplicate the same vhd file in another PC (exactly same hardware) ? Thanks, and sorry for my english.

  • Anonymous
    July 11, 2009
    Hi Keith. I might have missed it. But what if I already have a vhd file with Windows 7 RC installed in it, which I have created vith Virtual PC and just want to copy that file to a new machine as the boootable vhd file? How would I install the PE environment, create the virtual disk partition and install that file (copy) instead of doing a complete operating system install? Where may I look for steps to do this? Thanks and regards

  • Anonymous
    July 14, 2009
    This is REALLY stupid, but... if using the Windows Server 2008 disk, it NEEDS to be the Server 2008 r2 RC and not the Server 2008 w/ SP2 disk. (The file date you're looking for is 4/30/09 and not 5/11/09.

  • Anonymous
    July 14, 2009
    Obviously Casey didn't read the article.  I said R2.  R2 has meaning.  R2 is 64 bit only, has DirectAccesss, Boot from VHD, etc. Casey, next time you want to call someone stupid, get your facts straight first.

  • Anonymous
    July 14, 2009
    I thought it was pretty obvious that I was calling MYSELF stupid. I thought the article was put together very well, and very easy to understand. What I had to say was a stupid addition to your article, and my hope was that I could prevent somebody from making the same mistake I made.

  • Anonymous
    July 14, 2009
    Oops.  I thought you were calling me stupid.  I'm the only one allowed to do that (and do it frequently). Yep, the R2 or Win7 disk is one of the requirements because of the updated version of WinPE, Diskpart, etc. Peace !!!

  • Anonymous
    July 21, 2009
    Good Article. I have been using the VHD Boot Windows7 for sometime. But recently y organization decided to encrypt all our Laptops with pointsec software. From then on, I am not able to boot with the VHD Image. It Just gives "Blue screen". Any thoughts on this issue? Thanks in Advance, Jibu

  • Anonymous
    July 21, 2009
    Good Article. I have been using the VHD Boot Windows7 for sometime. But recently my organization decided to encrypt all our Laptops with pointsec software. From then on, I am not able to boot with the VHD Image. It Just gives "Blue screen". Any thoughts on this issue? Thanks in Advance, Jibu

  • Anonymous
    July 25, 2009
    Can you use the diskmanagement GUI in windows 7 to create a VHD and install directly onto that?

  • Anonymous
    July 25, 2009
    Brandon, the answer is yes.  If you are alreadey running Windows 7 or Windows Server 2008 R2.

  • Anonymous
    July 28, 2009
    It looks like you can't call the vhd with a filename with c:windows in it otherwise you get a message that includes "Windows is usually installed to the windows directory"..... call the vhd file c:win7rc.vhd and you will be good to go.

  • Anonymous
    July 28, 2009
    The comment has been removed

  • Anonymous
    August 05, 2009
    Keith, great article - Hyper-V will never be the same in dev and test environemnts.  A colleague mentioned that you cannot apply bitlocker to VHDs.  If you have the bitlocker requirement for all partitions, your only choice is to use legacy dual-boot, correct?

  • Anonymous
    August 05, 2009
    Roy, Correct.  BitLocker messes this all up right now so you would need to use partitions and the old school.  Even then you have to be pretty careful with bitlocker.

  • Anonymous
    August 06, 2009
    can i use this technique to restore my win7rc installation too ?