Recompiling the Mandrake Kernel
CONVENTIONS USED

This is one of the most requested tutorials, and since I've got this down to a few simple commands that I have memorized, I decided it'd be easy to write up a tutorial now. If I was asked about 4 or 5 months ago, which I was, I couldn't have said that I have ever recompiled a kernel. But now I have, and it is quite easy to do if you cheat a little bit.

I will assume that you have the necessary packages installed. If you are able to compile software, then you should be good to go. Also, you will need your kernel-source installed. This tutorial will be based on Mandrake 9.0, using the kernel that comes with it. But you can adapt this simply by changing the numbers where appropriate to reflect whatever version you are using.

First thing to do is open up a console. Change over to the root user account using su.

Now, type in cd /usr/src/ and hit Enter.

Type in rm -f linux and hit Enter. This removes the old symlink.

Next, we will make a copy of the Mandrake kernel source. To do this, type in cp -a linux-2.4.19-16mdk linux-2.4.19-1custom and hit Enter.

Once that is done copying, type in ln -s linux-2.4.19-1custom linux and hit Enter. This re-creates the symlink, but points it to the new source directory.

Next, type in cd linux and hit Enter.

Now, do make mrproper.

Now, using your favorite text editor (I use vim), open up the Makefile and change the fourth line to say EXTRAVERSION = -1custom instead of whatever is there by default.

Save that file and quit out of the editor.

Next, we would normally run a configuration program, but because we probably don't know exactly what we're doing, we will cheat a little. Type in cp ../linux-2.4.19-16mdk/.config .config and hit Enter. This copies Mandrake's config file, and we can use this as a basis for the new kernel. It is also a good idea to keep backups of good kernel config files, so that you can easily duplicate your configuration at a later date.

Next, type in make menuconfig. It'll compile the program and then run it. If you don't know anything about this program, you can take a look around in it a bit to see what all is there. If there is anything that you are sure of that you don't need or don't have, you can probably disable it. If you are unsure, just leave everything as it is. Use the arrow keys to navigate the menus. When you are ready, push the Right Arrow key once so that it is selecting Exit, and then hit Enter.

You will be asked if you want to save your configuration. Say yes by just hitting Enter.

Now, type in make dep clean bzImage && make -j3 modules and hit Enter. The system will begin compiling the kernel and the modules, and it should take a long while. Check on your system periodically, or just go away for a half hour or more and come back and it should be done.

If there are no visible errors on the screen, then everything has been compiled properly. Now, type in make modules_install and hit Enter. Once that is done, go on to the next steps.

Type in cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.19-1custom followed by Enter. This is the actual kernel.

Next, do cp System.map /boot/System.map-2.4.19-1custom to copy this file.

Finally, copy the config file over as well: cp .config /boot/config-2.4.19-1custom followed by Enter.

Now the new kernel is installed. There are still two more steps to do.

Make a new initrd firstly, by typing in mkinitrd /boot/initrd-2.4.19-1custom.img 2.4.19-1custom and pressing Enter.

Once that is done, you need to edit your bootloader's config file. I use Grub, so this tutorial will focus on that. If you don't use Grub, well, I can't help you. But if you're familiar with your bootloader's config file, go ahead and add the necessary lines into it.

I'll assume you like to edit your files with kate. Type in kate /boot/grub/menu.lst and hit Enter. This will open the Grub config file for editing in Kate.

Find the section similar to this:

title linux
kernel (hd0,0)/boot/vmlinuz root=/dev/hda1 devfs=mount hdd=ide-scsi
initrd (hd0,0)/boot/initrd.img

If you are unsure which section it is exactly, then look for the title line, and find the one that you normally choose to boot into Linux (usually it's just called linux).

Make a copy of this section so that it appears twice, identically.

Now, change the copied entry to reflect the proper kernel, and give it a new title so you know which one is which. For example, the changes I made are in red:

title linux-custom_kernel
kernel (hd0,0)/boot/vmlinuz-2.4.19-1custom root=/dev/hda1 devfs=mount hdd=ide-scsi
initrd (hd0,0)/boot/initrd-2.4.19-1custom.img

Save that, and then reboot. When your bootloader comes up, select your new entry from the menu. If you've done it correctly, your system will boot using the new kernel.

Please note, if you are an NVidia user, you will have to recompile your drivers to use with this new kernel.

If it doesn't work as expected, restart your computer and choose the old entry and your system will boot normally.

This works very well for me, and I've got one system's boot time down from 65 seconds to 25 seconds, from power on, just by removing bits and pieces from the kernel and recompiling and testing it, and rinse and repeat.

I hope this was easy to follow and works for you.


© D. Olson 2001-2003 -- Originally found on The Mandrake eXPerience