Friday, September 17, 2010

Grub setup for multiple OSes in a neat way

Armed with a grub CD I proceeded with the Windows 7 installation. First I made a backup of the Vista partition just in case, then I formatted it and installed Windows 7. The Windows 7 installation created a Boot directory on my WinXP partition along with bootmgr, the Vista/7 boot manager. The installation also added a note to boot.ini that this is the WinXP boot configuration. If you install Windows Vista/7 on a new harddrive, this stuff will be put onto a hidden partition.

;Warning: Boot.ini is used on Windows XP and earlier operating systems.
;Warning: Use BCDEDIT.exe to modify Windows Vista boot options.

Of course it also updated the MBR to point to the new boot manager.

In order to set things up like I wanted, I first copied the Boot directory and bootmgr to my Win7 partition. Then I booted into Win7 and used bootsect (a tool located on the Win7 install DVD in the boot folder) to write a Windows 7 boot record to the Win7 partition and a WinXP boot record including ntldr to the WinXP partition.

Commands used (I first moved to the directory where bootsect resides):
bootsect /nt60 C: (NT 6.0 boot record for Win7 partition)
bootsect /nt52 D: (NT 5.2 boot record for XP partition)

Then I booted to Ubuntu Linux using the Grub Boot CD to setup Grub again. I used the below-mentioned commands.

From the standard Ubuntu terminal:
sudo grub

Commands for the grub CLI:
find /boot/grub/stage1 //returns where grub is actually installed
root (hd0,0) //type here whatever find returned
setup (hd0) //this installs grub into the MBR, if you want to put it into a specific partition use the (hd0,x) syntax to specify a partition

Finally I cleaned up the boot.ini file using a simple text editor and removed unnecessary options from the Windows 7 boot manager (basically to make it boot instantly once selected from Grub) using bcdedit.

From the Windows 7 CLI (with admin rights):
bcdedit /v //this command displays a list of entries, basically needed to get the ID of the legacy entry
bcdedit /delete {ID} /f //substitute ID with the ID obtained from the previous command

I also removed bootmgr and the Boot directory from the Windows XP partition. In order to accomplish this you need to first claim ownership of the files and then set the priviledges for your user / group to be allowed to delete them.

The end result is a clean boot setup with grub as the main boot manager, which is used to boot Ubuntu Linux, Windows XP and Windows 7 without nested selection screens. The great thing about this setup is, that it is scalable, supporting an virtually arbitrary number of boot options without interfering with each other.

Note that the order in which the different operating systems are installed is largely unimportant as long as one knows where lies what and how to restore overwritten boot configuration or work around that using a prepared boot manager CD (it's also possible to put one on a separate hard drive or even USB drive).

No comments:

Post a Comment