Saturday, July 12, 2008

Using the FreeBSD Boot Loader

7/12/2008 09:40:00 PM |

Note: Lynx doesn't render this page properly, I'll need to figure out how much CSS support it has first. NS4 and IE5 work, but not how they should.

How the loader works

The FreeBSD boot third stage bootstrap loader (loader(8)) loads the kernel and various types of modules including splash screens, screen savers, networking drivers, etc.

Loader startup

Loader is started by the second stage bootstrap loader. The location of the loader is specified by boot.config and is usually /boot/loader. When the loader is started, it first reads /boot/boot.4th if it exists, then reads /boot/loader.rc, but if it can't be read, /boot/boot.conf will be read. The loader.rc file usually contains the following lines:

\ Loader.rc
\ Includes and processes loader.rc
include /boot/loader.4th

\ Reads and processes loader.rc

\ Unless set otherwise, autoboot is automatic at this point

The lines preceeded by a "\" are comments, the line starting with "include" processes a 4th/ficl script and "start" begins the booting of the kernel. Loader.conf processing Loader.4th processes the files /boot/defaults/loader.conf and /boot/loader.conf. These two files work just like the rc.conf files. The file in the defaults subdirectory should not be touched. This contains examples of many of the commands that you can use to load modules. All changes should be made in the /boot/loader.conf file.

Booting FreeBSD from different BIOS drives

In order to boot FreeBSD from a drive other than the default BIOS drive, you will need to set the following two paramaters:

The first line tells the loader where the kernel and modules are at. In this case it will be the third BIOS drive. The second line tells the loader what device number should be used. In this case it will use wd0, da0, etc, depending upon the necessary drive type. When loader starts it will list all of the drives detected by BIOS followed by their disk numbers. It will look something like this: ...
BTX loader 1.00 BTX version is 1.01
Console: internal video/keyboard
BIOS drive A: is disk0
BIOS drive C: is disk1
BIOS drive D: is disk2
BIOS drive E: is disk3
BIOS drive F: is disk4

FreeBSD/i386 bootstrap loader, Revision 0.7 639/64448kB

On my system I have a 3.5" floppy (disk0) two SCSI drives (disk1 and disk2) and two IDE drives (disk3 and disk4) in my machine. The SCSI drives contain Windows95 and the IDE drives contain FreeBSD. Since FreeBSD is located on the third BIOS drive, loader will get confused and attempt to mount / from wd2 which doesn't exist. Specifying root_disk_unit="0" will tell loader to mount root from wd0, where it is supposed to be. (For reference, my boot.config countains 2:wd(0,a)/boot/loader so FreeBSD won't try to run loader from wd2. For more about this booting "problem" see TROUBLE.TXT on the root of an installation CD-ROM, or at Loading a splash screen
Once you get FreeBSD booting like it should, you can add a splash screen. This will give you something pretty to look at while you wait for FreeBSD to finish booting, and will also give you a lovely screen saver (if you don't load one on top of it.) First you will need to get a splash screen. A splash screen must be in the format of a color Windows BMP or a version 5 8-bpp single-plane ZSoft PCX less than 1024x786 (limitations on video memory and VESA BIOS may apply.) You can either make your own, or download one from the FreeBSD Splash Screen Gallery. Before you can load a kernel, you will need to do a few things:

Make sure pseudo-device splash is in your kernel.
Add the following lines to /boot/loader.conf:
splash_bmp_load="YES" # For Windows .bmp files or
splash_pcx_load="YES" # For ZSoft .PCX files (one or the other)
vesa_load="YES" # If the image is greater than 320x200
bitmap_name="/boot/splash.bmp" # Name of the splash image file


Instructions on compiling kernels can be found in the handbook here if you installed FreeBSD documentation on your hard drive, or here on if you haven't. In order to use the VESA module you will have to add options "VM86" to your kernel to get the splash screen to work. You can compile the VESA module straight into the kernel, but if you use a different screen saver, you won't be able to unload it and save kernel memory. The splash image will need to be on the root disk.
When the machine reboots you should see something similar to the following:

Loading /boot/defaults/loader.conf
/kernel text=0x161db8 data=0x218ac+0x223fc syms=[0x4+0x23040+0x4+0x243e4]
/modules/splash_bmp.ko text=0x10f9 data=0xc8+0x66c syms=[0x4+0x420+0x4+0x230]
/modules/vesa.ko text=0x2330 data=0xea0+ox23c syms=[0x4+0x7a0+0x4+0x585]
Hit [Enter] to boot immediately, or any other key for command prompt.

And then the splash screen should come up. If it doesn't and you see a line such as:
module_register_init: MOD_LOAD (splash_bmp, c02ee62c, 0> error 19

your video card may not support VESA modes without an additional software driver. You will need to use a 320x200 splash screen. Loading other modules

Many other modules are available for loading from /boot/loader.conf. If you often use linux binaries, linux_load="YES" can be added, the tun device used for ppp can be loaded and unloaded on demand: if_tun_load="YES" and many others. The advantage of the modules is that they can be loaded and unloaded as needed, and don't require a kernel recompilation and reboot in order to increase functionality. Loadable filesystems include:

ISO 9660 fs (CD-ROM)
Filedescriptors fs
Kernel fs
Memory fs
FAT-12/16/32 fs
Null fs
Portal fs
Proces fs
User-id map fs
Union fs

In order to see the whole list check out /boot/defaults/loader.conf, then just drop the appropriate line into /boot/loader.conf.

You Might Also Like :