Installing GRUB on FreeBSD

Installing GRUB onto a FreeBSD system isn’t that hard – if you know how.

If you just run grub-install as root – which should normally work – you might see an error like this:

# grub-install hd0

GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub> root (hd0,1,a)
Filesystem type is ufs2, partition type 0xa5
grub> setup --stage2=/boot/grub/stage2 --prefix=/boot/grub (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/ufs2_stage1_5" exists... yes
Running "embed /boot/grub/ufs2_stage1_5 (hd0)"... failed (this is not fatal)
Running "embed /boot/grub/ufs2_stage1_5 (hd0,1,a)"... failed (this is not fatal)
Running "install --stage2=/boot/grub/stage2 /boot/grub/stage1 (hd0) /boot/grub/stage2 p /boot/grub/menu.lst "... failed

Error 29: Disk write error
grub> quit

The first step is to set a FreeBSD kernel variable:

sysctl kern.geom.debugflags=16

This will make the master boot record (MBR) writable, which is normally where the boot record is installed. Unless you do this, you will receive the error above.

Once the variable is set, the program grub-install should work fine with your chosen drive. The menu is in /boot/grub/menu.lst; here is a starter example for FreeBSD:

title FreeBSD
root (hd0,0,a)
kernel /boot/loader

The loader is the “kernel” in this case, as it will load the FreeBSD kernel anyway and it allows you the ability to drop into the boot console if you want.

12 thoughts on “Installing GRUB on FreeBSD”

  1. Good info — GRUB is pretty cool since it is so flexible. Also it is needed to run FreeBSD under Xen virtualization due to real mode/protected mode issues with the default bootloader.

  2. Another thing that I noticed – it reconfigures the screen to 640×480 – which means my FreeBSD boot splash now fills the screen! Nice…. I’d been trying to do that.

  3. Update: grub apparently didn’t do what I thought. Something in my BIOS or video card must be not be set or reset during bootup; now the boot splash is back to its normal “squeezed”” size (rather than the full screen size). Same display – same physical resolution (pixel count) – different physical size. Sigh.

    It still comes out alright (kdm fills the screen, as does X) but still, its an annoying niggle.

  4. Thanks for this page. I got the error you described but didn’t realize that it was sysctl kern.geom.debugflags=16 that needed setting because pkg-message in the port says this is only required for FreeBSD 5.x and -CURRENT but I’m running 6.3 – guess the message is out of date.

    One thing though, grub-install didn’t create a menu.lst file – is it supposed to?

  5. To Mark: No, I don’t believe that grub-install is supposed to create the menu.lst file. Since I’ve worked with grub quite a lot under Red Hat Linux, I just flung together my own menu.lst file.

  6. OK, no problem – I’ve played with grub before so knew the format of the file. It’s just that in the instructions above ^^^ it says:

    “The menu is in /boot/grub/menu.lst”

    which kind of implies that it’s been created by the installer.

    Thanks anyway.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: