Wednesday, January 5, 2011

Booting into the MBR of another drive using GRUB 2

I wanted to try dual booting Linux and Windows on my machine, whose existing Windows hard drive is fully encrypted with Truecrypt. To avoid complications with Truecrypt, I put another physical disk in the machine with the intention of installing Linux on that. I wanted to be sure that the install did not touch the Truecrypt disk, including the MBR on that disk. The intention is that the new disk will become the boot disk and it will either load Linux or boot from the MBR on the Truecrypt disk.

The first trick is to make sure that the Linux installer does not overwrite the MBR on the Truecrypt disk, potentially rendering it unbootable. During the "expert install" of Debian based distros (including Ubuntu), it is important to install Grub 2 and then instruct Grub not to install to the MBR of the first hard disk. The installer will then give you the option to specify the drive whose MBR to modify - at this stage, choose the Linux disk, rather than the Trurcrypt disk.

After setting the Linux disk to be the boot disk in BIOS, edit /etc/grub.d/40_custom as the root user and add the following lines to the end:

menuentry "Other Disk" {
    set root = (hd1)
    chainloader +1
}

The key here is to set root to the Truecrypt hard drive. Do not specify a partition, because we want to boot using the MBR of the disk. Booting into grub and using ls at the grub command prompt will give you a list of all the available drives.

After modifying 40_custom, run update-grub, and reboot. You should be able to boot into Linux or into the Truecrypt drive using the Other Disk menu entry.

0 comments:

Post a Comment