In Debian Linux, there are two ways to compile custom kernels:
We’ll use the traditional method because it applies to all Linux distributions (in fact, the guide we linked is from the ArchWiki).
First and foremost, please take a snapshot of your VM before you get started.
Make sure you have the following kernel configuration/compilation dependencies installed:
build-essential bc python bison flex libelf-dev libssl-dev libncurses-dev
Reboot and make sure that your system is all good.
uname -r to make sure that you are running the stock kernel that ships
with Debian. At this time of writing, our system reports
In the Fall 2020 semester, you will be working Linux kernel version 4.19.50.
But instead of fetching the Linux source code from kernel.org,
you will be compiling the kernel source code provided in each kernel
assignment’s skeleton repo. You will find the pristine, mainline
Linux kernel source tree in the
linux/ directory in your assignment repo.
You should verify the version of the kernel. The first 6 lines of Linux’s
Makefile will show you the version:
$ head -n 6 Makefile # SPDX-License-Identifier: GPL-2.0 VERSION = 4 PATCHLEVEL = 19 SUBLEVEL = 50 EXTRAVERSION = NAME = "People's Front"
It is standard practice to run
make mrproper in a freshly cloned repo before
proceeding. This removes any configuration files that might have been
accidentally left over from previous builds.
The Linux kernel build system can be configured using the
.config, which must
be located at the root of the Linux source tree. This file is used to specify a
truly astounding number of options with which you can build your kernel.
You can start with the
.config file of your running kernel (e.g. the stock
Debian kernel). The
.config file that was used to build the stock Debian
kernel is located in the
/boot/ directory. The following command copies over
.config file, and updates any missing options with default values:
$ make olddefconfig
Depending on how your stock kernel is configured, this may report some warnings. For example:
/boot/config-4.19.0-10-amd64:6954:warning: symbol value 'm' invalid for ASHMEM /boot/config-4.19.0-10-amd64:7583:warning: symbol value 'm' invalid for ANDROID_BINDER_IPC
You should be able to ignore these without running into any trouble.
Now, run the following command to edit your
$ make menuconfig
This will open up an interactive menu that organizes configuration options in a
more user-friendly manner. If you make any configuration changes, it will also
create a backup of your original
.config file, named
Make the following changes, either using
menuconfig, or by directly editing
CONFIG_LOCALVERSION: This setting gives your custom kernel a unique
name to distinguish it from other kernels present in your system.
The local version will be appended to your kernel version to
form your kernel name. For example, if we build a 4.19.50 kernel with the
local version set to
-cs4118, it will be named
menuconfig, this can be found under
For your pristine kernel build, set this to
SYSTEM_TRUSTED_KEYS: This is used to bake additional trusted X.509 keys
directly into the kernel image, which can be used to verify kernel modules
before loading them. Debian 10 comes with this
configuration, but we won’t actually need this, so we will remove it.
menuconfig, this can be found by opening the
section, then opening the
Certificates for signature checking section
at the bottom.
You may find this option set to
clear out this field and leave it empty.
CONFIG_BLK_DEV_LOOP: Loop devices are regular files
that are made to appear as block devices in the device file system. They
will come in handy later when we start playing with file systems, but we
need to enable them in our kernel build before we can use them.
Loopback device support option can be found in
Device Drivers -> Block devices.
In stock kernels, this is usually set to
m, for “module”. This means
it won’t be linked into the kernel image, but will be available as a
dynamically-linkable kernel module.
Set this option to
y, so that loop device functionality is always
available without having to insert it. You should see a
* next to the
After setting your local version, take a moment to inspect the contents of the
.config file. Make sure that the options you configured are set to what you
expect them to be.
Linux also provides the
scripts/diffconfig utility, which can be used to
.config files. For example, you would see:
$ scripts/diffconfig .config.old .config BLK_DEV_LOOP m -> y LOCALVERSION "" -> "-cs4118" SYSTEM_TRUSTED_KEYS "debian/certs/debian-uefi-certs.pem" -> ""
Compiling a kernel takes a long time – it can take over an hour on a slow
machine. You can speed up this process by running compile jobs in parallel – if
your computer has multiple CPU cores, you should configure your VM to use them.
make as a non-root user:
$ make -jN
N is the number of parallel jobs you would like
make to spawn.
Use the number of CPUs for
N. So for a 8-core (virtual) machine, you
Then, install the kernel modules and the kernel itself:
# make modules_install # make install
Verify that you have the following 3 files in
vmlinuz-4.19.50-cs4118 initrd.img-4.19.50-cs4118 System.map-4.19.50-cs4118
Reboot by running:
Make sure to pick your custom kernel from the boot loader menu.
Now verify that you’re running your own custom kernel by running:
$ uname -a
4.19.0-10-amd64, you should now see your kernel version string,
Last updated: 2020-09-03