As we’ll cover in tedious detail in Chapter 18, you can configure the OpenBSD kernel, but before you do so, be sure that you can boot alternate kernels. You’ll need to be able to boot a different kernel if, say, you hose your filesystem so badly that it won’t even boot to single-user mode, and you need to recover using the installation kernel.
An OpenBSD installation includes three kernels out of the box: the single-processor kernel /bsd, the multiprocessor kernel /bsd.mp, and the upgrade and install kernel /bsd.rd. (If your machine has multiple processors, the installer renames /bsd to /bsd.sp and /bsd.mp to /bsd.)
To boot a nonstandard kernel, first reboot and interrupt the boot process at the boot loader prompt. Run boot
, and give the full path to the kernel you want to boot:
boot> boot /bsd.rd
This will start the system using your chosen kernel. You can use other boot options as well, such as booting the alternate kernel in single-user mode:
boot> boot -s /bsd.sp
This will let you recover from a bad kernel, try a new kernel, or anything in between.
Suppose you’ve really fouled everything up beyond all recognition, and you don’t have a usable kernel on your root partition. Fortunately, if you have a usable kernel on a different hard drive, you can boot from that. (Usually, this kernel lives on an alternate root partition, /altroot, as discussed in Chapter 8.) In this section, I’ll break the task of booting from that alternate kernel into a few steps: finding the hard disk with the partition, finding the partition with the file, and booting the right file on that partition.
Once you’re familiar with OpenBSD, you may begin to think of the hard drives in your system by their device names, such as /dev/sd0, /dev/wd1, and so on. Unfortunately, those are the kernel’s names for the disks; the boot loader recognizes only the BIOS’s disk names.
To ask the boot loader about disks, use the machine diskinfo
command:
boot> machine diskinfo
Disk BIOS# Type Cyls Heads Secs Flags Checksum
fd0 0x0 *none* 80 2 18 0x4 0x0
hd0 0x80 label 1024 255 63 0x2 0x51db843d
hd1 0x81 label 1024 255 63 0x2 0x9329b723
hd2 0x82 label 1024 255 63 0x2 0xcfadb343
boot>
Here, the boot loader has found four disk devices. The first, fd0
, is a floppy disk drive. This drive might or might not have a disk in it, but whatever it has, it’s almost certainly not your alternate kernel. (It might be an installation disk, though, so don’t automatically rule out using it for disaster recovery.)
The other three devices—hd0
, hd1
, and hd2
—are hard disks. The first, hd0
, is the default system boot disk. If you can’t boot from that disk, you need to find the hard disk that contains your kernel.
Vague stirrings of memory in this output lead me to think that hd2
might be the disk that holds my backup root partition. To try it, tell the loader that disk partition hd2a
is the new root partition:
boot> set device hd2a
Before trying to boot from this partition, look at its contents:
boot> ls
stat(hd2a:/.): Invalid argument
boot>
Apparently, disk hd2
has no partition a
. After service is restored, I’ll take this disk out behind my garage and beat its weakness out of it. For now, let’s try the only remaining disk, hd1
.
boot> set device hd1a boot> ls drwxr-xr-x 0,0 512 . drwxr-xr-x 0,0 512 .. drwxr-xr-x 0,0 512 altroot drwxr-xr-x 0,0 512 home drwxr-xr-x 0,0 512 tmp …
This looks like an actual root partition (altroot
offers a hint).
At this point, we could boot a different kernel, but we’ll just boot the /bsd kernel on this partition in single-user mode, because the filesystem table would have the incorrect entry for the root filesystem, which would mess up all sorts of stuff.
boot> boot -s
booting hd1a:/bsd: 5669864+1601484+935608+0+617568 [89+499848+323884]=0xd351b8
…
Alternatively, you could give the device name at the boot prompt:
boot> boot -s hd1a:/bsd
As a general rule, you should mount the actual root partition on /mnt, make the necessary changes for normal operation, and reboot into the proper root partition. You could also boot the /bsd.rd kernel, giving you a cleaner boot at the cost of having fewer tools available.