- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud

Compiling a Linux Kernel (Ubuntu)
For most Linux administrators, updating a kernel is done through the package manager for the Linux distribution that is being used. However, there can be situations where a particular kernel version or specific kernel configurations are needed. In this lab, you will be tasked with downloading the full kernel source tree, updating the kernel configuration to certain specifications, and then compiling a new kernel image.

Lab Info
Table of Contents
-
Challenge
Enable source URIs for apt repositories.
- Open the sources.lst file in
/etc/apt/
:
vim /etc/apt/sources.lst
-
Uncomment
deb-src
URIs manually or by substitution —:%s/# deb-src/deb-src/g
-
Resynchronize the package index files:
apt-get update
- Open the sources.lst file in
-
Challenge
Install dependencies
- Install additional dependencies:
apt-get install -y make gcc libncurses5-dev dpkg-dev build-essential bison flex libssl-dev libelf-dev
-
Challenge
Download the Kernel source tree to /usr/src
- Switch to the
/usr/src
directory:
cd /usr/src/
- Download the kernel source tree:
apt-get install -y linux-source kernel-package
- Select the following option:
keep the local versions currently installed
- Switch to the
-
Challenge
Update the kernel configuration
- Switch to the kernel source tree directory and extract the archive:
cd /usr/src/linux-source-[kernel_version] tar jxvf linux-source-[kernel_version].tar.bz2 mv linux-source-[kernel_version]/* . rm -rf ./linux-source-[kernel_version]/
- Get the necessary packages
apt-get build-dep -y linux-source mkdir debian/stamps
- Update the kernel configuration with the
make menuconfig
command:
cp /boot/config-$(uname -r) .config yes '' | make oldconfig make menuconfig
- Navigate with your arrow keys and use enter to go to
Device Drivers
>Block devices
- Using the “n” key, exclude the following two drivers -
DRBD Distributed Replicated Block Device support
andPacket writing on CD/DVD media (DEPRECATED)
- Exit the menu and save your configuration changes.
- Prepare to compile the Kernel:
make clean
-
Challenge
Compile the kernel image (this step can take 15-20 minutes to complete)
- Create the compressed kernel image by calling the bzImage target:
make bzImage
Note: This can take 15-20 minutes to complete
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.