Besides Linux and Hurd, Grub2 has native support for FreeBSD, NetBSD and OpenBSD, and can boot any OS which complies to the multiboot specification. If you fancy to install several GNU/Linux distributions you can multiboot using several Grubs.
FreeBSD
Direct Kernel Boot
GRUB can boot a FreeBSD kernel by using the kfreebsd command. The procedure would look like this:
1. Set the partition where resides the FreeBSD kernel:
set root=(/dev/ad4,msdos1)
2. Load the kernel
kfreebsd /boot/kernel/kernel
3. Load the kernel boot information
kfreebsd_loadenv /boot/device.hints
4. Set the root device-path
set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ad4s1a
5. Set any file-system options to pass
vfs.root.mountfrom.options=rw
6. Finally, run the command
boot
The list of all available options for the kfreebsd command can be seen by running kfreebsd --help from the GRUB prompt.
Example, using /etc/grub.d/40_custom
A FreeBSD entry in /etc/grub.d/40_custom should look like this:
menuentry "FreeBSD 8.0 direct" { insmod ufs2 set root='(/dev/ad4,msdos1)' search --no-floppy --fs-uuid --set 4c0029f407b3cd1d kfreebsd /boot/kernel/kernel kfreebsd_loadenv /boot/device.hints kfreebsd_module /boot/splash.bmp type=splash_image_data set kFreeBSD.vfs.root.mountfrom=ufs:ad4s1a }
You can get the fs_uuid from the Grub2 command line by typing:
ls (hd0,1)
It is possible to define the FreeBSD bootloader options ( /boot/loader.conf ) in the form of set commands.
For instance, to force the kernel to wait for USB devices to appear:
set kFreeBSD.kern.cam.boot_delay="10000"
NetBSD
Direct Kernel Boot
GRUB can boot a NetBSD kernel by using the knetbsd command. Procedure is as follows:
1. Set the partition where resides the NetBSD kernel. If NetBSD is installed on the first partition of your first hard disk, you would need:
set root=(hd0,msdos1)
2. Load the kernel and specify the root device-path:
knetbsd /netbsd --root=wd0a
3. Finally, run the command
boot
The list of all available options for the knetbsd command can be seen by running knetbsd --help from the GRUB prompt.
Example, using /etc/grub.d/40_custom
menuentry "NetBSD on sda1" { insmod ufs2 set root=(hd0,msdos1) knetbsd /netbsd --root=wd0a }
Generic Multi-Boot
Booting a multi-boot compliant kernel, requires loading the kernel with the 'multiboot' command, and then executing it with the 'boot' command. An example of very simple but fully compliant kernel, is the Grub Invaders game which you can start this way:
1. Load Grub Invaders with the command multiboot
multiboot /boot/invaders
2. Run the command
boot
Chain Loading
If you want to use FreeBSD, NetBSD's own boot program, it is perfectly fine to chain load the OS by specifying the partition. A custom entry would look like this:
menuentry "FreeBSD"{ set root=(hd0,msdos1) chainloader +1 }
If you have more than two versions of Ubuntu or several OSs installed, instead of using chainloader you should add to /etc/grub.d/40_custom the following kinds of entries:
menuentry "Yet another distro/installation/encrypted Ubuntu installation/..." { set root=(hd0,msdosX) configfile /boot/grub/grub.cfg }
Where X is 5 if the /boot of your target OS is at /dev/sda5. It is very important (e.g. after dist-upgrade of your second OS) to be able to rescue your original Grub using live-session and chroot environment as instructed on askubuntu.com.
It is wiser to use command configfile rather than multiboot because in Ubuntu 12.04 multiboot used to be pointed at /boot/grub/core.img and in newer Ubuntus (at least 14.04 onwards) confusingly at a different place /boot/grub/i386-pc/core.img.
After having made custom menu entries to all of your alternative OSs, you can clean up the grub by sudo nano /etc/default/grub and adding there the line:
GRUB_DISABLE_OS_PROBER=true
so the grub will stay more simple and neat. In the end, command sudo update-grub.
External links
http://mail-index.netbsd.org/netbsd-users/2011/09/13/msg009128.html
http://lists.gnu.org/archive/html/grub-devel/2011-09/msg00028.html
http://abhinav-upadhyay.blogspot.com/2011/05/making-netbsd-dual-boot-with-linux.html
http://lists.gnu.org/archive/html/grub-devel/2010-01/msg00091.html