Debian – How to strip unused architectures, drivers, etc from headers when building a custom linux kernel

compilingdebianlinux-kernel

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?

Best Answer

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.

Related Question