Skip to content

Linux Kernel Compilation

Mattscreative edited this page Nov 19, 2025 · 2 revisions

🔨 Linux Kernel Compilation Guide

Complete beginner-friendly guide to kernel compilation on Linux, covering Arch Linux, CachyOS, and other distributions including downloading kernel source, configuring, compiling, and installing custom kernels.


📋 Table of Contents

  1. Preparing for Compilation
  2. Downloading Source
  3. Configuring Kernel
  4. Compiling Kernel
  5. Installing Kernel
  6. Troubleshooting

🛠️ Preparing for Compilation

Install Tools

Install build tools:

# Arch/CachyOS
sudo pacman -S base-devel linux-headers

# Debian/Ubuntu
sudo apt install build-essential linux-headers-$(uname -r)

# Fedora
sudo dnf groupinstall "Development Tools"
sudo dnf install kernel-devel

Check Requirements

Verify tools:

# Check GCC
gcc --version

# Check Make
make --version

# Check kernel headers
ls /usr/src/linux-headers-*

📥 Downloading Source

Get Kernel Source

Arch/CachyOS:

# Get kernel source using asp
asp update linux
asp checkout linux

# Or download from kernel.org
wget https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.1.tar.xz
tar xf linux-6.1.tar.xz
cd linux-6.1

Debian/Ubuntu:

# Download kernel source
apt source linux-source

Fedora:

# Download kernel source
dnf download --source kernel

⚙️ Configuring Kernel

Kernel Configuration

Configure kernel:

# Copy existing config
cp /proc/config.gz .
gunzip config.gz
cp config .config

# Or use defaults
make defconfig

# Configure (menu-based)
make menuconfig

# Or use existing config
zcat /proc/config.gz > .config
make olddefconfig

Configuration Options

Common options:

  • menuconfig: Text-based menu
  • xconfig: X11 GUI (requires Qt)
  • gconfig: GTK GUI
  • oldconfig: Use existing config

🔨 Compiling Kernel

Build Kernel

Compile:

# Get number of CPUs
nproc

# Compile (use all CPUs)
make -j$(nproc)

# Build modules
make modules

# Install modules
sudo make modules_install

What it does:

  • Compiles kernel image
  • Builds kernel modules
  • Takes time (30 minutes to hours)

📦 Installing Kernel

Install Kernel

Arch/CachyOS:

# Copy kernel
sudo cp arch/x86/boot/bzImage /boot/vmlinuz-linux-custom

# Update bootloader (GRUB)
sudo grub-mkconfig -o /boot/grub/grub.cfg

# Or systemd-boot
sudo cp arch/x86/boot/bzImage /boot/EFI/arch/vmlinuz-linux-custom

Debian/Ubuntu:

# Install kernel
sudo make install

# Update bootloader
sudo update-grub

Fedora:

# Install kernel
sudo make install

# Update bootloader
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

🔧 Troubleshooting

Compilation Errors

Common issues:

# Check errors
make -j$(nproc) 2>&1 | tee build.log

# Clean build
make clean

# Reconfigure
make menuconfig

Boot Issues

If kernel doesn't boot:

# Boot from previous kernel
# Select from GRUB menu

# Check logs
journalctl -k

# Verify kernel
uname -r

📝 Summary

This guide covered kernel compilation for Arch Linux, CachyOS, and other distributions, including preparation, source download, configuration, compilation, and installation.


🔗 Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally