Last week I could not attend to my Case Studies I lesson (I am studying the Official Master’s Program on Libre Software at Universidad Rey juan Carlos), and it was about compiling the Linux kernel. What a pity! I’ve never compiled nor customized too much my Linux systems so it was a chance to overcome my fears.
But it is nice to know that the teacher uploaded the video-recorded session and the documentation used on it in the Case Studies I Moodle Course. So last night I watched the video and took a look at the documentation, and ok, it seems easier than I thought, but a big doubt came to my mind:
“Let’s say that I customize my kernel and compile it, and it works very well; but what happens when a new release comes out? Ain’t not easy-solution as apt-get && apt-upgrade any more isn’t it?”
Since I could not attend to class, I had to search and find the answer on my own. And I can say that the answer is that the process of upgrading a customized kernel can be quite automated, at least theoretically.
In the “Linux Kernel in a Nutshell” book there is a chapter specifically dedicated to this. I will try to summarize the process.
Assume that you are running a customized version of 2.6.32-25 kernel, and a new release, 2.6.32-26 is announced.
The first think is to know that almost all the work can be done with normal user account. Only the two or three commands it takes to install the new kernel should be done as the superuser (root).
The second thing is backup the configuration of your actual kernel so if anything goes wrong you don’t need to spend again all the time to get your old customized-and-working configuration. Supposing that your working and customized kernel sources are on ~/linux/linux-188.8.131.52-canela folder:
$ cd ~/linux/linux-184.108.40.206-canela $ cp .config ../good_config
Later you have to follow these steps:
1.- Get the new source code.
2.- Apply the changes to the old source tree to bring it up to the newer level.
3.- Reconfigure the kernel based on the previous kernel configuration.
4.- Build and install the new kernel.
These steps can be done manually or in a semi-automated way. First I will explain manually and later I will introduce several tools to automate the process.
1.- Download the new source
You don’t need to download the complete source code, you can download just the patch that can upgrade your running kernel release to the newer one: you go to kernel.org and you download the incremental patch from your running version to the newer one (in our example we would download http://kernel.org/pub/linux/kernel/v2.6/incr/patch-220.127.116.11-26.bz2. You can decompress the files on ~/linux/patch-18.104.22.168-26.bz2
2.- Apply the changes to the old source tree.
I said before that your running kernel sources were at ~/linux/linux-22.214.171.124-canela. So we go there and apply the patch:
$ cd ~/linux/linux-126.96.36.199-canela $ patch -p1 < ../patch-188.8.131.52-26
After our kernel sources are updated, we rename the sources folder:
$ cd .. $ mv linux-184.108.40.206-canela linux-220.127.116.11-canela
3.- Reconfigure the kernel based on the previous kernel configuration
Since we already have a working configuration, instead of make menuconfig, we can use the commands make oldconfig or make silentoldconfig.
Both take the current kernel configuration in the .config file to apply the settings to the new kernel, and both also stop and ask the user, if there is a new option, what the new configuration value should be set to.
The difference between them is that make oldconfig printouts all configuration questions, providing also the answer if the option is already handled in the configuration file.
On the other hand, make silentoldconfig does not print anything to the screen, unless it needs to ask a question about a new configuration option.
So we can apply the configuration to the kernel by:
$cd ~/linux/linux-18.104.22.168-canela $ make silentoldconfig
4.- Build and install the new kernel.
This can be done as explained on the Case Studies video.
The automation tool
ketchup is a command-line tool to manage your Linux kernel sources. With ketchup the process of download the sources and apply patches can be automated. In short we could upgrade our customized and working kernel with these commands:
$ cd ~/linux/linux-2.6.32-25-canela
$ ketchup 2.6
$ make silentoldconfig
Note: If Ketchup should abort with a gpg error, then it couldn’t verify the patch’s or kernel’s signature. Add the 2.6 public key to your keyring:
$ gpg –keyserver wwwkeys.pgp.net –recv-keys 0x517D0F0E