Hack 24 Customize the Default Boot Menu


figs/expert.gif figs/hack24.gif

Configure a splash screen.

You're not quite sure what you did to give the impression that you don't already have enough to do. Somehow, though, you were elected at the latest staff meeting to create a jazzy logo that will appear on every user's computer when they boot up in the morning.

While you may not be able to tell from first glance, the FreeBSD boot menu supports a surprising amount of customization. Let's start by examining your current menu to see which tools you have to work with.

3.2.1 The Default Boot Menu

Your default boot menu will vary slightly depending upon your version of FreeBSD and whether you chose to install the boot menu when you installed the system. Let's start with the most vanilla boot prompt and work our way up from there. In this scenario, you'll see this message as your system boots:

Hit [Enter] to boot immediately, or any other key for command prompt. Booting [/boot/kernel/kernel] in 10 seconds...

FreeBSD 5.1 introduced a quasi-graphical boot menu that includes a picture of Beastie and the following options:

Welcome to FreeBSD!   1. Boot FreeBSD [default]   2. Boot FreeBSD with ACPI disabled   3. Boot FreeBSD in Safe Mode   4. Boot FreeBSD in single user mode   5. Boot FreeBSD with verbose logging   6. Escape to loader prompt   7. Reboot           Select option, [Enter] for default           or [Space] to pause timer  10

It is possible to get this menu without doing a full install of FreeBSD 5.1. If you're like me and use cvsup [Hack #80] and buildworld to keep up-to-date, you already have the necessary files but need to do a bit of editing to enable this boot menu. Even if you already have the boot menu, follow along because we're about to discover some of the logic behind the FreeBSD boot process. This will be excellent preparation for learning how to hack in your own customizations.

Let's start by taking a look at the directory that contains all of the boot information. Not surprisingly, it's called /boot:

# ls /boot -F beastie.4th     cdboot*         kernel.old/     loader.rc      support.4th boot            defaults/       loader*         mbr boot0           device.hints    loader.4th      modules/ boot1           frames.4th      loader.conf     pxeboot boot2           kernel/         loader.help     screen.4th

The actual file containing the new menu is beastie.4th. If your sources are out-of-date and you don't have this file, you can download it from http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/boot/forth/. Be sure to download also the latest versions of frames.4th and screen.4th.

The /boot directory also contains the loader executable. This application is responsible for finishing the boot process. To do so, it depends on two configuration files, loader.rc and loader.conf. Let's take a peek at loader.rc:

# more loader.rc \ Loader.rc \ $FreeBSD: src/sys/boot/forth/loader.rc,v 1.2 1999/11/24 17:59:37 dcs Exp $ \ \ Includes additional commands include /boot/loader.4th \ Reads and processes loader.rc start \ Tests for password -- executes autoboot first if a password was defined check-password \ Unless set otherwise, autoboot is automatic at this point

We're aiming to be hackers here, not destroyers of systems. A system that refuses to boot completely is not a very fun system to work on. So, before mucking about with any of the files in /boot, make sure you have your Emergency Repair Kit ready (see [Hack #71] and [Hack #72] for more information). Also, take extra care in your editing and be especially alert for typos before saving your changes.


Lines that begin with a backslash (\) are comments. Additionally, you can add your own comments to lines containing a command by preceding your comment with a # like this:

include /boot/loader.4th    # do NOT remove this line! start                       # do NOT remove this line!

Those are good comments to add, as you want to make sure you never remove those two lines they are necessary to the workings of your boot loader.

Before editing this file, make a backup copy first:

# cp loader.rc loader.rc.orig

Then, to tell your system to use beastie.4th, carefully add the following lines to the bottom of /boot/loader.rc.

\ Load in the boot menu include /boot/beastie.4th \ Do the normal initialization and startup initialize drop \ Start the boot menu beastie-start

Triple-check for typos. When you're ready, make sure that you've saved all of your work and check that no one else is connected to the system. In order to test out the change, you're going to have to reboot:

# reboot

