fbpx
Compiling a Linux kernel is not an everyday occurrence for most administrators. It is all the more important to know the right tools when the time comes. The following article shows examples of how Mainline / Vanilla Kernel and the distribution-specific kernel are compiled.

Install required software

The following packages are needed to compile:

$ sudo apt-get install fakeroot build-essential devscripts libncurses5 libncurses5-dev
$ sudo apt-get build-dep linux

The library ncurses needs to be installed only when make menuconfigused.

Download Linux Kernel Source

The kernel source code can be reached via several ways. Distribution kernels always contain patches from the respective kernel team of the distribution. The mainline / vanilla kernel does not include these patches. For Ubuntu there is a Kernel Mapping Table (canonical.com), which represents a mapping between Mainline and Ubuntu Kernel.

Traditionally, kernels were mostly compiled under /usr/srcas root . Currently it is no longer necessary to use root to compile root . The tar archive can therefore be unpacked as a normal user in the home directory. If the Linux source code is installed via apt as a package, it will remain /usr/srcin use. There rootrights are needed again.

Mainline / Vanilla Kernel

The mainline kernel, without distribution patches, is maintained at kernel.org . Download is a tar archive, XZ compressed available.

$ wget https://kernel.org/pub/linux/kernel/v3.x/linux-3.17.2.tar.xz
$ tar xf linux-source-3.17.tar.xz

Kernel Packages in Repos

In the repositories is the Linux source code as a package, the Linux sources are apt-getinstalled by:

$ apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-3.13.0 - Linux kernel source  for version 3.13.0 with Ubuntu patches
$ Sudo apt-get install linux-source
[ ... ]
/ usr / src $ sudo tar xjf linux-source-3.2.tar.bz2

Kernel teams

  • Debian: https://wiki.debian.org/DebianKernel
  • Ubuntu: https://wiki.ubuntu.com/KernelTeam

The kernel compiling steps are tar.gzthe linux-sourcesame for both the package and the package. If the kernel is /usr/srccompiled into what is the case linux-srcby default, root rights are needed.

Create configuration

The kernel configuration defines how and what parts of the kernel are compiled. The best way to start is to use the existing .configdistribution file. There are also several maketargets available for editing the configuration.

make menuconfig is an interactive menu for customizing the kernel config file

$ Cp / boot / config ` uname -r ` config
$ make silentoldconfig
$ make menuconfig
  • make silentoldconfigSame as oldconfig, but quietly, so update deps
  • Attention : If make localmodconfigused, all currently not loaded modules are deactivated in the configuration! It may therefore also be the case that the USB module driver drops out if no USB medium is connected. Therefore, use this make target only if you want to create a customized kernel for the associated system.
    • make localmodconfig: Update current config disabling modules not loaded, sa Linux kernel tailor made (heise.de)
  • make menuconfig: Update current config using a menu based program

Compile and install

The kernel is either compiled over makeor over make deb-pkg. The latter creates .debpackages, making it easier to install the kernel across multiple systems.

make and install

makealone, bzImagebuild the kernel image , the targets, make modules_installand make installinstall the kernel modules, kernel, initramfs, and perform a GRUB update.

The following example compiles the kernel through the linux-3.17.2.tar.xz archive:

$ make -j5
  SYSTBL arch / x86 / syscalls /../ include / generated / asm / syscalls_32.h
  SYSHDR arch / x86 / syscalls /../ include / generated / asm / unistd_32_ia32.h
  SYSHDR arch / x86 / syscalls /../ include / generated / asm / unistd_64_x32.h
[ ... ] 
  LD [ M ]   sound / pci / hda / snd-hda-intel.ko
  LD [ M ]   sound / pci / snd-as300.ko
  LD [ M ]   sound / soundcore.ko
$ sudo make modules_install
  INSTALL arch / x86 / crypto / aes-x86_64.ko
  INSTALL arch / x86 / crypto / aesni-intel.ko
[ ... ]
  INSTALL sound / pci / snd-as300.ko
  INSTALL sound / soundcore.ko
  DEPMOD 3.17.2
$ sudo make install
sh ./arch/x86/boot/install.sh 3.17.2 arch / x86 / boot / bzImage \ 
		System.map "/ boot"
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.17.2 /boot/vmlinuz-3.17.2
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.17.2 /boot/vmlinuz-3.17.2
update-initramfs: Generating /boot/initrd.img-3.17.2
run-parts: executing /etc/kernel/postinst.d/pm-utils 3.17.2 /boot/vmlinuz-3.17.2
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.17.2 /boot/vmlinuz-3.17.2
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.17.2 /boot/vmlinuz-3.17.2
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set to no longer supported.
Found linux image: /boot/vmlinuz-3.17.2
Found initrd image: /boot/initrd.img-3.17.2
[ ... ]

make deb-pkg

As mentioned earlier, make deb-pkgDebian Packages builds after compiling. To set up the kernel, it is sufficient to install the generated packages via dpkg.

In the following example, the package was linux-sourceinstalled and the kernel /usr/srccompiled in, so it sudouses:

$ sudo make -j5 deb-pkg LOCALVERSION = -custom KDEB_PKGVERSION = 1
  CHK include / config / kernel.release
  UPD include / config / kernel.release
make KBUILD_SRC =
  SYSHDR arch / x86 / syscalls /../ include / generated / uapi / asm / unistd_32.h
  SYSHDR arch / x86 / syscalls /../ include / generated / uapi / asm / unistd_64.h
[ ... ] 
dpkg-deb: building package ` linux-headers-3.13.11.8-custom 'in` ../linux-headers-3.13.11.8-custom_1_amd64.deb' .
dpkg-deb: building package ` linux-libc-dev 'in` ../linux-libc-dev_1_amd64.deb' .
dpkg-deb: building package ` linux-image-3.13.11.8-custom 'in` ../linux-image-3.13.11.8-custom_1_amd64.deb' .
dpkg-deb: building package ` linux-image-3.13.11.8-custom-dbg 'in` ../linux-image-3.13.11.8-custom-dbg_1_amd64.deb' .
$ cd ..
$ sudo dpkg -i linux-image-3.13.11.8-custom_1_amd64.deb
[ ... ]
Preparing to unpack linux-image-3.13.11.8-custom_1_amd64.deb ...
Unpacking linux-image-3.13.11.8-custom ( 1 ) ...
Setting up linux-image-3.13.11.8-custom ( 1 ) ...
update-initramfs: Generating /boot/initrd.img-3.13.11.8-custom
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.13.11.8-custom
Found initrd image: /boot/initrd.img-3.13.11.8-custom
[ ... ]


Debian
  • Under Debian, a newer kernel can be installed through the Backport repository. Attention: Security updates are only distributed after backports after best effort!
# echo "deb http://http.debian.net/debian wheezy-backports main 
deb-src http://http.debian.net/debian wheezy-backports main "> /etc/apt/sources.list.d/backports.list
# apt-get update
# apt-get install -t wheezy-backports linux-image-amd64 linux-headers-amd64
Categories: Tutorials

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.