Get kernel source: apt-get install vs apt-get source

8,834

In Debian terminology, when you run

apt-get source linux-image-3.19.0-trunk-amd64

(or the equivalent apt-get source linux), you're actually downloading and extracting the source package. This contains the upstream code (the kernel source code downloaded from kernel.org) and all the Debian packaging, including patches added to the kernel by the Debian kernel team.

When you run

apt-get install linux-source-3.19

you're actualling installing a binary package which happens to contain the source code of the Linux kernel with the Debian patches applied and none of the Debian packaging infrastructure.

The source package's name is just linux; apt-get source will convert any binary package name it is given into the corresponding source package name.

By the way, since experimental packages aren't upgraded automatically, you should make sure you've updated your copy of linux-source-3.19 and re-extracted it before comparing; the .dts file you're seeing in your diff was introduced in the latest update. The packages currently in the archive all contain this file.

The remaining differences are pretty much normal: as has been indicated in the comments, debian contains all the packaging and is only in the source package, .pc is used by quilt to keep track of the original files modified by patches, and is also only in the source package, and the .1 files are generated manpages, probably a side-effect of the kernel build, and therefore only appear in the binary package (but they shouldn't really be there).

The reference package is the source package, as obtained by apt-get source. This builds all the kernel binary packages, including linux-source-3.19 which you install with apt-get install. The latter is provided as a convenience for other packages which may need the kernel source; it's guaranteed to be in the same place all the time, unlike the source package which is just downloaded in the current directory at the time apt-get source is run.

As far as documentation goes, I'd follow the Debian documentation in the kernel handbook (section 4.5). Rebuilding the full Debian kernel as documented in section 4.2 which you linked to takes a very long time because it builds a number of variants.

Share:
8,834

Related videos on Youtube

poinu
Author by

poinu

Computer science student in Barcelona.

Updated on September 18, 2022

Comments

  • poinu
    poinu over 1 year

    I'm looking forward to download a Linux Kernel to get to know how to modify it and how to compile it.

    I am using Debian distribution and I'm interested in the Debian-modified Linux Kernel rather than in the vanilla Kernel form kernel.org.

    Doing some research I found out there are mainly two ways for achiving this purpose:

    • Install source package (i.e. apt-get install linux-source-3.19)
    • Download source from binary package (i.e. apt-get source linux-image-3.19.0-trunk-amd64)

    The first option will download the source tarball into /usr/src/linux-source-3.19.tar.xz and the later will download a source tarball (linux_3.19.1.orig.tar.xz), a patch (linux_3.19.1-1~exp1.debian.tar.xz) and a description file (linux_3.19.1-1~exp1.dsc). The latter will also unpack and extract everything into a 'linux-3.19.1' directory.

    At first I thought both versions would result with the same code, as they have the same kernel version and patch level (based on the report of the apt-cache command). However, diff command reported differences when comparing the unpacked source from apt-get install with the unpacked source from apt-get source (for both patched and non-patched code).

    When comparing apt-get install with apt-get source:

    $ diff -rq apt-get-install/ apt-get-source/ | wc -l
    253
    
    $ diff -rq apt-get-install/ apt-get-source/ | grep "Only in"
    Only in apt-get-install/arch/arm/boot/dts: sun7i-a20-bananapro.dts
    Only in apt-get-install/arch/s390/include/asm: cmb.h.1
    Only in apt-get-install/drivers/dma-buf: reservation.c.1
    Only in apt-get-install/drivers/dma-buf: seqno-fence.c.1
    Only in apt-get-install/drivers/gpu/drm/i915: i915_irq.c.1
    Only in apt-get-install/drivers/scsi: constants.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_acm.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_ecm.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_obex.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_serial.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_subset.c.1
    Only in apt-get-install/include/linux: reservation.h.1
    Only in apt-get-install/kernel: sys.c.1
    Only in apt-get-install/lib: crc32.c.1
    Only in apt-get-install/sound/soc: soc-cache.c.1
    

    And when comparing apt-get install with apt-get source (+ patch):

    $ diff -rq apt-get-install/ apt-get-source+patch/
    Only in apt-get-install/arch/s390/include/asm: cmb.h.1
    Only in apt-get-source+patch/: debian
    Only in apt-get-install/drivers/dma-buf: reservation.c.1
    Only in apt-get-install/drivers/dma-buf: seqno-fence.c.1
    Only in apt-get-install/drivers/gpu/drm/i915: i915_irq.c.1
    Only in apt-get-install/drivers/scsi: constants.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_acm.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_ecm.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_obex.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_serial.c.1
    Only in apt-get-install/drivers/usb/gadget/function: f_subset.c.1
    Only in apt-get-install/include/linux: reservation.h.1
    Only in apt-get-install/kernel: sys.c.1
    Only in apt-get-install/lib: crc32.c.1
    Only in apt-get-source+patch/: .pc
    Only in apt-get-install/sound/soc: soc-cache.c.1
    

    I've found some links where both methods are mentioned but I couldn't get anything clear from those:

    https://kernel-handbook.alioth.debian.org/ch-common-tasks.html#s-common-official https://help.ubuntu.com/community/Kernel/Compile (Option B vs Alternate option B)

    I would really appreciate if someone could tell me the differences and advise me which is the preferred option. Thank you.

    • Alen Milakovic
      Alen Milakovic about 9 years
      Congratulations on a sensible and well written question. Please give your Debian version. Are you on wheezy or jessie or something else? The versions you mention appear to be currently only in experimental, in any case. "However, diff command reported differences". Can you summarize those differences?
    • poinu
      poinu about 9 years
      @FaheemMitha Thank you! I'm on wheezy (stable) but, as you said, I'm getting the source from the experimental repository. When comparing the source from apt-get install with the non-patched source from apt-get source, I get 238 common files that differ and 15 files (mostly drivers) that are only found if using the apt-get install method. When comparing the source from apt-get install with the patched source, I get that none common files differ and there are 16 files that are only found if using the apt-get install method.
    • poinu
      poinu about 9 years
      14 of those files match the files only found in the non-patched source (from the first comparison), but a debian and a .pc directories are only found in the patched source and the file /arch/arm/boot/dts/sun7i-a20-bananapro.dts is only found in the non-patched. I tried my best to explain this in a clear way but if it is confusing I'll try to post the differences in a clearer way!
    • terdon
      terdon about 9 years
      It is probably simpler to just copy the diff output and paste it into your answer. You seem to be familiar with the formatting options already but, if not, see here for help.
    • Alen Milakovic
      Alen Milakovic about 9 years
      The debian directory is a packaging directory. Has nothing to do with the kernel source. The .pc directory ditto. This is where quilt stores its state. Quilt is used here by the Debian packaging machinery to apply patches, per the 3.0 (quilt) source format. I don't know about /arch/arm/boot/dts/sun7i-a20-bananapro.dts. Overall I didn't really follow your comparison. I suggest you elaborate, and put the information in the question, not in a comment. Bear in mind you can ask about Debian kernel packaging issues on the Debian Kernel mailing list.
    • Alen Milakovic
      Alen Milakovic about 9 years
      @terdon I suspect any diff would be too large. I suggest some kind of tabular comparison. Have two columns of file names, perhaps, each representing one of the two kernel source versions. If a file is found in one but not the other, put it in the relevant column - leave the other blank. If they are in both but differ, then write the name in both columns.
    • poinu
      poinu about 9 years
      @FaheemMitha (@terdon) I tried to do something clear but not too long. Finding packaging files in the apt-get source tarball makes sense but I still have no idea about the other files.
    • terdon
      terdon about 9 years
      Hmm, all the duplicates have a .1 extension. Could it be that say cmb.h.1 and cmb.h are the same file that has been duplicated? That might explain the differences.
    • poinu
      poinu about 9 years
      @terdon None of the .1 files are duplicates in this case. They seem to be formatted documentation files or error reports. I could find this line: The template for this document tried to insert the structured comment from the file /tmp/buildd/linux\-3\&.19\&.1//arch/s390/include/asm/cmb\&.h at this point, but none was found\&. This dummy section is inserted to allow generation to continue\&.
    • Alen Milakovic
      Alen Milakovic about 9 years
      As @stephen says, the .1 are probably man pages. I suggest you report this to the kernel mailing list ) don't see why that is there. Ben Hutchings, at least, replies to his email. You should also link to this question for context.
  • Chan Kim
    Chan Kim almost 3 years
    Thanks! the kernel handbook link seems to have changed : debian.org/doc/manuals/debian-kernel-handbook