I am doing some changes on ubuntu linux source code. I used find / -name user.c command to locate user.c but failed. Where is it? My working environment is ubuntu14.04.

  • Try running the command sudo updatedb && locate user.c. That should search your PC for the file. – RPiAwesomeness Dec 21 '14 at 2:11
  • 2
    Where did you download the kernel sources to? – David Foerster Dec 21 '14 at 2:15
  • I do as you say, and I found there is no user.c in /usr/src, but some websites(Linux-cross-Reference)says there is a file kernel/user.c,could you please explain this for me? Thanks! – BecomeBetter Dec 21 '14 at 2:16
  • Try running sudo apt-get install linux-source and then re-run the commands RPi suggested. – Seth Dec 21 '14 at 2:18
  • @DavidFoerster I didn't download any source, I'm using ubuntu14.04, there are lots of source code in /usr/src,I chose linux-headers-3.13.0-35 folder to do my changes in order not to do harm to my system once I failed. But where is that file? And could you please explain for my the right way to modify linux source code then compile and use it ? – BecomeBetter Dec 21 '14 at 2:20

You didn't install the kernel source code, only kernel headers (usually ending in .h), which declare kernel interfaces exposed to user space.

You can get the kernel source code files (including those ending in .c) by installing linux-source Install linux-source with

apt-get source linux-image-$(uname -r)

or by downloading the code repository (either through Git or with a click on the “snapshot“ link behind the newest revision in the shortlog). If you choose to install the linux-source package, the source code files will reside below /usr/src. If you download them manually, they'll be wherever you chose to clone/extract them.

For more information on how to compile your own kernel on Ubuntu refer too the Ubuntu Wiki. To make it very short, it basically comes down to

fakeroot debian/rules binary-headers binary-generic

though I prefer the more versatile

make-kpkg --rootcmd fakeroot --initrd --jobs $(getconf _NPROCESSORS_ONLN) kernel-image kernel-headers

Edit: The stroked out text passages work as intended but aren't as useful if you aim to modify the kernel source and build your own kernel.

  • I also want to know after doing that, where the linux-source is located? Then I can modify the linux source?It would be better if you could show me some articles aiming for that:) – BecomeBetter Dec 21 '14 at 2:39
  • I added paragraphs about the location of the kernel sources and a link to a kernel build how-to. – David Foerster Dec 21 '14 at 2:56
  • when I ran command make-kpkg --rootcmd fakeroot --initrd --jobs $(getconf _NPROCESSORS_ONLN) kernel-image kernel-headers.It errs that We do not seem to be in a top level linux kernel source directory tree. Since we are trying to make a kernel package, that does not make sense. Please change directory to a top level linux kernel source directory, and try again. (If I am wrong, and this is indeed a top level linux kernel source directory, then I have gotten sadly out of date with current kernels, and you should upgrade kernel-package),Where is the top level linux source ? – BecomeBetter Dec 26 '14 at 8:23
  • My working directory is \usr\src\linux-source-3.13.0,when I change it to \usr\src,it still errs like that. – BecomeBetter Dec 26 '14 at 8:25
  • I doubt you have write permission in /usr/src or its subdirectories. Building the kernel as root isn't such a good idea, because one should do as few things as possible as super-user (“With great power comes great responsibility”). It would probably be easier and cleaner to copy, clone, or download and extract the kernel source to a directory you own and build the kernel there. – David Foerster Dec 26 '14 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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