If all went well, you now have a Beastie menu to assist you in your bootup selection. If your boss had something else in mind other than the ultracool Beastie menu, let him know that have you not yet begun to customize!

3.2.2 Configuring the Splash Screen

Remember the other file I mentioned, loader.conf? Well, you should actually have two files with that name. /boot/defaults/loader.conf is the system default, and you should never edit this file. Instead, copy it over to /boot/loader.conf and make your changes there. That way, not only do you have a chance to see what is available for customization, you also reduce your risk of typos. Each line in this file is commented and additional information can be gleaned from man loader.conf.

Locate the Splash screen configuration section so you can configure that company logo your boss keeps insisting on. This is what it looks like by default:

splash_bmp_load="NO"          # Set this to YES for bmp splash screen! splash_pcx_load="NO"          # Set this to YES for pcx splash screen! vesa_load="NO"                # Set this to YES to load the vesa module bitmap_load="NO"              # Set this to YES if you want splash screen! bitmap_name="splash.bmp"      # Set this to the name of the bmp or pcx file bitmap_type="splash_image_data" # and place it on the module_path

Obviously, we'll have to change the NO in one of those splash lines to a YES. Which one depends upon your picture format. The two types of images that can be loaded are bmp or pcx. Depending upon the image you have to work with, change the appropriate NO to a YES.

If the image also happens to have eight or more bits of color, set vesa_load to YES. If you have no idea what type or size of picture you're dealing with, use the file command:

# file logo.bmp logo.bmp:  PC bitmap data, Windows 3.x format, 408 x 167 x 8

This particular logo is a bitmap that is 408 167 pixels at 8 bits of color.

Don't forget to set the path of your bitmap file, and make sure you remember to copy that bitmap to the specified location:

bitmap_name="/boot/logo.bmp"

Leave this line as is:

bitmap_type="splash_image_data"     # and place it on the module_path

Finally, enable bitmap loading:

bitmap_load="YES"

When you're editing /boot/loader.conf, keep in mind that you are asking the loader program to load various portions of the kernel. If you have changed your kernel configuration file [Hack #54], double-check that you haven't stripped your kernel of a function you're now asking loader to load. For example, before rebooting I should double-check that splash functionality is still in my kernel. Here, my new kernel configuration file is named NEW:

# grep splash /usr/src/sys/i386/conf/NEW device        splash        # Splash screen and screen saver support

splash also requires device sc, so ensure that is your console type:

# grep -w sc /usr/src/sys/i386/conf/NEW device    sc

The -w flag tells grep to treat sc as a word rather than attempt to match any word containing the letters sc.

Once you're happy with your changes, make sure no one is working on the system and then reboot. Your bitmap image should appear right after you make your choice at the Beastie menu. It will remain on the screen until you press a key. This behavior has the advantage of displaying your company logo instead of the usual startup messages. However, if you ever need to see those messages, simply press a key and your bitmap will disappear.

3.2.3 The Terminal Screensaver

As it is set up now, the bitmap will also act as a terminal screensaver that will kick in after five minutes. To change the screensaver's timeout value, add this line to /etc/rc.conf:

blanktime="60"

The number you choose represents the number of seconds. If you decide you don't like the screensaver functionality, add this line to /etc/rc.conf:

saver="NO"

Those changes to /etc/rc.conf won't take effect until you reboot the system. To enforce those settings immediately, at least until the next reboot, use the vidcontrol command:

# vidcontrol -t 60 # vidcontrol -t off

Regardless of your timeout setting, you can still launch the screensaver at will say, when you leave your terminal by pressing the Shift and Pause keys simultaneously. You may just want to do that before you go grab your boss to show him that jazzy company logo.

3.2.4 See Also

  • man loader

  • man splash

  • /usr/share/examples/bootforth/ (bootloader examples for the experienced hacker who understands Forth)

  • The Boot section of the FreeBSD Handbook (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/boot.html)

  • http://www.baldwin.cx/splash (splash images to get you started)



BSD Hacks
BSD Hacks
ISBN: 0596006799
EAN: 2147483647
Year: 2006
Pages: 160
Authors: Lavigne

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net