Wednesday, November 21, 2012

BSD in Grub 2 Boot Menu

There are lot of places where you can find the solution for this. But most of them are in forums. You have find the correct one out. So, here is how we have to do that.

First, Grub2's menu shouldn't be edited directly. Reason? That will be rewritten with each Grub update or refresh. So, we have to edit the following file

/etc/grub.d/40_custom

Just add the following

menuentry 'BSD' --class bsd --class os {
    set root='hd1,msdos2'
    drivemap -s (hd0) ${root}
    chainloader +1
}


Now let me explain each ad every line.

menuentry 'BSD' --class bsd --class os {

Tells Grub that there is another menu entry to display in the boot screen. Whatever inside '' is the title that will be displayed. Other stuff are just for Grub to get some info on the  OS.

set root='hd1,msdos2'

hdX,mdosY

here is a catch! X starts with 0 and Y starts with 1. That means, if you have 3 hard disks, first is 0, second is 1 and third is 2. Now, if you have 3 partitions, first is 1, second is 2 and third is 3.

So in this example, the bsd is on second hard disk second partition.

drivemap -s (hd0) ${root}

Now you have to swap your hard disks. You can boot only from first disk. So we can use "drivermap -s". -s will swap whatever assigned to root to hd0 and hd0 to root. This is bit easier compared to earlier versions of Grub.

chainloader +1

This is the only thing that tells the Grub to actually load the bsd.

}

You need explanation for this?