Where / which is the actual kernel source?

I am following this to learn to compile the kernel. I used

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

to download the source code of the Linux kernel I am curretly using.

After running the above command, the following files (and directories) were downloaded.

user $ ls -l
total 130972
drwxrwxr-x 27 sps sps      4096 Oct 16 03:10 linux-lts-vivid-3.19.0
-rw-rw-r--  1 sps sps  10980684 Oct  5 10:54 linux-lts-vivid_3.19.0-30.34~14.04.1.diff.gz
-rw-rw-r--  1 sps sps      7396 Oct  5 10:54 linux-lts-vivid_3.19.0-30.34~14.04.1.dsc
-rw-rw-r--  1 sps sps 123115155 May  6 21:35 linux-lts-vivid_3.19.0.orig.tar.gz
user $ 

In the same page it is mentioned:

Building the kernel is quite easy. Change your working directory to the root of the kernel source tree and then type the following commands:

But I am not sure which is the "root of the kernel source tree".

Is it the current directory (where I ran apt-get source ... and where I have the above listed files)?

Or, is it the directory:

drwxrwxr-x 27 sps sps      4096 Oct 16 03:10 linux-lts-vivid-3.19.0

or, should I extract the tarball

-rw-rw-r--  1 sps sps 123115155 May  6 21:35 linux-lts-vivid_3.19.0.orig.tar.gz

Output for uname -r:

user $ uname -r
3.19.0-30-generic
user $ 

Solution 1:

From the Debian Wiki:

Source packages provide you with all of the necessary files to compile or otherwise, build the desired piece of software.

It consists, in its simplest form, of three files:

  • The upstream tarball with .tar.gz ending

  • A description file with .dsc ending. It contains the name of the package, both, in its filename as well as content (after the Source: keyword).

  • A tarball, with any changes made to upstream source, plus all the files created for the Debian package.

    • This has a .debian.tar.gz (source format : 3.0)
    • or a .diff.gz ending (source format : 1.0)

It's quite the same for Ubuntu, and in your case:

  • "linux-lts-vivid-3.19.0": the actual kernel, patched starting from the upstream tarball "linux-lts-vivid_3.19.0.orig.tar.gz" with the modifications listed in "linux-lts-vivid_3.19.0-30.34~14.04.1.diff.gz";
  • "linux-lts-vivid_3.19.0-30.34~14.04.1.diff.gz": a tarball, with any changes made to upstream source, plus all the files created for the Debian package;
  • "linux-lts-vivid_3.19.0-30.34~14.04.1.dsc": a descrition file ".dsc" ending. It contains the name of the package, both, in its filename as well as content (after the Source: keyword);
  • "linux-lts-vivid_3.19.0.orig.tar.gz": the upstream tarball with ".tar.gz" ending (mind that in my experience it's not always a ".tar.gz" file, it can be in slightly different formats, such as ".tar.xz");

When you run apt-get source linux-image-$(uname -r), the upstream tarball is automatically patched with the modifications listed in "linux-lts-vivid_3.19.0-30.34~14.04.1.diff.gz" in "linux-lts-vivid-3.19.0":

% apt-get source linux-image-$(uname -r)
# ...
dpkg-source: info: extracting linux in linux-3.19.0
dpkg-source: info: unpacking linux_3.19.0.orig.tar.gz
dpkg-source: info: applying linux_3.19.0-30.34.diff.gz
# ...

Solution 2:

The root of your kernel tree is the directory linux-lts-vivid-3.19.0.

About the other files:

In the tarball linux-lts-vivid_3.19.0.orig.tar.gz you can find the "vanilla" kernel, as released upstream; to this kernel the Ubuntu developers have added patches, drivers, changed things that are collected in the diff which is compressed in linux-lts-vivid_3.19.0-30.34~14.04.1.diff.gz.