Upgrading the Linux Kernel

Article by Kristen Grubb (1,930 pts ) , published Oct 17, 2009

Although most users will never find the need to upgrade their kernel there are several valid reasons for doing so. A newer device driver may become available, there may be some security bugs that need to be fixed, or the newest kernel may be more stable and reliable.

Compiling the Kernel

The most recent kernel is usually not available through your distribution's package manager, so you will have to download the source code from kernel.org. There are multiple versions of the kernel to choose from, so unless you are looking to test the very latest, pick a stable version for your upgrade.

Once you have downloaded the source code, it is a good idea to move the file to the /usr/src directory before you begin the build process. From here on in, you will have to have root privileges to build the kernel. You can either become root with the "su" command, or place the "sudo" before each of the following commands. If you downloaded via http from the kernel.org website you will most likely have a .tar.bz2 file to unpack. Move to the /usr/src directory and type the commands: bunzip2 linux-<version>.tar.bz2 (where <version> is the version number of the kernel you downloaded) and tar -xvf linux-<version>.tar.

You will then have the source directory called linux-<version>. Move into that directory to begin the build process. Type the command make menuconfig. This will bring up a ncurses interface that will walk you through the kernel configuration options. Read the options carefully and when you are finished make sure you choose save.

Once you choose your options you will type the following commands to build the kernel:

make dep

make clean

make bzImage

The next two commands are only used if you chose to enable modules during the make menuconfig stage.

make modules

make modules_install

That's it for building the kernel.

Updating the grub bootloader

Now you have to tell your OS to use the new kernel. That means adding it to the grub boot loader. Open the file /boot/grub/menu.lst in your favorite text editor. You will be looking for the section that looks like:

title Ubuntu 9.04, kernel 2.6.28-15-generic

uuid e4f56224-63eb-4f0f-a974-7b4938d56fd3

kernel /boot/vmlinuz-2.6.28-15-generic root=UUID=e4f56224-63eb-4f0f-a974-7b4938d56fd3 ro quiet splash

initrd /boot/initrd.img-2.6.28-15-generic

quiet

or:

title Red Hat Linux (2.4.18-0.12)

root (hd0,0)

kernel /vmlinuz-2.4.18-0.12 ro

root=/dev/hda3

initrd /initrd-2.4.18-0.12.img

It will be found around line 133, if you are using Ubuntu.

You will need to make another section exactly like that for the new kernel. The UUID and root variables will stay the same for each kernel version you will install. This is the id of your hard drive and where the root directory is held. The rest of the section should be changed to reflect your new kernel. Reboot the system and press "ESC" during the boot process to access the grub menu. Choose your new kernel and press enter.

If everything works the way you want it to, you can make it the default kernel by editing the menu.lst file again. You will be looking for the line that says "default 0." Change the number to the section number of your new kernel. The first kernel section is numbered 0, the second is numbered 1 and so on. If you don't want to change the default number, you can simply place the new kernel information in the first section.

There you have it - a brand new, upgraded kernel. It's really not as hard as you may think.

Additional Resources