One thing that makes Linux stand out is that if you have the knowledge, you rarely have to reboot your computer just because you made some changes. Usually, you can get by with restarting the particular service or module that was affected. You do have to reboot when you want to change the kernel, however. Because the kernel sits at the core of everything, the whole system has to be reloaded.
There is a way around it; well, sort of. When you reboot, you’re completely stopping the system, then letting the firmware/BIOS and bootloader start the kernel again. But you don’t have to drop down to the firmware or bootloader if all you want to do is replace the kernel. In fact, the Linux kernel is capable of unloading itself and handing control over to a different (or the same) kernel, resulting in a much faster reboot. What makes the process tricky is that the new kernel needs to be loaded in memory exactly where the current kernel sits, but the current kernel needs to be running in order to load the new kernel. We don’t have to worry about this because the crafty Linux kernel engineers have figured out a way.
Enter kexec; or, restarting the kernel without rebooting the computer. There’s a wonderful article over at IBM developerWorks that explains how it works. I’d been wanting to give this a try, but the article makes the process seem quite hairy. That was almost four years ago. I just tried kexec on my Ubuntu 8.04 laptop, and it worked almost flawlessly.
To use kexec, you must first install the kexec-tools package available in the universe repository. After that’s installed, the following two commands restart the kernel (it’s also possible to start a different kernel):
$ sudo kexec -l --append="`cat /proc/cmdline`" --initrd=/boot/initrd.img-`uname -r` /boot/vmlinuz-`uname -r` $ sudo kexec -e
Almost flawlessly? Well… after the system was restarted, I somehow lost control of the keyboard and the touchpad. The machine was responsive on the network, though. This may be because kexec doesn’t clean up; it just reloads the kernel. It should work much better once it’s integrated with the standard reboot/shutdown processes. For now, kexec seems to be coming along very well.