Solved What is the proper way to deal with broken kernel?

I have been a Linux user for a long time, and begin to experiment with FreeBSD only recently. The reason is that I want to see how tcp/ip network stack is implemented, but the Linux code base is hard for me to parse. I am lucky to find a McKusick's The Design and Implementation of the FreeBSD Operating System in a public library. So I decide to take a look at FreeBSD.

I run a instance of FreeBSD in qemu, and track svn head to see most recent changes. (Perhaps it's a bad choice for me). I follow the advice in the handbook to build the kernel and world. However after installing the kernel and reboot, it can't even boot into single user mode. (This bug has been fixed in a more recent commit today).

Here are my three question as a newbie.
  1. Linux distributions often keep several versions of kernel, so in case one failed I can boot into another. Is there any way to achieve this in FreeBSD?
  2. Is it OK to boot from a FreeBSD ISO image, mount the virtual disk(with broken kernel in it) in qemu, build the kernel, and install the kernel to the virtual disk? If it is possible, where can I find documentation to do that?
  3. Can I just copy the kernel in the FreeBSD ISO image into the virtual disk with failed kernel and replace it?
My biggest lesson is to save a snapshot for FreeBSD vm before installing new kernel. But in case I run FreeBSD on bare metal, there is no such easy way to recover.

Thanks for reading this thread. Any feedback is welcome.
 
  1. If you install a new kernel, the old one gets saved as kernel.old. You can also save a known good kernel as kernel.good for example. Or kernel.RELEASE, or whatever else you like. Simply copy the /boot/kernel directory to /boot/kernel.GOOD.
  2. Sure, I've rescued more than one server that way. No need for qemu though. Boot from the ISO, mount the filesystems and you're good to go.
  3. Yes, but beware of dragons, i.e. a different version of the kernel compared to the rest of the userland (aka 'world').
 
While kernel.old is certainly helpful and saved us all a lot of times.. If you use ZFS, the best answer (IMO!) is Boot Environments (see bectl(8)). That way you are installing new bits into new BE, and boot into it selecting it in boot loader menu. If everything is OK, you activate it; if not, you simply boot to old one (and fix things as needed).
 
If you use ZFS, the best answer (IMO!) is Boot Environments (see bectl(8)).
If you're using ZFS then this is indeed a really good solution. But for just mucking about with the kernel it may be a little overkill. Simply saving a known good kernel saved my bacon more than once.
 
Sure, I've rescued more than one server that way. No need for qemu though. Boot from the ISO, mount the filesystems and you're good to go.

I don't quite understand how to do that. Let say I build kernel and world in another machine(machine1). Mount the disk(disk0) with broken kernel in it.

How do I install both kernel and world to disk0 from machine1? I guess kernel installation can be done by copying /boot/kernel. What about world?
 
It's been a while since I needed it but the installation media has a "live" option. That will allow you to mount the original disks on /tmp/disksroot for example. Compiling world (or the kernel) can be done from any directory, it doesn't necessarily have to be /usr/src. The installworld and installkernel stages allow you to set DESTDIR as a base of the install.

For example: make installworld DESTDIR=/tmp/somewhere
 
Back
Top