Share Tweet Share





I was having an interesting conversation with my BSD buddies on whether Ubuntu is suitable/not for servers and I did my usual bragging about the servers not needing to be rebooted. I was then asked about kernel updates and a wish was expressed for an ability to update kernels without having to reboot the server. This started tickling a few memory cells which hadn’t yet been wiped out by various substances and/or old age so I went to my knowledge repository (otherwise known as Google) and dragged up some info. I was pleased to find that things had progressed since I last looked at it and even better. The current *buntu and Debian kernels are ready for it. You are probably wondering what it is so before you bust your britches I will tell you. It is called kexec and it is a method of changing Linux kernels without having to physically reboot the computer. In other words changing a Linux kernel is just about as easy as stopping and starting a normal service. There is one caveat. This only works on x86 platforms. Fine by me because I use x86 platforms 🙂 So I thought WTF (just think Risky Business the movie) and decided to give it a go. I am now wondering why I didn’t try it before. Installation was super simple. Kexec is a two part beastie. It consists of the kernel part which is patched into the vanilla kernel. Debian and *buntu distributions already have that patched in. Then there is the user part which is the kexec program. This is installed simply by typing “aptitude install kexec-tools”. Not too heavy, not too light, its just right. After I installed kexec which took a grand total of thirty seconds I just had to give it a try. First of all I tried it in a virtualbox session but virtualbox didn’t like that and just sat there spinning its wheels until I killed it. So I decided to try it on my desktop. I had several kernels installed on my system so I did a quick cat of my grub menu.lst to see them. Here is an abridged output. locutus@borgship:~# cat /boot/grub/menu.lst kernel /boot/vmlinuz-2.6.24-21-generic root=UUID=xxx-xxx-xxx ro quiet splash initrd /boot/initrd.img-2.6.24-21-generic kernel /boot/vmlinuz-2.6.24-20-generic root=/dev/hda1 ro quiet splash initrd /boot/initrd.img-2.6.24-20-generic I only have two kernels listed here but there are more. Using that information it was easy to set up the kernel to boot into. First I had to load the kernel into memory by typing. “kexec -l boot/vmlinuz-2.6.24-20-generic –append=root=/dev/hda1 ro quiet splash –initrd=/boot/initrd.img-2.6.24-20-generic” As you can see the info is copied straight from the grub menu. Once the selected kernel is loaded into memory, which pretty much happens instantaneously, it is just a matter of activating that kernel. This is done quite simply by typing “kexec -e” The computer then acts as though it has rebooted but instead of taking a couple of minutes it only takes a few seconds. This is because it does a warm boot instead of a cold boot like when your computer is physically rebooted. Of course any open programs are closed and connections are cut just as though the computer has been physically rebooted but those services are restored in far less time than a normal reboot. In fact to make sure of it I remotely connected into another computer and tried it out. This computer is a web, file and chat server and I was connected via ssh. I selected my kernel and did the kexec deed. Sure enough I was cut off so I counted to ten and tried to reconnect, which I did. Normally If I do that I would have had to wait for about five minutes while the computer power cycles and comes back up. So all in all it (ie kexec) is a great time saver and very useful tool if you like to play around with different kernels. For mission critical machines which require more than five ball uptime I would say it is essential.