(Tip) kernel.gen: the 'ultimate' failsave

Hi gang,

The one thing I love about FreeBSD apart from it's maturity and professionality (just check the handbook, the handbook itself is in my humble opinion proof of this) is its customization.

Like so many I prefer to customize my environment. Both the base OS as well as the kernel, clean, to the point and even a security aspect: no overhead features which could be (theoretically!) abused. So far, so good. Especially on my VPS & laptop (where the hardware is quite unlikely to change) do I prefer customization on the kernel.

So how to cope when things do change? Well, this works for me:
  • Build a GENERIC kernel (it's the default, when in doubt: # cd /usr/src && make KERNCONF=GENERIC buildkernel).
  • Install it ('somewhere') then rename the installation directory to kernel.gen.
    • Warning: make sure to (re)install a valid kernel as replacement!
  • Summing up: If you're following this tip then you'll now have the following sub directories in /boot: kernel, kernel.old (optional) and kernel.gen.
  • Edit /boot/menu.4th
Specifically, replace this line:

s" kernel kernel.old"
With this:

s" kernel kernel.old kernel.gen"

The result?

Quite simple and very effective: when stuff does go horribly bad then all you have to do is press S within the boot menu twice. First time it'll try to use the backup kernel (kernel.old), but the second time you press this it'll try kernel.gen. The variant which is bound to work because it supports a wide range of (popular) hardware.
Just a tip to add to this: you don't actually need to edit the menu file. Any directory with the naming convention /boot/kernel.<kernel_name> should appear in the boot menu. You can install a kernel to such a directory with make installkernel KODIR=/boot/kernel.<kernel_name>. You can also boot any kernel by dropping to the boot prompt and typing boot kernel.<kernel_name>. I always keep /boot/kernel.generic installed and up-to-date for emergency purposes. ;)