Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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-

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- patch -p1 < file.diff

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


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

share|improve this question
up vote 2 down vote accepted

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

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.

share|improve this answer
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? – detly Jan 17 '13 at 0:28
I can't find anything newer, so I suspect that's still the most accurate documentation. – ImaginaryRobots Jan 17 '13 at 1:50
This should not be marked as solved. Doesn't answer the question just points somewhere with irrelevant info... – pst007x Oct 20 '13 at 0:08
@pst007x , then post a new and more accurate answer instead. – ImaginaryRobots Oct 22 '13 at 4:02

You need to download the source. You can do this via apt-src but I would (personally) just grab the latest from, 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-
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.

share|improve this answer
Thanks, that's 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 3 '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 3 '10 at 22:37

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|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.