“Kernel Recompilation“. Man! what a dreadful name, there’s been a lot of hype surrounding the 3.0 kernel and as the saying goes “you’re virgin until you compile your first kernel” so all you trekkies out there know what to do now.
I’m using my favorite distro: Slackware 13.37
Why and when do we need to recompile a kernel ?
- Add new features to the kernel (ie: Hardware support for a particular device)
- Security updates and patches
- upgrade to the latest version
I- Download the kernel source code
From www.kernel.org, it’s the HQ for the latest kernels and upstream fixes, but It’s down for the time being so we’re gonna make our way with a different mirror. I’ve picked up V 3.0.4 but you can choose whatever suits you.
/usr/src/ is the preferred location, however, you can untar and install wherever you want, for other distros like Red Hat, you can directly install in /usr/src/linux)
# cd /usr/src
#tar -xzvf linux-3.0.4.tar.gz
At this point, we’ve downloaded and uncompressed the source code, the next step is to remove the symbolic link to the old kernel and create a new one pointing to the kernel we’ve just downloaded:
#ln -s linux-3.0.4 linux
Since we don’t wanna configure the kernel from scratch we’re gonna copy the old configuration and then tweak it a bit to meet our requirements :
#cp /boot/config .config
Now, here’s the interesting part; configuration, this can be done in three ways:
- make menuconfig (command line)
- make xconfig (X Window based graphical environment)
- make config (this is a yes/no based process and it’es very tedious, don’t choose unless you’ve lost a bet or something)
Tip: To help identify your hardware to enable the right features when configuring, you can run cat /proc/cpuinfo to retrieve information regarding your processor family, I’ll go with the core 2/newer xeon here . Use the libpci-based command lspci to display information regarding all PCI devices on the system including Network, Graphic Cards, etc.
For the purpose of this guide here, we’ll go on with xconfig, you can add some features like High-Memory support if you have more than 4GB of RAM, KVM support, SCSI device support, preemption model, special drivers etc
After you’re done, save and close the config window.
If you’re using a 2.4 kernel you might need to build a list of dependencies with make dep, otherwise skip this to the next step:
# make bzImage
This will compile the kernel, and place it as a compressed file under arch/i386/boot then to compile the modules and install them:
This will copy the modules in /lib/modules/ .
Tip: The compilation process might take an important amount of time. Another compilation algorithm is faster then the one used with “make bzImage” but less effective (it might generate some errors if the kernel is too large), you can give it a try by running make zImage . Another technique is to use make -j<number> bzImage where “number” is the number of your processors, so in my case since i Have two processors I would process make -j2 bzImage , make -j2 modules, make -j2 modules_install
Next, move the recently compiled kernel to the boot directory ( it will be later on loaded into the memory at start up)
#cp arch/i386/boot/bzImage /boot/vmlinuz-3.0.4
If you’re recompiling the same kernel version then don’t forget to add -custom to the EXTRAVERSION (so it will look like this vmlinuz-3.0.4-custom) this way it won’t interfere with the old kernel.
Copy the System.map (this is an optional step for this file which is used by the kernel to map symbol names to their addresses in memory.)
#cp System.map /boot/System.map-3.0.4
Delete the link to the old System.map:
Make a symbolic link for that specific kernel :
#ln -s /boot/System.map-3.0.4 /boot/System.map
At this point we’re done, still we should make an entry for that new kernel in lilo. Open the file /etc/lilo.conf
you’ll find the old entry, use it as template for the new one for example the old entry looked like this
image = /boot/vmlinuz
root = /dev/sda2
label = Linux
The new one would look like this
image = /boot/vmlinuz-3.0.4
root = /dev/sda2
label = CustomKernel
Save and close, to update the bootloader run:
Now reboot into your new kernel and check its version with uname -r. That’s it!
Tip: it’s always safe to keep an entry for the old kernel until you’re sure that the new one is working fine, this way, if anything goes wrong, you can always use the old kernel for recovery.