← Back to torvalds/linux

How to Deploy & Use torvalds/linux

Linux Kernel Build and Deployment Guide

Comprehensive guide for compiling, configuring, and installing the Linux kernel from source.

1. Prerequisites

Required Build Tools

# Debian/Ubuntu
sudo apt-get update
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev \
    dwarves python3 git bc cpio kmod

# Fedora/RHEL
sudo dnf groupinstall "Development Tools"
sudo dnf install ncurses-devel bison flex elfutils-libelf-devel openssl-devel \
    dwarves python3 git bc cpio kmod

# Arch Linux
sudo pacman -S base-devel ncurses bison flex openssl elfutils python git bc cpio kmod

Disk Space

  • Minimum: 15 GB free space (for kernel source + build artifacts)
  • Recommended: 25+ GB (for multiple configurations and debug symbols)

System Requirements

  • x86_64, ARM64, or supported architecture toolchain
  • Running Linux system (native build) or cross-compilation toolchain
  • Root access (for installation steps)

2. Installation

Clone the Repository

# Clone the mainline kernel
git clone https://github.com/torvalds/linux.git
cd linux

# Optional: Checkout specific version (e.g., v6.8)
git checkout v6.8

Verify Source Integrity

# Verify tags if using a release
git verify-tag v6.8  # Requires GPG setup for kernel.org keys

3. Configuration

Initial Configuration

Start with a base configuration matching your current system:

# Copy current running kernel's config
cp /boot/config-$(uname -r) .config

# Or use architecture defaults
make defconfig              # x86_64 default
make defconfig ARCH=arm64   # ARM64 default

# Update config for new kernel options (answer defaults)
make olddefconfig

Interactive Configuration (Optional)

Customize kernel features, drivers, and modules:

# Text-based menu (recommended)
make menuconfig

# GUI configuration (requires Qt)
make xconfig

# Minimal config (answer questions interactively)
make config

Key Configuration Files

  • .config: Main kernel configuration (generated/edited by above commands)
  • localversion: Append custom string to kernel version (e.g., -custom)
  • include/config/: Auto-generated headers during build

Environment Variables

# Speed up compilation (adjust to your CPU cores)
export MAKEFLAGS="-j$(nproc)"

# Cross-compilation example (ARM64 on x86)
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-

4. Build & Run

Compile the Kernel

# Full build (kernel + modules)
make

# Or explicitly specify jobs
make -j$(nproc)

# Build specific targets only
make bzImage          # Compressed kernel image only
make modules          # Loadable modules only

Install Modules

# Install kernel modules to /lib/modules/$(KERNELRELEASE)/
sudo make modules_install

Install Kernel

# Automated installation (updates bootloader)
sudo make install

# Manual installation (if automated fails)
sudo cp arch/x86/boot/bzImage /boot/vmlinuz-linux-custom
sudo cp System.map /boot/System.map-linux-custom
sudo cp .config /boot/config-linux-custom
sudo mkinitcpio -k <kernel-version> -g /boot/initramfs-linux-custom.img

Update Bootloader

GRUB (most distributions):

sudo update-grub              # Debian/Ubuntu
sudo grub2-mkconfig -o /boot/grub2/grub.cfg  # Fedora/RHEL

systemd-boot:

sudo kernel-install add <kernel-version> /boot/vmlinuz-linux-custom

Manual GRUB entry (if needed): Edit /etc/grub.d/40_custom:

menuentry "Linux Custom" {
    linux /boot/vmlinuz-linux-custom root=UUID=<your-root-uuid> rw
    initrd /boot/initramfs-linux-custom.img
}

Testing in Virtual Machine (Recommended First)

Before installing on bare metal:

# Build for QEMU testing
make -j$(nproc)
make modules_install INSTALL_MOD_PATH=/tmp/rootfs

# Run with QEMU
qemu-system-x86_64 -kernel arch/x86/boot/bzImage \
    -append "root=/dev/sda1 console=ttyS0" \
    -drive file=disk.img,format=raw \
    -serial stdio

5. Deployment

Production Deployment Strategies

Package-Based Deployment (Recommended for fleets):

# Create Debian package
make bindeb-pkg LOCALVERSION=-custom

# Creates ../linux-image-*.deb and ../linux-headers-*.deb
sudo dpkg -i ../linux-image-*.deb

# Create RPM (Fedora/RHEL)
make binrpm-pkg LOCALVERSION=-custom

Container/Cloud Deployment:

# Build for containerized environments (minimal config)
make tinyconfig
make menuconfig  # Enable necessary container features
make -j$(nproc)

# Create custom initramfs for cloud images
dracut --kver <version> /boot/initramfs-custom.img

Embedded/IoT Cross-Compilation:

# ARM64 embedded device
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make defconfig
make menuconfig  # Enable specific SoC drivers
make -j$(nproc)
make INSTALL_MOD_PATH=/mnt/rootfs modules_install

Kernel Update Management

# Keep old kernel as fallback
sudo kernel-install add <new-version> /boot/vmlinuz-new

# Set default boot entry
sudo grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux custom"

6. Troubleshooting

Build Errors

Error: openssl/opensslv.h: No such file or directory

# Solution: Install OpenSSL development headers
sudo apt-get install libssl-dev  # Debian/Ubuntu
sudo dnf install openssl-devel   # Fedora

Error: bc: command not found

# Solution: Install basic calculator
sudo apt-get install bc

Error: fatal error: gelf.h: No such file

# Solution: Install elfutils
sudo apt-get install libelf-dev

Error: No rule to make target 'debian/canonical-certs.pem'

# Solution: Remove certificate references from config
scripts/config --disable SYSTEM_TRUSTED_KEYS
scripts/config --disable SYSTEM_REVOCATION_KEYS
make olddefconfig

Boot Failures

Issue: Kernel panic - not syncing: VFS: Unable to mount root fs

# Solution: Ensure SATA/NVMe drivers built-in (not modules)
make menuconfig
# Device Drivers -> Serial ATA and Parallel ATA drivers -> <*> AHCI SATA support
# Or ensure initramfs includes necessary drivers

Issue: Module version mismatch

# Rebuild modules for exact kernel version
make clean
make prepare
make modules
sudo make modules_install

Issue: Missing firmware

# Install linux-firmware package or build into kernel
# Firmware Drivers -> Firmware loading facility -> Build named firmware blobs into the kernel binary

Runtime Issues

Issue: New kernel not showing in bootloader

# Reinstall and update GRUB
sudo make install
sudo update-grub

# Or manually copy and update
sudo cp arch/x86/boot/bzImage /boot/vmlinuz-$(make kernelrelease)
sudo update-initramfs -c -k $(make kernelrelease)

Issue: Performance degradation

# Check for debugging features accidentally enabled
cat /boot/config-$(uname -r) | grep DEBUG
# Disable: CONFIG_DEBUG_KERNEL, CONFIG_DEBUG_FS, CONFIG_KGDB in .config

Cleaning Build Artifacts

make clean          # Remove most generated files (keep .config)
make mrproper       # Remove all generated files + .config
make distclean      # Remove editor backups and patches