Posted by: kezhong | July 25, 2009

Patching the Linux Kernel

As my last blog, I had built a new kernel which its release was 2.6.30. I would like to upgrade it to the current stable release 2.6.30.2 today. I have two approaches, one is building a new kernel like the last blog, and another is patching the kernel. In this test, I used the second one.

Upgrade from release 2.6.30 to 2.6.30.2
1.Backup the existing source tree
# cd /usr/src
# tar cvfj linux-2.6.30.tar.bz2 linux-2.6.30
2.Get and apply the patch
# wget http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.30.2.bz2
# cd linux-2.6.30
# bzcat ../patch-2.6.30.2.bz2 | patch –p1
patching file Documentation/sysctl/vm.txt
patching file Makefile
patching file arch/alpha/include/asm/percpu.h
… …
# cd ..
# mv linux-2.6.30 linux-2.6.30.2
3.Recompile and config
# cd linux-2.6.30.2
# make oldconfig
# make clean
# make bzImage
# cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.30.2
# chmod a+x /boot/vmlinuz-2.6.30.2
# cp System.map /boot/System.map-2.6.30.2
# make modules
# make modules_install 
# mkinitrd /boot/initrd-2.6.30.2.img 2.6.30.2
# vi /boot/grub/menu.list
title Fedora (2.6.30.2)
            root (hd0,0)
            kernel /vmlinuz-2.6.30.2 ro root=/dev/mapper/VolGroup-lv_root rhgb quiet
            initrd /initrd-2.6.30.2.img
 
4.Reboot and verify
# reboot
# uname –r
2.6.30.2

Upgrade from release 2.6.30.2 to 2.6.30.3
I found the latest stable release 2.6.30.3 come out, when I wanted to post this article. So I decided to upgrade my system to the newest release.
1.Apply the patch in reverse
# cd /usr/src
# wget http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.30.2.bz2
# cd linux-2.6.30.2
# bzcat ../patch-2.6.30.2.bz2 | patch –p1 -R
2.Get and apply the patch
# cd ..
# wget http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.30.3.bz2
# mv linux-2.6.30.2 linux-2.6.30.3
# cd linux-2.6.30.3
# bzcat ../patch-2.6.30.3.bz2 | patch –p1
3.Recompile and config
# make oldconfig
# make clean
# make bzImage
# cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.30.3
# chmod a+x /boot/vmlinuz-2.6.30.3
# cp System.map /boot/System.map-2.6.30.3
# make modules
# make modules_install 
# mkinitrd /boot/initrd-2.6.30.3.img 2.6.30.3
# vi /boot/grub/menu.list
title Fedora (2.6.30.3)
            root (hd0,0)
            kernel /vmlinuz-2.6.30.3 ro root=/dev/mapper/VolGroup-lv_root rhgb quiet
            initrd /initrd-2.6.30.3.img
 
4.Reboot and verify
# reboot
# uname –r
2.6.30.3 

According to Wikipedia, the patch file is a text file that consists of a list of differences and is produced by running the related diff program with the original and updated file as arguments. With my experience, when you want to build a new kernel, you can choose the method either building a new kernel with original source code or patching the kernel. They have their own advantages.

If you choose the patching method, you should consider the relationship between base stable release and others. For example, assume that your current stable release is 2.6.26.2, if you want to upgrade it to 2.6.26.8 through patching, the first you should do is downgrading (reversing) it to its base stable release 2.6.26, and then do the others. Another example, assume that your current stable release is 2.6.26.8, if you want to upgrade it to 2.6.27.1 through patching, you should downgrade it to its base stable release 2.6.26, patch the kernel to 2.6.27, and then patch it to 2.6.27.1.


Responses

  1. […] See the original post:  Patching the Linux Kernel « Kezhong's Weblog […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: