7

I am building custom linux kernel packages in a Ubuntu 13.10 amd64 environment using
apt-get source linux-image-$(uname -r)
the debian way make-kpkg clean;fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers.

Linux headers is larger than image

The result are two .deb files where the file linux-headers- is 8.2M in size and the resulting linux-image- is only 6.1M. After having a look in what files the linux-image- contains, I see that there are loads of headers for items which are disabled in the .config file.

Linux-headers-... content

  • unused file systems, like /fs/reiserfs/,
  • unused security modules, like /security/selinux/,
  • unused includes, like /include/pcmcia/ or /include/sound/,
  • unused architectures, like /arch/powerpc/, /arch/s390/, /arch/parisc/, /arch/blackfin/, /arch/cris/, /arch/xtensa/, /arch/alpha/, /arch/ia64/, /arch/h8300/, /arch/arm/, etcetera,
  • unused drivers, like /drivers/leds/, /drivers/eisa/, /drivers/isdn/, /drivers/net/ppp/, /drivers/net/wireless/, etcetera,
  • unused networking like /net/bluetooth/, /net/wimax/, /net/decnet/, etcetera

What (and how) are the options for stripping the unused items out of the linux-headers- package and/or otherwise reduce the file size?

Pro Backup
  • 4,924
  • Why do you want to reduce linux-headers package size? – जलजनक Mar 14 '14 at 09:40
  • 1
    May be I don't need the linux-headers- package to create and use a working custom linux kernel at all, and just strip the kernel_headers from fakeroot make-kpkg. – Pro Backup Mar 14 '14 at 10:29
  • You can find details about the Debian way of debian compilation here - http://unix.stackexchange.com/a/115921/4671 . This answer needs to be cleaned up, but I haven't got around to it. Feel free to add questions/comments. – Faheem Mitha Mar 15 '14 at 12:29
  • 1
    The linux-headers package is only needed when you want to compile sources, kernels or build other packages. They are also not a part of a system runtime. So precisely spoken there is no use-case for stripping unused header files. –  Mar 22 '14 at 01:33
  • @bersch Without a better answer, I am willing to award your comment the bounty. – Pro Backup Mar 23 '14 at 10:55
  • @ProBackup if you don't want some stuff, just remove it at compile time from the config file. as far as unused archs go, they shouldn't be there if it is properly compiled. did you look at my answer linked to in my comment above? a step-by-step guide is impractical. it depends on what you want to do. – Faheem Mitha Mar 23 '14 at 16:53
  • @FaheemMitha Yes I did have a look at the link. – Pro Backup Mar 24 '14 at 08:08

1 Answers1

5

The linux-headers package is only needed when you want to compile sources, kernels or build other packages.

Package description from debian:

This package provides the architecture-specific kernel header files for Linux kernel 2.6.32-5-686, generally used for building out-of-tree kernel modules. These files are going to be installed into /usr/src/linux-headers-2.6.32-5-686, and can be used for building modules that load into the kernel provided by the linux-image-2.6.32-5-686 package.

kernel-headers are also not a part of a system runtime. So precisely spoken there is no use-case for stripping unused header files from the package. However the original description restricts this by saying generally and limits it's usage to build kernel modules. If you are running a custom kernel which was built with kpkg, then you may also relink your /usr/include/{linux,asm,asm-generic} headers to be able to properly compile other sources.