Monday, June 21, 2010

Adding Winpe boot to Windows 7 boot menu

I spent good part of today preparing a new test machine. One thing I always wanted was to have a native WinPE boot in the test machine. This was possible with vista but not with previous versions of Widows. For pre-Vista systems, I had to mess around with bootmanager/ntldr to get this to happen. I used a Windows 7 system today, but don't see any reason why it would not work with Vista.
In test environments, it is useful to have a WinPE boot option in windows boot menu. Booting to WinPE would allow you to look at the filesystem in case if the computer is not booting and more importantly, it will help easy refreshing of the system by restoring a fresh image. Having a PXE server in your network too, would equally be useful in terms of booting to preOS environments.

I had a WinPE build, created using the latest version of WAIK (Windows Automated Installation Kit) . If you don't have WinPE, search for AIK , which is a free download from Microsoft. It is not difficult to build WinPE using WAIK, and lot of help in the net!

This is all I had to do.

Copy boot.sdi file

If you install Windows 7 using the default settings, it would have created a small partition to hold boot files. This is usually 200MB, and no drive letter assigned. If you don't have this small partition, skip step fist and last step. All files will be in C: in that case.

  • Start diskmanager and assign a drive letter to the boot partition
  • Boot files are in the "\boot" folder in that partition. This is a hidden folder, but from a CMD window, you can go to the folder with 'CD \boot' command.
  • Files in the boot are not hidden. It has most of the boot files necessary but not boot.sdi file. Copy this to the \boot folder from WinPE build's boot folder.
  • Now we are done with the hidden partition, go to diskmanager and remove the driver letter for that partition. Otherwise it will continue to mount it all the time.

Copy the .Wim file

The boot image or WinPE, WinPE.wim file can be found in the WinPE built created from AIK. Copy the .wim file from the WinPE build to a convenient location in the system. You may have enough space in the boot partition (it is 200MB but there are no many files), but try to avoid it. You can create a new folder in drive C: and use it to hold your .wim as well as .vhd in time to come! Say your Windows partition is C: and the name of the .wim file is winpe.wim, and copied it to C:\Images.

Add an entry to BCD

Usually, the {ramdiskoptions} entry is not created when installing Windows. Just make sure if it is there or not with the following command.

bcdedit /enum {ramdiskoptions}

If it says "There are no matching objects or the store is empty", that indicates {ramdskoptions} entry has not been created. Create it with the following commands.

bcdedit /create {ramdiskoptions}
bcdedit /set {ramdiskoptions} ramdisksdidevice boot
bcdedit /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi

Now, create the actual entry with following commands.

bcdedit /create /d "WinPE boot" /application osloader

After successfully creating the entry, this will display the {GUID} of the entry in format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. Use that value in the following commands.

bcdedit /set {GUID} device ramdisk=[C:]\Images\winpe.wim,{ramdiskoptions}
bcdedit /set {GUID} osdevice ramdisk=[C:]\Images\winpe.wim,{ramdiskoptions}
bcdedit /set {GUID} systemroot \Windows
bcdedit /set {GUID} detecthal Yes
bcdedit /set {GUID} WinPE Yes

Finally, add it to the current boot options list with

bcdedit /displayorder {GUID} /addlast
Reboot the system and select WInPE boot to boot to WinPE

Surprisingly, you can boot the same machine to 32 bit WinPE as well as 64bit (if the machine is 64bit.) just by using the appropriate WinPE.wim. They can be in the same menu, no other files need change.


Notes:

  • In boot menu, if "Ramdisk Options" is displayed instead of the description of WinPE, remove the description of the {ramdiskoptions} with the following command.

bcdedit /deletevalue {ramdiskoptions} description

  • If booting to winpe fails and says "A required device is not accessible", check if you have copied the boot.sdi file to the correct location.

Sunday, June 20, 2010

Can Windows 7 natively boot Vista VHD?

I spent good part of yesterday trying to natively boot a PC with a Vista VHD. I am impressed with the native VHD boot of Win7. Both experimenting and testing benefit from it. The ability to refresh a machine in around 5 minutes without using any tools is truly amazing. Yes, virtual machine snapshots do it even faster, but you lose a good part of the machines power when using a virtual machine. Specially if you use it for a prolong period, native boot has advantages.

Yesterday I wanted to try natively booting a system from a Vista VHD. There were several posts in the net how you go around doing it, and they seems to be so simple and did not understand why MS does not support it. Step by step instructions I saw is identical to what you do when getting a Win7 VHD to boot natively.

To tell a long story short, it didn't work. At boot up, Windows goes to recovery mode if I have an boot entry to Vista VHD. Surfing the net a bit proved that I'm not alone in that.

After half a day later, my hopes were shattering. There are couple of posts explaining why it can't be done. Well, every thing ever been done on this planet has been put away by someone saying it's not possible. So those posts didn't stop me trying it. However, now I believe it is not possible - at least in the way described in some sites (just adding the VHD to boot menu) but may be there is another way - I will keep trying.

I came across the product VMLight when searching for this. It seems they have a driver that can natively boot any VHD (not only Vista but XP, Linux too). I will try it but I'm not sure if it is really 'native'. Though you boot from a VHD, it is probably using another layer to translate VHD to a SCSI device. This could affect performance but the flexibility you get with the ability to natively boot all current OSs could well worth it.