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 menuconfig
used.
Download Linux Kernel Source
The kernel source code can be reached via several paths. 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/src
as 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 as a package via apt, it will remain /usr/src
in 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-get
installed 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.gz
the linux-source
same for both the package and the package. If the kernel is /usr/src
compiled into what is the case linux-src
by 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 .config
distribution file. There are also several make
targets available for editing the configuration .
$ Cp / boot / config ` uname -r ` config
$ make silentoldconfig
$ make menuconfig
make silentoldconfig
Same as oldconfig, but quietly, so update deps- Attention : If
make localmodconfig
used, 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 make
or over make deb-pkg
. The latter creates .deb
packages, making it easier to install the kernel across multiple systems.
make and install
make
alone, bzImage
build the kernel image , the targets, make modules_install
and make install
install 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-pkg
Debian 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-source
installed and the kernel /usr/src
compiled in, so it sudo
uses:
$ 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
[ ... ]
More ways to new kernel
Finally, other ways to install new kernels without having to compile yourself.
Ubuntu
- The Ubuntu Hardware Enablement Stack is the most common way to install new kernels on Ubuntu, sa. Ubuntu 12.04.2 LTS Enablement Stack Delivers New Kernel and LTSEnablementStack (wiki.ubuntu.com).
- Ubuntu also offers kernel mainline builds – MainlineBuilds (wiki.ubuntu.com).
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
1 Comment
Trent · January 24, 2020 at 10:06 PM
Seriously outdated post:
sudo make -j5 deb-pkg LOCALVERSION = -custom KDEB_PKGVERSION = 1
make: *** empty variable name. Stop.