Home > FreeBSD > Installing GRUB on FreeBSD

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.

Categories: FreeBSD Tags: , , ,
  1. 26 February 2008 at 11:27 am | #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. 26 February 2008 at 3:51 pm | #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. 21 April 2008 at 8:48 am | #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. locky
    1 May 2008 at 7:45 am | #4

    Thank you very much.
    You really help me.

  5. 4 May 2008 at 3:19 pm | #5

    Thanks a lot, it works :)

  6. Mark Ovens
    26 May 2008 at 12:07 pm | #6

    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?

  7. 27 May 2008 at 9:15 am | #7

    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.

  8. Mark Ovens
    28 May 2008 at 11:48 am | #8

    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.

  9. Daniel G.
    25 August 2008 at 2:19 am | #9

    Thank you!

  1. 19 April 2008 at 2:50 pm | #1
  2. 4 May 2008 at 5:40 pm | #2