FreeBSD has a bootloader vastly different than GRUB or LILO. The equivalent of stage1 in GRUB (which is used to locate the rest of GRUB and load it) is boot0 in FreeBSD, which is actually used to directly chainload Windows (or any other dual boot setup using the FreeBSD bootloader). The problem with boot0 is that, because it fits entirely in the MBR’s boot code area (which is 440 bytes), it doesn’t load a configuration file at all. FreeBSD still gives you a way to configure it, however, with boot0cfg
. Read on for a simple tutorial on the basics of boot0cfg
.
With boot0cfg
, you can easily hide partitions from the boot0
menu. For example, Windows 7 uses two NTFS partitions (one is the “System Reserved Partition”, and the other is the C: partition), but only the System Reserved Partition is bootable. On my system, the partition order is:
/dev/ada0s1 System Reserved Partition
/dev/ada0s2 C:
/dev/ada0s3 FreeBSD slice
Booting from /dev/ada0s2
(F2 in boot0
) doesn’t work, so let’s hide it from the list of partitions. boot0cfg
lets you set a mask that boot0
will use to determine what partitions to show. The mask is a hexadecimal number from 0x0 (all disabled) to 0xf (all enabled). In the example above, partitions 1 and 3 should be enabled, so the mask is 0b0101, or 0x5. The right-most bit is partition 1, and the left-most bit is partition 4.
This is a table for the different masks you can use:
Part. 1 | Part. 2 | Part. 3 | Part. 4 | Mask |
enabled | disabled | disabled | disabled | 0x1 |
disabled | enabled | disabled | disabled | 0x2 |
enabled | enabled | disabled | disabled | 0x3 |
disabled | disabled | enabled | disabled | 0x4 |
enabled | disabled | enabled | disabled | 0x5 |
disabled | enabled | enabled | disabled | 0x6 |
enabled | enabled | enabled | disabled | 0x7 |
disabled | disabled | disabled | enabled | 0x8 |
enabled | disabled | disabled | enabled | 0x9 |
disabled | enabled | disabled | enabled | 0xa |
enabled | enabled | disabled | enabled | 0xb |
disabled | disabled | enabled | enabled | 0xc |
enabled | disabled | enabled | enabled | 0xd |
disabled | enabled | enabled | enabled | 0xe |
enabled | enabled | enabled | enabled | 0xf |
Once you know what mask you need to use, run boot0cfg -m $MASK /dev/$DISK
, replacing $MASK
with the mask in the table above, and $DISK
with the disk you want to configure. The disk should be the disk, not a partition (for example, /dev/ada0
instead of /dev/ada0s1
). In our example above, the command would be boot0cfg -m 0x5 /dev/ada0
. The next time you reboot, you should only see the enabled partitions. The mask won’t, however, force a partition boot0
wouldn’t normally show to be shown. It is only capable of disabling partitions that boot0
normally shows.
An important note: you cannot boot from disabled partitions, at all! Trying to hit the key for a disabled partition just results in boot0
printing #
and waiting for another key to be pressed.
One thought on “Using boot0cfg on FreeBSD to configure the bootloader”