PDA

View Full Version : How to patch a kernel....


laclasse
03-03-2003, 07:42 AM
After seeing a lot of people wondering, here is a short description of steps needed to patch a kernel source tree.

Note that these instructions are valid for a 'VANILLA' kernel, i mean a plain kernel source downloaded from www.kernel.org or one of the mirror. I cannot give instructions for 'Vendor' kernels such as RH, Mandrake or SuSE. Why ?

1) Cause i don't use them
2) Cause it has proven difficult to find out the exact patches appplied by the vendors.

So, first download a kernel source from www.kernel.org or a mirror. The latest is 2.4.20.
Once the file linux-2.4.20.tar.gz is on your hdd, put it anywhere ( your home dir is fine ), and untar/decompress it with

$ tar -xvzf linux-2.4.20.tar.gz
( or tar -xvjf linux-2.4.20.tar.bz2 if ya download the bzip2 file )

==> This will last for a while, and produce lots of output, showing you what is getting de compressed and where. The whole decompressed source is 274 megs or so, so plan some space.

Then go and download the patches you need. www.google.com/linux , enter kernel patches as a search string, you will found a lot. The patches can be anything from .patch, to .txt to .diff extensions. Note that a lot of them are compressed, like "patch.kernel-2.4.20.diff.gz "

In this case you have to :
$ gzip -d patch.kernel-2.4.20.diff.gz
$

Now the patch will have lost his .gz extension.
Next we are gonna apply the patch:

$ pwd
/home/user
$ ls
linux-2.4.20 linux-2.4.20.tar.gz patch.kernel-2.4.20.diff
$ cd linux-2.4.20
$ patch -p1 < ../patch.kernel-2.4.20.diff

( lots of output, watch out for :
Hunk Succeed ;) IF ya have a lot of Hunk Failed at blAHBLAH...that doesn't look too good. Once patch is successfull, apply the others ( if so ), then make xconfig and you will see the new options of your patches ( acpi, Preemptive Kernel, Lock Break for the preemptive kernel, ACPI options, ACPI suspend etc ......).

Not that this guide doesn't dispense getting a kernel compile How to from www.tldp.org
Hope that helps and clear things...
:banana: :banana:

allbad
03-03-2003, 08:45 AM
Thanks for the info laclasse, I'm going to need to do this eventually.

Do you know if I will have to go through this whole process to add support for something, and not necessarily need to upgrade the kernel?

My linux install is fine, however, I recently added a second hard drive that I need to read data from (read only is find). Unfortunately, the kernel doesn't support NTFS -- I basically need to add support for that and hope it's a quickie vs. patching the kernel.

Thanks

laclasse
03-03-2003, 09:08 AM
allbad,

If ya want to recompile only the support for NTFS, it is possible. But be aware that the 'write' on NTFS file system from linux is considered unstable and dangerous ( data corruption ). The READ only is fine tho.

Here what to do for adding the support without recompiling the whole kernel.

1) got (cd to ) to your kernel source dir, it has to be the same source than the 'PRESENT' running kernel.
2) make xconfig
3) got to Filesystem, and add as 'M' or modules the NTFS read support
4) back to main, click save and exit
5) in the shell even if it says 'now you should make dep', for get it, do this instead:
$ make clean && make modules

then
$ su -c "make modules_install"
Password: XXXX

( Note that this will erase your /lib/modules/2.4.X/ kernel modules directory and install the new ones, plus the NTFS, so make sure your kernel config is complete )

Once done, do as root:
# modprobe ntfs
#

If it retiurns no errors, ya away, check with /sbin/lsmod as root that the ntfs module is loaded.

You can then mount XP/NT/2k volumes with the mount command:
mount -t ntfs /dev/hda1 /home/allbad/windowsXP

Afetr creating the /home/allbad/windowsXP dir off course. Hope that helps.

allbad
03-03-2003, 10:14 AM
Thanks for the info. I just intend to read data off a drive from my old system. Will try it tonight!