Saturday, 26 July 2008

Dual-booting with Grub

On one of my PC's I still dual boot to Windows. Most of the online guides to dual booting instruct you to install Windows first and then install Linux and let Linux modify your boot sector accordingly.

I don't like doing it this way partly because I am an uber-geek and like to do stuff the hard way but also because i have a special setup whereby I can boot natively into Windows or I can boot the same Windows installation from within a vmware virtual machine which is neat. I might describe how to do that one day.

Anyway, to do this, Windows must be on its own separate drive and both Windows and Linux must use their own boot loaders and both must believe that they are booting from the primary hard disk.

To achieve this we must fool Windows into thinking that it is on the primary drive even tough it is on a secondary.

To do this we simply add the following stanza to /boot/grub/menu.lst

title Windows
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd1,0)
chainloader +1

NOTE: The "map" lines have a 'space' between (hd0) (hd1). You will get "GRUB: Error 11: Unrecognized device string" error without that space.

If you want to hide/unhide partitions also add;
hide (hd0,0)
unhide (hd0,0)

Once you’ve made the change just update Grub with this command:


When you reboot, you should see an option to boot Windows.

For this to work, you must have a hard disk with a bootable, working copy of Windows on it. For example, install the HDD in your PC as the first drive (master) and install Windows. If it boots OK when you are done then remove the disk and install the one that has[will have] Ubuntu on it and set the Windows drive as slave. Modify grub as above and everything should be hunky-dory. (Disclaimer; If you muck any of this up it could render your PC unbootable and cause you much distress and possibly anger. It is your responsibility to ensure that you know what you are doing when mucking about inside your PC. For further info see this)

No comments: