Master Elegant Linux Kernel Upgrades: Step-by-Step Guide
This article walks you through the complete process of upgrading the Linux kernel—explaining kernel fundamentals, compilation steps, configuration tuning, packaging as RPM, and deployment across multiple servers—to achieve efficient, reliable, and elegant kernel updates in production environments.
Preface
The ADDOPS team presents a practical guide to upgrading the Linux kernel, aiming to make the process more elegant and efficient for daily operations.
Kernel Overview
The kernel is the core component of Linux, bridging user space and hardware. Many system functions such as iptables, cgroups, and debugging rely on kernel support.
Kernel Components
Key files that constitute the kernel include:
/boot/vmlinuz-3.8.0 – the compressed bootable kernel image.
/boot/initramfs-3.8.0.img – initial RAM filesystem containing essential drivers.
/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 Loading Sequence
Boot loader loads the kernel and initrd images into RAM.
The boot loader transfers execution control to the Linux kernel.
The kernel decompresses initrd and mounts it as a temporary root filesystem.
The kernel mounts the temporary root as /dev/ram0 in read‑write mode.
User space /linuxrc runs to perform early setup tasks.
Control returns to the kernel after /linuxrc finishes.
The kernel mounts the real root filesystem and starts /sbin/init .
Compiling the Kernel
Follow these steps to build a custom kernel (example based on version 3.12.17):
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.12.17.tar.xz
tar -xf linux-3.12.17.tar.xz && cd linux-3.12.17
make mrproper – clean previous build artifacts.
make menuconfig – launch the configuration UI (requires ncurses-devel ).
During make menuconfig you select options (m, y, n). Unselected options may omit needed features (e.g., NAT). The resulting .config file drives the build.
Typical configuration snippets:
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=yAfter configuring, run:
make dep – resolve dependencies and update .config .
make clean – remove previous build leftovers.
make -j8 bzImage – compile the kernel image using parallel jobs.
make -j8 modules – build loadable modules.
make -j8 modules_install – install modules to /lib/modules/… .
make -j8 install – copy the kernel, initramfs, and update /etc/grub.conf .
Adjust the boot order in grub.conf so the new kernel becomes the default, then reboot.
Kernel Migration
To deploy a compiled kernel to multiple servers without rebuilding:
cp vmlinuz-3.12.16 /boot/
cp System.map-3.12.16 /boot/
mkdir -p /lib/modules/3.12.16
cp -r modules/* /lib/modules/3.12.16/
mv /lib/firmware /lib/firmware_old
cp -r firmware /lib/Package these files and transfer them to target machines, then adjust the bootloader.
RPM Package Upgrade
On CentOS, kernel updates are delivered as RPMs. You can build your custom kernel into an RPM to simplify upgrades:
Download the source RPM (e.g., rpm -i kernel-3.10.0-514.el7.src.rpm ).
Edit /root/rpmbuild/SPECS/kernel.spec to point to your source tarball and desired configuration.
Build the RPM with rpmbuild -ba /root/rpmbuild/SPECS/kernel.spec .
After building, install the new kernel with a single command:
yum upgrade kernelBy assigning a higher version number to your custom RPM, you ensure that yum prefers your kernel over the distribution’s default during upgrades.
360 Zhihui Cloud Developer
360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.