Absolute OpenBSD: Unix for the Practical Paranoid

When your hardware's BIOS finishes counting onboard memory and finding all the system hard drives, it will pass control of the system to the boot loader. The boot loader is a small program that handles initial system configuration and booting the kernel. OpenBSD provides the ability to interrupt the booting process, configure the system before it boots, and adjust your kernel settings, or even boot an alternate kernel. This program is documented in boot(8), but we'll cover some of the basic functions here.

Boot Prompt

When your hardware hands control of the boot process over to the OpenBSD partition, you'll see a prompt much like this.

boot>

The boot loader runs from the BIOS bootstrap loader, and provides very rudi-mentary configuration abilities. The boot program's main purpose is to load the kernel into memory and start it. The boot loader loads the kernel, waits for five seconds, and starts the kernel. Because this runs before the kernel starts, the boot program gives you the opportunity to issue pre-booting instructions to the kernel.

Delaying the Boot

Once this prompt has been idle for five seconds, the system will boot! If you're not exactly sure what you're doing, you might want to tell it to delay the boot for a little longer. You can do this by increasing the timeout value.

boot> set timeout 60 boot>

This tells OpenBSD to boot after being idle for 60 seconds, which is not an unreasonable delay when you're poking around the boot loader trying to figure out what you want to do! Now, let's look at some more useful functions than slowing your system down.

Booting Single-User

Single-user mode is the earliest point where your OpenBSD system can give you a command prompt. At this point the kernel has probed all the hardware, attached drivers to hardware it's going to acknowledge, and started init(8). No file systems are mounted, except for a read-only root partition. The network is not started, no daemons are running, security is not implemented, and file system permissions are ignored. You get a bare-naked command prompt on a minimally running system.

To boot into single-user mode, use the -s flag on the boot command.

boot> boot -s

Why would you want to use single-user mode? Suppose you've upgraded a program on your system, and it now crashes your computer on every boot, before you can log in. A computer can easily get caught in a panic loop where it crashes and restarts until someone manually intervenes and shuts down the offending program. You might have a disk go bad, and crash the system before the boot can finish. Perhaps you made some stupid mistake in configuring your system, and now it just won't finish booting at all, or perhaps you need to clear some file flags (see Chapter 10). Any of these require intervention before the boot finishes.

Generally speaking, you want a fully functional file system before doing much of anything in single-user mode. If your system crashed, you'll have to check the file system consistency before mounting any file systems. The following commands will clean and mount all of your file systems. (fsck(8) and mount(8) have many more options; check out Chapter 18 for the most common ones or the man page for the full gory details.)

# fsck -p # mount -a

Once you're in single-user mode and have your file systems mounted, all of the usual command-line functions should be available. You can edit configuration files, start and stop programs, and generally do whatever you like. What exactly you want to do depends on exactly what your problem is.

Starting the Network in Single-User Mode

The shell script /etc/netstart can start the network while in single-user mode. You could go and run all the appropriate commands by hand, but /etc/netstart will read the appropriate /etc/ files and do all the grunt work for you. You need to explicitly run this script through sh(1).

# /bin/sh /etc/netstart

Of course, if network configuration problems are why you're running in single-user mode, this script will only re-create your problem!

Booting in Kernel Configuration Mode

The -c flag to boot makes the system come up in kernel configuration mode. This allows you to change some of a kernel's built-in constants. We'll discuss this at great length in Chapter 11. For now, you just need to know that the mode exists so that other examples here make some sort of sense.

Booting Alternate Kernels

You can choose to boot a kernel other than /bsd. You might need this if you're building your own kernel, as discussed in Chapter 11. Just give the boot command the full path to the kernel you want to boot. For example, if your kernel in /bsd is faulty and you need to boot off your known-good /bsd. GENERIC kernel, do the following:

boot> boot /bsd.GENERIC

This should get your system up and running and let you install a proper kernel in /bsd.

You can use any other boot flags with this. For example, boot -s /bsd. GENERIC will boot the GENERIC kernel in single-user mode.

Booting from an Alternate Hard Disk

You might have multiple OpenBSD installs on different hard disks on one computer, for either testing or redundancy purposes. By default, OpenBSD boots from the first disk it finds. If you have four IDE disks, for example, it boots from the first disk on the first IDE controller. You could have a separate root partition installed on another disk, with a separate /etc/fstab pointing to emergency /usr and /var partitions.

To tell the boot loader to use a root partition on another drive give the full path to the kernel you want to boot, including the device name of the drive the root partition is on. This is much like booting an alternate kernel, just adding the hard drive device name as part of the path. Here, we boot the kernel /bsd.old on the "a" partition (traditionally root) on the third IDE hard disk, also known as "wd2a." (If you have four IDE disks, this is the master drive on the second controller.)

boot> boot wd2a:/bsd.old

The OpenBSD installer will do its very best to put the root partition on the "a" partition, but if you managed to put it elsewhere you will have to enter the proper partition here.

Other Useful Boot Commands

If you forget which kernels you have on a system, the "ls" command lists all the files in the root directory. You can list other directories on the root partition by giving a full path, i.e., "ls /etc."

The "boot" command by itself will boot the system immediately, without waiting for the five-second timeout. Similarly, the "reboot" command tells the system to do a warm boot.

The "help" command lists all available boot loader commands, including the less frequently used ones that we don't discuss here. If you want truly detailed help with the boot loader, however, you should go read the boot(8) man page.

Finally, you can combine the boot flags to achieve exactly the effects you want. To boot an old kernel in single-user mode, you would do this:

boot> boot -s /bsd.old

Категории