5

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
  • 223

3 Answers3

5

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.

Oli
  • 293,335
  • 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? – jon3laze Nov 03 '10 at 22:31
  • 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 – Oli Nov 03 '10 at 22:37
3

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.

1

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.

Kees Cook
  • 17,473