How to compile your own kernel
Downloading the Kernel Source
As the final step before getting started on compiling the kernel, you need to download the kernel source from kernel.org. To streamline the different steps of downloading, verifying, and unpacking the kernel source, I used a script supplied by kernel.org [1]. Copy the contents of the script into your favorite text editor, save it, and add the executable permission to it. Prior to running the script, create the Downloads
directory in the root user's home directory. Proceed from here on as the root user. You must supply the kernel version number you wish to download as an argument to the script. For this example, I used 5.12:
# mkdir Downloads # ./get-verified-tarball.sh 5.12
Listing 2 shows the script's output.
Listing 2
Download Script Output
Using TMPDIR=/root/Downloads/linux-tarball-verify.yceAuEZym.untrusted Making sure we have all the necessary keys gpg: WARNING: unacceptable HTTP redirect from server was cleaned up gpg: WARNING: unacceptable HTTP redirect from server was cleaned up pub rsa4096 2013-01-24 [SC] B8868C80BA62A1FFFAF5FDA9632D3A06589DA6B1 uid [ unknown] Kernel.org checksum autosigner <autosigner@kernel.org> pub rsa4096 2011-09-23 [SC] 647F28654894E3BD457199BE38DBBDC86092693E uid [ unknown] Greg Kroah-Hartman <gregkh@kernel.org> sub rsa4096 2011-09-23 [E] pub rsa2048 2011-09-20 [SC] ABAF11C65A2970B130ABE3C479BE3E4300411886 uid [ unknown] Linus Torvalds <torvalds@kernel.org> sub rsa2048 2011-09-20 [E] Downloading the checksums file for linux-5.12 Verifying the checksums file gpgv: Signature made Sun 11 Jul 2021 07:25:09 AM EDT gpgv: using RSA key 632D3A06589DA6B1 gpgv: Good signature from "Kernel.org checksum autosigner <autosigner@kernel.org>" Downloading the signature file for linux-5.12 Downloading the XZ tarball for linux-5.12 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 112M 100 112M 0 0 2445k 0 0:00:47 0:00:47 --:--:-- 354k Verifying checksum on linux-5.12.tar.xz linux-5.12.tar.xz: OK Verifying developer signature on the tarball gpgv: Signature made Mon 26 Apr 2021 12:49:05 AM EDT gpgv: using RSA key 647F28654894E3BD457199BE38DBBDC86092693E gpgv: Good signature from "Greg Kroah-Hartman <gregkh@kernel.org>" Successfully downloaded and verified /root/Downloads/linux-5.12.tar.xz
You can copy the kernel source to /usr/src/kernels
, or you can leave it where it is (/root/Downloads
) and extract the kernel source tar file:
# cd Downloads # unxz -v linux-5.12.tar.xz # tar xvf linux-5.12.tar # cd linux-5.12
Now you're ready to begin compiling the kernel.
Compiling the Kernel
This first step, which is completely optional, is my favorite part of compiling a new kernel or adding and subtracting features from an existing one. It is the menuconfig
command, which results in the Linux Kernel Configuration menu (Figure 1):
# make menuconfig
Using this graphical interface, you can enable and disable features for your new kernel. Once you've made the changes you require, exit the menu. This procedure saves your choices to the hidden configuration file .config
and backs up any existing .config
file to .config.old
. You're now ready to compile the kernel. Start the compile process by running the make
command:
# make
Compiling the kernel can take a very long time depending on your system's CPU and memory capacity. For some small virtual machines, the process can take hours. For example, mine took roughly 10 hours to complete after performing a bit of troubleshooting along the way. For details, see the "Troubleshooting" section.
Once complete, you will find your new kernel listed as an executable file named vmlinux
. You're now almost ready to install the new kernel onto your system. But first, you need to install the new kernel modules.
Kernel Modules
Install the Linux kernel modules created during the compile process with:
# make modules_install
This process only takes a few minutes and occurs without intervention.
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.