- Lab
- A Cloud Guru
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.
Path 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
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.