0% found this document useful (0 votes)
4 views8 pages

Compile

This document provides a comprehensive guide on compiling and booting a Linux kernel, covering installation prerequisites, downloading, extracting, configuring, compiling, installing, and booting the new kernel. It includes specific instructions for Debian-based systems and Red Hat-based systems, detailing commands and steps necessary for each process. The guide emphasizes the use of Oracle VirtualBox for users on Windows or macOS to create a Linux virtual machine for the compilation process.

Uploaded by

A Mc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Compile

This document provides a comprehensive guide on compiling and booting a Linux kernel, covering installation prerequisites, downloading, extracting, configuring, compiling, installing, and booting the new kernel. It includes specific instructions for Debian-based systems and Red Hat-based systems, detailing commands and steps necessary for each process. The guide emphasizes the use of Oracle VirtualBox for users on Windows or macOS to create a Linux virtual machine for the compilation process.

Uploaded by

A Mc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Compile and boot a Linux kernel

Anthony McGlone

March 20, 2023


Table of Contents

Chapter 1: Introduction 2
1.1 Installing Oracle VirtualBox . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Chapter 2: Debian - Ubuntu - Linux Mint 3
2.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Download the latest Linux kernel . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Extract the source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.4 Configure the kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.5 Compile the kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.6 Install the kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.7 Boot the new kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Chapter 3: Red Hat - CentOS 7
3.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Download the latest Linux kernel . . . . . . . . . . . . . . . . . . . . . . . . . 7

1
Chapter 1 Introduction
This guide will demonstrate the basic process of compiling and booting a Linux kernel. More
advanced kernel configuration (such as enabling device drivers or new kernel modules) will not
be covered.

If you’re already using a Linux operating system (OS), you can skip ahead to the kernel in-
stallation instructions for your OS.

If you’re on Windows or macOS, you can use Oracle’s VirtualBox to build a Linux virtual
machine (VM). The VM’s hard disk size should be at least 50 gigabytes.

1.1 Installing Oracle VirtualBox


1. Read the installation instructions for your OS.
2. Download the VirtualBox binary/package for your OS.
3. Download the .iso file of a Linux OS (e.g. Ubuntu, CentOS, Fedora).
4. Create a virtual machine using the .iso file.

2
Chapter 2 Debian - Ubuntu - Linux Mint
2.1 Prerequisites
In your Linux OS or VM, open a terminal. Install the kernel compilation tools:

sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev

2.2 Download the latest Linux kernel


Open the kernel home page by navigating to this website. Download the latest source code by
clicking on the large yellow button.

A tar.xz file will be downloaded to the Downloads folder (e.g. linux-6.0.2.tar.xz).

2.3 Extract the source code


In your terminal, cd into the Downloads folder. In the unxz command below, replace
<tar.xz file> with the file. Run the command to extract the tar file:

unxz -v <tar.xz file>

The Pretty Good Privacy (PGP) signature for the tar file should be verified before its con-
tents are extracted. On the kernel home page, find the table row corresponding to the latest
kernel version and copy the link address from the [pgp] link. In the wget command be-
low, replace <pgp link address> with this link. Then run the command to download the
tar.sign file:

wget <pgp link address>

Next, start the verification process. In the gpg command below, replace <tar sign file>
with the downloaded tar.sign file. Then run it:

gpg --verify <tar sign file>

The output from the command contains the Rivest–Shamir–Adleman (RSA) key, which will
be used in the verification of the tar file’s signature:

gpg: assuming signed data in ’linux-6.0.2.tar’


gpg: Signature made Sat 15 Oct 2022 07:04:02 IST
gpg: using RSA key 647F28654894E3BD457199BE38DBBDC86092693E
gpg: Can’t check signature: No public key

Replace <RSA key> in the following command with the RSA key from your terminal’s
output. Then run it:

3
gpg --recv-keys --keyserver hkps://keyserver.ubuntu.com <RSA key>

This command should download a public key that will be used in the verification. The out-
put will look like this:

gpg: key 38DBBDC86092693E: 1 duplicate signature removed


gpg: key 38DBBDC86092693E: public key "Greg Kroah-Hartman
gpg: <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1

Re-run the following command to complete the signature verification:

gpg --verify <tar sign file>

If successful, the output should look like this:

gpg: assuming signed data in ’linux-6.0.2.tar’


gpg: Signature made Sat 15 Oct 2022 07:04:02 IST
gpg: using RSA key 647F28654894E3BD457199BE38DBBDC86092693E
gpg: Good signature from "Greg Kroah-Hartman <[email protected]>"
gpg: aka "Greg Kroah-Hartman <[email protected]>" [unknown]
gpg: aka "Greg Kroah-Hartman (Linux kernel stable release signing key)
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 647F 2865 4894 E3BD 4571 99BE 38DB BDC8 6092 693E

Extract the Linux kernel code using the tar command:

tar xvf <the tar file>

There should now be a folder with the extracted source code (e.g. linux-6.0.2/)

2.4 Configure the kernel


cd into the extracted folder. Before compiling the kernel, choose the modules that should be
included. First, copy the modules from the existing kernel configuration to the new configura-
tion file:

cp -v /boot/config-$(uname -r) .config

The next step is to run make menuconfig. This will load a graphical dialog (see Figure
2.1). The dialog can be used to add or remove modules from the config (do not edit the config
at this time). A quick note on the dialog controls. Use the up/down arrow keys to navigate
vertically. Use the Enter/return key to select a submenu in the dialog. Typing Y will include a
feature. Typing N will exclude it. Use the left/right arrow keys to navigate to Exit when you
want exit a submenu or the dialog.

4
Figure 2.1: Linux kernel configuration dialog

Navigate around the dialog to examine the submenus. Then exit the dialog. Run the following
commands to ensure there are no certificate signing errors during the compilation process:

scripts/config --disable SYSTEM_TRUSTED_KEYS


scripts/config --disable SYSTEM_REVOCATION_KEYS

2.5 Compile the kernel


The kernel compilation process can take quite some time. To compile the kernel, use the make
command. Specify the number of cores to use in the compilation with the -j option. The
following command will run the compilation with two cores:

make -j 2

Note: Once you run this command, you will have to answer a long list of questions. Press
the Enter/return key to select the default option for each answer. When the compilation is
finished, the command prompt will be returned.

2.6 Install the kernel


To prepare for installation, install the kernel modules:

sudo make modules_install

Once the command prompt is returned, run the kernel installation command:

sudo make install

5
When the install command is finished, run ls -l /boot. Three files should be updated
(X.X.X should show the version number of the new kernel):

initrd.img-X.X.X System.map-X.X.X vmlinuz-X.X.X

2.7 Boot the new kernel


Reboot your Linux OS with the command:

reboot

When you have rebooted, open a terminal and run:

uname -mrs

You should see the version of the updated kernel.

6
Chapter 3 Red Hat - CentOS
3.1 Prerequisites
In your Linux OS or VM, open a terminal. Install the GCC compiler:

sudo yum groupinstall "Development Tools"

Install the additional tools required to compile the kernel:

sudo yum install ncurses-devel bison flex elfutils-libelf-devel openssl-devel

3.2 Download the latest Linux kernel


TODO: Combine this Chapter with the previous one.

You might also like