Operations 8 min read

Master Linux Kernel Compilation: A Step‑by‑Step Guide

This guide walks you through obtaining the Linux kernel source, extracting it, configuring options with menuconfig, compiling with make, installing modules and the kernel, updating bootloader entries, and cleaning up, providing practical commands and tips for a successful custom kernel build.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Kernel Compilation: A Step‑by‑Step Guide

Introduction

The Linux kernel is the core of the operating system, handling process, memory, file, device, and network management. While it follows a monolithic design, it uses a modular approach that allows dynamic loading of kernel modules and kernel threads.

Because the kernel is free software, new releases add features and fix bugs. To use these new features or create a custom, more efficient kernel, you need to compile the source yourself.

Obtaining the Source

Download the desired kernel source package (e.g., version 3.10.10) from the official site kernel.org . Avoid compiling the very latest version unless you are prepared for possible incompatibilities.

Extracting the Source

Extract the tarball into /usr/src. After extraction, a directory named after the kernel version appears; you can create a symbolic link named linux pointing to this directory for convenience.

Preparing the Build Environment

Install development tools (e.g., gcc, make, ncurses‑devel). Before configuring, gather hardware information:

cat /proc/cpuinfo
x86info   # requires manual installation
lscpu
lspci   # use -v for details
lsusb   # use -v for details
lsblk

Configuring the Kernel

Several configuration methods are available: make config – step‑by‑step selection make allyesconfig – enable all options make allnoconfig – disable all options make menuconfig – text‑based menu (requires gcc and ncurses-devel) make gconfig – GNOME graphical interface (requires GTK2) make kconfig – KDE graphical interface (requires Qt)

Kernel options can be marked as: [*] – built into the kernel [M] – compiled as a loadable module [ ] – not selected

After finishing configuration, the settings are saved in a hidden .config file. You can copy /boot/config over it for a quick start.

Compiling the Kernel

When compiling over a remote connection, use screen to keep the session alive:

screen          # start a new window
Ctrl+A D        # detach
screen -ls      # list windows
screen -r SCREEN_ID   # reattach

Start the build:

make

Installing Modules and the Kernel

Install compiled modules:

make modules_install

Modules are placed under /lib/modules/<em>kernel-version</em>.

Install the kernel itself:

make install

New kernel files appear in /boot and grub.conf is updated automatically.

Booting the New Kernel

Reboot and select the newly installed kernel from the boot menu.

Verify the running version with uname -r.

Cleaning Up

Before a fresh build, clean previous artifacts: make clean – removes compiled objects but keeps

.config
make mrproper

– removes all generated files, configuration, and backups make distclean – complete clean

Speeding Up the Build

Use parallel jobs: make -j$(nproc) To place build output elsewhere:

mkdir /path/to/somewhere
cd /path/to/somewhere
./configure --ksource=/usr/src/linux

Compiling Only Parts of the Kernel

Compile a specific subdirectory:

cd /usr/src/linux
make path /to/dir/

Compile selected modules: make M=path/to/dir Compile a single module: make path /to/dir/MOD_NAME.ko Redirect output directory:

make O=/path/to/somewhere

Conclusion

Compiling a Linux kernel involves obtaining the source, configuring options, building, installing, and updating the bootloader. While time‑consuming, especially the menu configuration, the process grants full control over kernel features.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

KernelCompilationscreenMake
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.