[ Content | View menu ]

Kernel Compilation How-To

This little tutorial is to teach you how easy it is to compile a kernel, however I should warn you that I’ve only tested this on Arch Linux and no other distributions, so things may be slightly different. This is something people frequently fail at, so you can obviously never have too much documentation on it. Despite sounding difficult, it’s actually fairly simple if you know what you’re doing. The mistakes crop in if you disable (oe enable) something you shouldn’t have in the config stage…

Firstly, you should have installed wget, tar, cs, zcat, make, cp and mkinitcpio. That shouldn’t be a problem for most distributions. You will also need ncurses (and the development packages if your distribution separates them) if you want to use menuconfig, qt if you want to use xconfig, and gtk if you wnt to use gconfig. All three config utilities do the same job, but I like xconfig myself, menuconfig can be confusing, and gtkconfig crashed every time I tried to run it on my machine. Anyway, on with the compiling!

Fetching and Extracting the Source

The kernel source is located on ftp.XX.kernel.org/pub/linux/kernel/, where XX is your country code (for example, ‘us’, ‘uk’, and ‘de’). I recommend you download the source from the mirror closest to you, as it is likely to be fastest. We shall use wget to get the latest kernel (as of this writing), 2.6.25.6

$ wget -c ftp://ftp.uk.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.6.tar.bz2
$ tar xvjf linux-2.6.25.6.tar.bz2
$ cd linux-2.6.25.6

Configuring it

If your distribution’s kernel supports it, you can grab their config using zcat and work from that. If not, you’ll have to configure it all yourself. I recommend working from your distributions kernel config if you can, because you KNOW it works perfectly. Don’t forget to rename your kernel’s version, otherwise it will conflict with the currently installed one.

$ zcat /proc/config.gz > .config
$ make oldconfig # Skip this step if you are configuring from scratch.
$ make xconfig # You could use menuconfig or gconfig here instead.

Compiling and Installing

This is the easiest - but most boring - part of making your own kernel. It requires absolutely no interaction, except entering the commands, and can take a long time. The following three commands will compile the kernel fully, and install the kernel modules to /lib/modules/.
$ make clean
$ make bzImage
# make modules_install
# cp -v arch/ARCH/boot/bzImage /boot/vmlinuz-2.6.25.6-NAME
# mkinitcpio -k 2.6.25.6-NAME -g /boot/kernel26-NAME

Note that ARCH is the architechture you want to use, and NAME is a unique name to differentiate your kernel files from other kernel files.

GRUB

Now, you will need to add your kernel to the GRUB menu.lst file yourself. Which is incredibly simple really - you can just copy and edit the entry for your existing kernel if you’re unsure.

Filed in How To, under , , on June 27, 2008

No Comments

Write comment - TrackBack - RSS Comments

Write comment