Operations 12 min read

Master Elegant Linux Kernel Upgrades: Step-by-Step Compilation and RPM Packaging

This guide walks you through the fundamentals of Linux kernel upgrades, covering kernel anatomy, compilation steps, configuration tuning, kernel migration, and creating RPM packages for streamlined, reliable updates across multiple servers.

Efficient Ops
Efficient Ops
Efficient Ops
Master Elegant Linux Kernel Upgrades: Step-by-Step Compilation and RPM Packaging

Introduction

Linux’s core component is the kernel; upgrading it is a common operation when new features or bug fixes are needed. This article explains how to perform kernel upgrades elegantly and efficiently.

Kernel Overview

The kernel consists of user space and kernel space, handling hardware interaction and providing essential services such as iptables, cgroups, and system debugging.

Kernel File Layout

/boot/vmlinuz-3.8.0 – compressed bootable kernel image.

/boot/initramfs-3.8.0.img – initial ramdisk containing essential drivers and modules.

/boot/System.map-xxx – symbol table for the kernel.

/lib/modules/kernel. version – loadable kernel modules (.ko files).

/lib/firmware – firmware for devices such as network cards.

/etc/grub.conf – bootloader configuration.

Kernel Boot Sequence

Boot loader loads the kernel and initrd into RAM.

The kernel takes control and decompresses initrd.

The kernel mounts a temporary root filesystem (ram0).

User space init scripts run, preparing the real root filesystem.

The real root filesystem is mounted and

/sbin/init

is executed.

Compiling the Kernel

After understanding the layout, you can compile a custom kernel in a few steps.

Download

Obtain the source from kernel.org (example uses version 3.12.17).

make mrproper

Clean previous build artifacts (equivalent to

make clean all

).

make menuconfig

Launch the configuration UI (install

ncurses-devel

if needed). The interface lets you enable or disable features such as Bluetooth drivers or NAT modules. Options are set to

m

,

y

, or

n

.

Only load the modules you need; compiling everything makes the kernel bulky. Example configuration flags for cgroup support:

<code>CONFIG_CGROUP_SCHED=y
CONFIG_CGROUPS=y
CONFIG_CGROUP_NS=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CGROUP_DEVICE=y
CONFIG_CGROUP_CPUACCT=y
CONFIG_CGROUP_MEM_RES_CTLR=y
CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_PERF=y
CONFIG_SCHED_AUTOGROUP=y
CONFIG_CFQ_GROUP_IOSCHED=y
CONFIG_NET_CLS_CGROUP=y
CONFIG_NETPRIO_CGROUP=y</code>

To simplify selection, copy the current server’s

.config

as a baseline, adjusting for version differences.

make dep

Check and resolve configuration dependencies, updating

.config

accordingly.

make clean

Remove artifacts from previous builds.

make -j8 bzImage

Build the compressed kernel image;

-j8

runs eight parallel jobs (use

-j&lt;2×CPU cores&gt;

for faster builds).

make -j8 modules

Compile loadable modules.

make -j8 modules_install

Install modules into

/lib/modules/&lt;kernel-version&gt;/

.

make -j8 install

Copy the kernel image, initramfs, and update

/etc/grub.conf

. Adjust the boot order manually if needed.

After rebooting, verify the new kernel runs correctly.

Kernel Migration

To deploy a compiled kernel to many servers without recompiling, transfer the following files:

/boot/vmlinuz-3.12.16

/boot/System.map-3.12.16

/lib/modules

/lib/firmware

<code>cp vmlinuz-3.12.16 /boot/
cp System.map-3.12.16 /boot/
mkdir -p /lib/modules/3.12.16
/bin/cp -r modules/* /lib/modules/3.12.16/
mv /lib/firmware /lib/firmware_old
cp -r firmware /lib/</code>

Then generate a new initramfs and update GRUB:

<code>/sbin/new-kernel-pkg -v --mkinitrd --depmod --install --make-default --dracut --host-only 3.12.35-101.el6.x86_64</code>

RPM‑Based Upgrade

On CentOS, kernel updates are delivered as RPM packages. Build your custom kernel into an RPM to upgrade multiple servers with a single command:

<code>yum upgrade kernel</code>

To create the RPM, download the source RPM, install it, and modify the

.spec

file:

<code>rpm -i kernel-3.10.0-514.el7.src.rpm
# edit /root/rpmbuild/SPECS/kernel.spec to point to your source and config
# then rebuild the package</code>

By assigning a higher version number (e.g., “100”), your custom RPM will be preferred over the distribution’s kernel during upgrades.

operationsKernelCompilationLinuxUpgraderpm
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login 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.