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.

About these ads

12 Responses to Installing GRUB on FreeBSD

  1. FreeBSD vps says:

    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. ddouthitt says:

    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. Pingback: FreeBSD News - quick links (week 16) | FreeBSD - the unknown Giant

  4. ddouthitt says:

    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.

  5. locky says:

    Thank you very much.
    You really help me.

  6. monsun says:

    Thanks a lot, it works :)

  7. Pingback: GRUBówka « Blogavo

  8. Mark Ovens says:

    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?

  9. ddouthitt says:

    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.

  10. Mark Ovens says:

    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.

  11. Daniel G. says:

    Thank you!

  12. If you are performing a new installation (I was performing a new installation for a xen virtual machine), then you need to select “CD-ROM” instead of ‘file’ when you open your iso file.

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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers

%d bloggers like this: