Linux Kernel Compilation
Jump to navigation
Jump to search
How to compile a Linux kernel
- Note: the following was written in 2004, so may be a bit obsolete ☺
Many people don't dare to compile their Linux kernel because they fear that's a complicated and risky task. Actually it isn't for someone having basic Unix knowledge... Besides configuring and compiling your own kernel let you optimize it according to your system setup.
The following example is using a kernel from Mandrake (2004), which should be pretty generic for any RPM-based distribution. Let's say that your current kernel version is "2.4.25-7mdk", that you want to upgrade to "2.6.3-15mdk" and that you already have downloaded kernel-source-2.6.3-15mdk.i586.rpm into /var/tmp.
As the "root" user:
- Backup your current kernel:
- cd /usr/src ; tar cf /var/tmp/linux-2.4.25-7mdk.tar linux-2.4.25-7mdk
- cd /lib/modules ; tar cf /var/tmp/2.4.25-7mdkcustom.tar 2.4.25-7mdkcustom
- Backup your /etc (never know what may happen to your kernel modules-related configuration files...):
- cd / ; tar cf /var/tmp/etc.tar etc
- Install your new kernel source:
- rpm -U (or use Mandrake's "urpmi") /var/tmp/kernel-source-2.6.3-15mdk.i586.rpm
- Go to the source directory:
- cd /usr/src/linux-2.6.3-15mdk
- Configure your kernel:
- make xconfig (or "make gconfig" or "make menuconfig")
- make dep (Note: this is obsolete/useless with the 2.6 series)
- Compile:
- make && make modules ("make modules" is not needed with the 2.6 series where modules are already built by the default "make")
- Install:
- make modules_install (this will copy your kernel modules into /lib/modules/2.6.3-15mdkcustom)
- make install (this will copy your kernel files into /boot and update your boot loader)
- On a Mandrake system, when installing a 2.6 series kernel you may need either:
- ln -s /lib/modules/2.6.3-15mdkcustom /lib/modules/2.6.3-15mdk
- ln -s /lib/modules/2.6.3-15mdkcustom /lib/modules/2.6.3-15mdksmp
- Restore your previous kernel source and modules (they may have been partially uninstalled):
- cd /usr/src ; rm -r linux-2.4.25-7mdk ; tar xf /var/tmp/linux-2.4.25-7mdk.tar
- cd /lib/modules ; rm -r 2.4.25-7mdkcustom ; tar xf /var/tmp/2.4.25-7mdkcustom.tar
- Reboot:
- init 6