Correct way to apply patches to your kernel?

25,534

Solution 1

To avoid frustration, you should generally do such things the Ubuntu way. Full instructions using official packages can be found here:

https://help.ubuntu.com/community/Kernel/Compile

It provides lists of dependencies and step-by-step commands for getting a custom kernel up and running.

By following that procedure, you will end up with an uninstallable package containing your custom kernel, which means that you will be able to switch back to the official kernels in future if needed.

Solution 2

You need to download the source. You can do this via apt-src but I would (personally) just grab the latest from kernel.org, extract it, patch it (just using local paths like the desktop, it doesn't need to be hidden in /usr/src at all!) and follow the "old fashioned way" instructions for compiling it.

Note that some patches are only for certain versions of the kernel (this includes point releases) so make sure your patch works for the source version before you waste 20-30 minutes compiling it.

But your specific problem is you need to be in the directory that you want to apply the patch to. In your case:

cd /usr/src/linux-headers-2.6.35.22/
patch -p1 < /path/to/file.diff

Obviously change the path to the patch (or stick it in the same directory). If the source files are owned by root, prefix sudo onto the patch command or run sudo su to become root while you do this.

Solution 3

The instructions you are following are showing you the command-line prompt /usr/src/linux #, which is not something you type as part of the command. The command to type that will apply the patch starts at patch and continues from there.

Share:
25,534

Related videos on Youtube

jon3laze
Author by

jon3laze

Updated on September 17, 2022

Comments

  • jon3laze
    jon3laze over 1 year

    I am following the instructions located here to setup my server. It states that I have to apply a patch which I've downloaded onto the machine. My question is, the article says to use the following command:

    /usr/src/linux # patch -p1 < file.diff //note I replace file.diff w/ routes-2.6.36.16.diff
    

    This returns:

    -bash: /usr/src/linux: No such file or directory
    

    I go on to assume that /linux # should be replaced with the actual linux kernel version/dir. I've tried this using the following command:

    /usr/src/linux-headers-2.6.35.22 patch -p1 < file.diff
    

    This returns the same. When I view the contents of /usr/src I only have two directories linux-headers-2.6.35.22 and linux-headers-2.6.35.22-generic-pae I need guidance as to the correct way to apply a patch to the kernel.

    Edit

    If I execute /usr/src/linux-headers-2.6.35.22/ patch -p1 file.diff I get -bash: /usr/src/linux-headers-2.6.35.22: is a directory. I need to know how I go about finding the specific file that needs to be patched here...

  • jon3laze
    jon3laze over 13 years
    Thanks, that's working...to a point. I am not getting a message that patch is not installed... sudo apt-get install patch comes back unable to locate package. I am running ubuntu server 10.10 and on setup i did not select any specific function (dns, lamp, etc) do I need to install a package manager?
  • Oli
    Oli over 13 years
    You need build-essential IIRC but you'll need a lot more for building the kernel. Run this: sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge
  • detly
    detly over 11 years
    These instructions are now a couple of years out of date. The tools and package structure has changed somewhat since then. Do you know of any up-to-date instructions?
  • ImaginaryRobots
    ImaginaryRobots over 11 years
    I can't find anything newer, so I suspect that's still the most accurate documentation.
  • pst007x
    pst007x over 10 years
    This should not be marked as solved. Doesn't answer the question just points somewhere with irrelevant info...
  • ImaginaryRobots
    ImaginaryRobots over 10 years
    @pst007x , then post a new and more accurate answer instead.