How do I apply a patch to my Linux kernel?
I am trying to compile the iscsi-target software SCST. It wants me to apply a patch to my Linux kernel in order to allow for certain performance gains. The problem is I still new to Linux development. Where do I begin? How do I apply the patch? Do I need to recompile the kernel? Help!
I am running Ubuntu 10.04.3 amd64
Kernel version 2.6.32-28-server
11 Answer
Your Linux distribution usually has its own instructions. Search their website or ask on IRC – or at least tell us the distro; without knowing it, it's impossible to provide a reliable anwer.
- Arch Linux:
- CentOS:
- Debian: , ,
- Fedora:
- Ubuntu:
The generic instructions are:
Download the kernel source from Kernel.org. "Stable" is probably the best choice. Extract to a convenient place (I use
~/src/linux).- Read the file named
README.
- Read the file named
Once inside the source directory, copy the current kernel's configuration, with:
zcat /proc/config.gz > .configIf /proc doesn't have it, look for
/boot/config-[version]instead.Apply the patch, with:
patch -p1 < foo.patch(try-p0if it gets rejected).Compile the kernel with:
make silentoldconfigmakeInstall the modules with:
sudo make modules_installInstall the kernel image
.../linux/arch/i386/boot/bzImageto wherever your bootloader wants it. (For example,/boot/vmlinuz-custom.)Build an initramfs for the new kernel, if your distribution uses it, and again make sure the bootloader knows its location. For example, on Arch Linux you would use:
mkinitcpio -k /boot/vmlinuz-custom -g /boot/initramfs-custom