Kernel hacking — part two
Linus Torvald’s original 1991 Linux kernel contained just 20,000 lines of source code.
Geoff Palmer | Monday, June 27 2005Linus Torvald’s original 1991 Linux kernel contained just 20,000 lines of source code. By the time of version 1.0’s official release three years later it had grown to 170,000 lines. Two years on and the version 2.0 source tree had more than 400,000 lines of code. Version 2.4, released in 2001, cracked the two million mark while the latest version, 2.6, has close to three million lines of code. And last month you turned all that source into a bootable Linux system with just half a dozen commands.
What we built last time was a “vanilla” or standard kernel. Vanilla kernels are as acceptable as vanilla ice cream, but with Linux we don’t have to live in a one-flavour world. Via the make menuconfig process you’ll have discovered how to modify, build-in, modularise and remove a vast range of “componentry”, but that’s just the beginning. There is also a huge range of what I like to think of as kernel clip-ons. In Linux they’re called patches.
There are two routes for adding functionality to the kernel. The big stuff, such as support for multiprocessor architectures, requires a great deal of work from a large number of people and so tends to get a specific kernel release all to itself. (The addition of SMP is one of the major differences between 2.4 and 2.6.) But smaller stuff, often what an individual considers a nice-to-have feature, invariably first appears as a kernel patch. If the feature proves popular and stable it’ll often find its way into future official releases.
Some patches add features, others remove them. A vanilla kernel can be used on a server and a desktop machine but why bother to include functionality if you’re never going to use it? By targeting a specific niche — say, desktop users — you can optimise the performance for one particular group.
Table 1 below gives a flavour of some of the common patch sets for Linux. It’s by no means comprehensive. There are hundreds if not thousands of patches available!
The process of patching a kernel is quite straightforward but you should always start with a vanilla kernel from kernel.org. (Most vendor kernels already contain patches. Trying to add patches on top of patches is a job for experts!)
Most patches assume your kernel source is in /usr/src/linux. This almost certainly isn’t the case. Your source code will be in a folder with a name like /usr/src/linux-2.6.11 so the first step is to create a logical link using the command ln -s linux-2.6.11 linux while in the /usr/src directory. If you now type ls -l you should see a little arrowhead indicating the /linux directory actually points to folder /linux-2.6.11.
For variety, and to confuse newcomers, patches may be compressed in one of four different formats, so you’ll need the right decompressor (see Table 2 above).
Move the uncompressed patch to /usr/src.
The patch process simply adds, removes or replaces lines of code in the kernel. The commands cd /usr/src/linux followed by patch -p1 < ../my.patch should do just that.
Sometimes patch and kernel numbers don’t quite marry up. You may have a 2.6.8 patch that you want to apply to a 2.6.11 kernel, for example. In spite of the difference in revision numbers the patch may work okay. Test it by adding the --dry-run parameter to the patch command. It’ll check whether the changes can be made without actually applying them. To remove a previously applied patch use the -R parameter.
It’s important to examine the README file that comes with the patch as that will detail the kernel settings the patch has added. These will need to configured in make menuconfig. And some patches like Supermount and SWSUSP require changes to configuration files too.
Ready-made kernels
You don't have to build your own kernel to avail yourself of the latest features. All distros release regular updates and they’re a doddle to install.
Mandrake
The root command urpmi kernel- will list all available packages beginning with “kernel-”. If there’s a later one than that shown by uname -r, give its full name to urpmi to install it.
If, after the file’s been downloaded, you get a message about it having a bad signature, compare the GPG# produced with that at bottom of web page mandrakesoft.com/security/advisories. If it matches, you’re okay.
Fedora Core
The availability of new kernels is shown in FC’s Up2Date GUI, though you have to specifically check a box before the system will install it. In both cases a reboot is required for the new kernel to be loaded. In Fedora, the new one becomes the default boot menu item. In Mandrake, it’ll be the last item on the menu. If you want to make it the default you’ll have to manually edit /etc/lilo.conf and then rebuild the menu with the lilo command. It’s also worth keeping an eye out for kind souls offering pre-built, pre-tested kernels with the extra features you want. Fedora users for example can download a kernel incorporating Software Suspend from http://mhensler.de/swsusp
Tablets tested: Can anything knock the iPad off it's number one spot? We round up 13 tablets.
Smart storage:
We test five NAS boxes.
Web Browsers:
Latest versions speedtested.
Hot Products || PC World editors iPhone 4S launch pics and unboxing
The iPhone 4S launched at midnight through both Vodafone and Telecom. ... READ MORE
Tux Love || Geoff Palmer Linux Mint: From scratch - Part III
Now you've tried Mint, you'll want to install it properly. If you're ... READ MORE
Tech Guy || Juha Saarinen Pumping ultrafast packets
Why thirteen is lucky for broadband speed tweaking Net nostalgia: One of ... READ MORE
In a Nutshell || Zara Baxter Logging, not login
At an event in Singapore yesterday, Seamus Byrne, the editor of CNet ... READ MORE
Harley O'Gyver || Harley Ogier Braver than a barrel of codemonkeys
If you've ever wondered, "can a grown man really do that?", Harley O'Gyver ... READ MORE
The Arcade || PC World editors Are HD remakes really necessary?
Remember all those games you loved in the 90s and early 00s? Well, now ... READ MORE
Dumb Terminal Live! || PC World editors New Zealand memes: We think we're real funny
We New Zealanders love the internet, and we have a pretty good sense of ... READ MORE






