Building Linux kernel on the Debian OS (Debian 10 Buster).
This blog-post describes simple method of the Linux Kernel building on Operational System Linux Debian 10.
At the current moment (when this blog-post is being created) (2021-06), last current version was Debian 10.10.
Current version of the Linux Kernel was 4.19.0-13 (4.19.160).
Follow kernels have been built, using this method:
- Linux Kernel 4.19.194 (release: 2021-06-10)
- Linux Kernel 5.11.22 (release: 2021-05-19)
- Linux Kernel 5.12.10 (release: 2021-06-10)
Necessary version of the Linux Kernel could be found here:
- Base/Root site of the Linux Kernel: www.kernel.org
- Linux Kernel 4.x: kernel v4.x
- Linux Kernel 5.x: kernel v5.x
There are files .sign, distributed by www.kernel.org, which contain Digital Signature of correspondent files. Digital Signature of correspondent files can be verified, using methods, described here: Signatures. The verification allows to check if downloaded files correspondent original release versions and haven’t been changed.
Building the Linux Kernel on the Linux Debian 10 OS:
- If current user is root, all next commands (including copy to /usr/src, dpkg -i, update-grub2, … ) can be executed without any additional changes of permissions. In another case, it’s necessary to care about permissions and add sudo before some commands.
- Download necessary version of the Linux Kernel.
- Copy kernel archive to the directory: /usr/src.
- Unpack archive:
- if extension of the archive is .tar.gz:
tar -zxf ./[Linux Kernel Sources].tar.gz
- For example:
tar -zxf ./linux-5.12.10.tar.gz
- if extension of the archive is .tar.xz:
tar -Jxf ./[Linux Kernel Sources].tar.xz
- For example:
tar -Jxf ./linux-5.12.10.tar.xz
- if extension of the archive is .tar.gz:
Directory ./linux-5.12.10 will be created, that contains sources of the Linux Kernel (version 5.12.10).
- Unpacked directory can be renamed from ./linux-5.12.10 to ./linux-source-5.12.10-amd64 , where ‘amd64‘ – target build platform:
mv ./linux-5.12.10 ./linux-source-5.12.10-amd64
.
- Some software needs to be installed:
apt-get install gcc make git exuberant-ctags bc libssl-dev libelf-dev elfutils fakeroot build-essential zlib1g-dev libncurses5-dev
.
- Run follow command:
cd /boot
.
This directory (/boot) contains installed Linux kernels and suite of config files, which have been used during building installed kernels. For example:
- Linux Kernel 4.19.0-13 (4.19.160) :
-
/boot/vmlinuz-4.19.0-13-amd64
-
- Config of the Linux Kernel 4.19.0-13 (4.19.160) :
/boot/config-4.19.0-13-amd64
.
- Copy this file: /boot/config-4.19.0-13-amd64 to unpacked directory (sources): /usr/src/linux-source-5.12.10-amd64.
- Make one more copy of the file: /usr/src/linux-source-5.12.10-amd64.
- For example:
cd /usr/src/linux-source-5.12.10-amd64
cp ./config-4.19.0-13-amd64 ./.config
.
- For example:
- Run
cd /usr/src/linux-source-5.12.10-amd64
- and one of the following commands:
make config
– text mode (questions)make menuconfig
– text mode (menu)make xconfig
– graphical mode (menu)
- All menu options can be configured, but it’s necessary to save current configuration to file:
/usr/src/linux-source-5.12.10-amd64/.config
.
- Script saves default values of all non-configured menu options.
- I.e. the most quick way of configuring:
- just:
make menuconfig
- and save configuration to the file
./.config
.
- Then open file:
/usr/src/linux-source-5.12.10-amd64/Makefile
and setup value: EXTRAVERSION.- For example:
EXTRAVERSION = -amd64
- For example:
- Follow commands can be used for cleaning and build:
make clean
– cleaning built binaries and temporary files
ormake deb-pkg
– full build and binary images creating.
- After finishing the build follow files will be created in the current directory
/usr/src/linux-source-5.12.10-amd64/ :
linux-5.12.10-amd64_5.12.10-amd64-1.dsc
linux-5.12.10-amd64_5.12.10-amd64-1_amd64.buildinfo
linux-5.12.10-amd64_5.12.10-amd64-1_amd64.changes
linux-5.12.10-amd64_5.12.10-amd64.orig.tar.gz
linux-5.12.10-amd64_5.12.10-amd64-1.diff.gz
linux-headers-5.12.10-amd64_5.12.10-amd64-1_amd64.deb
linux-image-5.12.10-amd64_5.12.10-amd64-1_amd64.deb
linux-image-5.12.10-amd64-dbg_5.12.10-amd64-1_amd64.deb
linux-libc-dev_5.12.10-amd64-1_amd64.deb
- For installing built .deb modules, use follow commands:
cd /usr/src/linux-source-5.12.10-amd64
dpkg -i ./linux-*.deb
- After that, new kernel will be installed to the directories:
/boot
/usr/lib/modules/5.12.10-amd64
/usr/lib/debug/lib/modules/5.12.10-amd64
/usr/src
- If grab2 is installed as boot loader package, follow command should be executed:
update-grub2
- that provides configuring the file:
/boot/grub/grub.cfg
This execution (update-grub2) is optional, as during running “dpkg -i ./linux-*.deb“, updating the /boot/grub/grub.cfg is provided by default.
- After reboot, new version of the kernel will be loaded:
- file:
/proc/version
- file: