1 min read #devops
On this page

Kernel Operations Manual

Compilation, module management, DKMS, and initramfs operations for custom Gentoo kernels.

Status Checks

uname -r                                 # Currently running kernel version
uname -a                                 # Full: version + architecture + build date
cat /proc/version                        # Kernel version + compiler information

# Installed kernels
ls -la /boot/vmlinuz-*                   # Kernel images
ls -la /lib/modules/                     # Module directory (one per kernel)
eselect kernel list                      # View via eselect

# Current kernel configuration
zcat /proc/config.gz                     # Configuration of the running kernel (requires CONFIG_IKCONFIG)
zcat /proc/config.gz | grep CONFIG_NF_TABLES
# If you can't view it: the kernel doesn't have CONFIG_IKCONFIG_PROC enabled. Check /boot/config-$(uname -r)

# Loaded modules
lsmod                                    # Loaded modules and reference counts
lsmod | grep mt7927
modinfo mt7927                           # Module details: parameters/dependencies/path/signature

# Kernel logs
dmesg -w                                 # Real-time kernel log
dmesg -T                                 # With human-readable timestamps
dmesg --level=err,warn                   # Show only errors and warnings
dmesg | grep -i "firmware\|mt79\|amdgpu" # Firmware/driver related

# Kernel parameters (runtime)
sysctl -a                                # List all parameters
sysctl net.ipv4.ip_forward               # Check a single parameter
sysctl net.ipv4                          # Check an entire subsystem

Kernel Compilation

# Source location
eselect kernel list                      # View available sources
eselect kernel set linux-6.6.21-gentoo   # Switch
cd /usr/src/linux                        # Symbolic link → current source directory

# Configuration
make menuconfig                          # TUI configuration
make oldconfig                           # Upgrade from old .config (interactive)
make olddefconfig                        # Upgrade from old .config (auto-select defaults)
make localmodconfig                      # Enable only options for currently loaded modules (minimal config)
make nconfig                             # Another TUI

# Save/restore configuration
cp .config /boot/config-6.6.21-gentoo    # Backup (convenient for future reference)
# If backup exists: cp /boot/config-6.6.21-gentoo .config && make olddefconfig

# Compilation (Gentoo)
make -j$(nproc)                          # Parallel compilation
make -j$(nproc) modules_install          # Install modules to /lib/modules/X.Y.Z/
make install                             # Install vmlinuz + System.map to /boot

# Or use genkernel (automated)
genkernel all                            # Fully automatic compilation + initramfs
genkernel --menuconfig all               # Let you modify configuration before compilation
genkernel --lvm --mdadm all              # Includes LVM/RAID support

# Distribution kernel (Gentoo, recommended)
emerge -av sys-kernel/gentoo-kernel      # Use distribution kernel (auto-updates, similar to Ubuntu)
# Alternatively: emerge gentoo-sources + manual compilation (more flexible)

DKMS (Dynamic Kernel Module Support)

# Status
dkms status                              # List all DKMS modules and their status (installed/built/added)
# Example: mt7927/2.12, 6.6.21-gentoo, x86_64: installed

# Install modules
dkms add /path/to/source                 # Add source to DKMS tree
dkms build mt7927/2.12                   # Compile
dkms install mt7927/2.12                 # Install to current kernel
dkms autoinstall                         # Automatically compile all DKMS modules for new kernels

# Uninstall/Remove
dkms remove mt7927/2.12 --all            # All kernels
dkms remove mt7927/2.12 -k 6.6.21        # Specific kernel
dkms uninstall mt7927/2.12               # Uninstall module (keep source)

# Debugging
dkms status --verbose                    # Detailed information
dkms build mt7927/2.12 --verbose         # Detailed compilation log
cat /var/lib/dkms/mt7927/2.12/build/make.log  # Build log

# DKMS auto-trigger mechanism after new kernel installation:
# @module-rebuild automatically calls dkms autoinstall during installkernel
# Check: eselect kernel list to confirm new kernel is selected, dkms status to confirm state

Module Management

# Temporary load/unload
modprobe mt7927                           # Load module (with dependencies)
modprobe -r mt7927                        # Unload module (with unused dependencies)
modprobe -f mt7927                        # Force load (ignore version mismatch)
modprobe -r --force mt7927                # Force unload

# Module parameters
modinfo -p mt7927                         # View supported parameters
modprobe mt7927 param1=value1             # Set parameters at load time
# Persistence: echo "options mt7927 param1=value1" > /etc/modprobe.d/mt7927.conf

# Blacklist (prevent loading)
# echo "blacklist nouveau" > /etc/modprobe.d/blacklist.conf
# echo "blacklist mt7927" > /etc/modprobe.d/blacklist-mt7927.conf

# Auto-load (at boot)
# echo "mt7927" > /etc/modules-load.d/mt7927.conf

# Parameters for all loaded modules
systool -vm mt7927                        # sysfs perspective (requires sysfsutils)
cat /sys/module/mt7927/parameters/*       # Check current value of each parameter

initramfs (dracut)

# Generate initramfs
dracut --force /boot/initramfs-6.6.21-gentoo.img 6.6.21-gentoo
dracut --force --hostonly /boot/initramfs-6.6.21-gentoo.img  # Modules needed only for current host
dracut --force --lvm --mdadm /boot/initramfs-6.6.21-gentoo.img  # Includes LVM/RAID

# View initramfs contents
lsinitrd /boot/initramfs-6.6.21-gentoo.img      # File list
lsinitrd /boot/initramfs-6.6.21-gentoo.img | grep lvm
lsinitrd --mod /boot/initramfs-6.6.21-gentoo.img # Included dracut modules

# Debug boot issues
dracut --force --verbose /boot/initramfs-6.6.21-gentoo.img  # View inclusion process
# Add to GRUB command line: rd.debug rd.shell
# Enter emergency shell if issues occur:
journalctl -b                              # View logs for this boot

# Kernel cmdline (GRUB)
# /etc/default/grub:
# GRUB_CMDLINE_LINUX="quiet splash rd.lvm.vg=vg0 resume=/dev/vg0/swap"
grub-mkconfig -o /boot/grub/grub.cfg       # Regenerate GRUB configuration

Kernel Parameter Tuning (sysctl)

# Temporary settings
sysctl -w net.ipv4.ip_forward=1
sysctl -w vm.swappiness=10

# Persistence
# /etc/sysctl.conf or /etc/sysctl.d/99-custom.conf:
#   net.ipv4.ip_forward = 1
#   vm.swappiness = 10
sysctl -p                                   # Load configuration
sysctl --system                              # Load all sysctl.d

# Common tuning items
# net.core.default_qdisc = fq                # qdisc for BBR
# net.ipv4.tcp_congestion_control = bbr      # TCP congestion control
# vm.swappiness = 1                          # Avoid swap as much as possible (1 is lowest besides 0)
# kernel.sysrq = 1                           # Enable Magic SysRq
# fs.inotify.max_user_watches = 524288       # inotify watch limit (for IDE/LSP with many files)

Kernel Debugging

# Boot parameters (temporary GRUB cmdline change)
# single                  # Single-user mode (maintenance)
# init=/bin/bash          # Enter shell directly (bypass init)
# ignore_loglevel         # Display all kernel logs
# rd.break=pre-mount      # dracut: Stop before mounting root filesystem

# Magic SysRq (Kernel emergency)
echo 1 > /proc/sys/kernel/sysrq            # Enable
# Alt+SysRq + b  → Immediate reboot
# Alt+SysRq + s  → Sync disks
# Alt+SysRq + u  → Remount read-only
# Alt+SysRq + e  → SIGTERM all processes
# Alt+SysRq + i  → SIGKILL all processes
# Safe reboot sequence: R E I S U B (or remember: "BUSIER" backwards)

# Post-crash analysis
cat /proc/sys/kernel/panic                 # Auto-reboot N seconds after crash (0=no auto-reboot)
# Enable kdump with crash tool to analyze vmcore

# Performance observation
perf top                                   # Real-time hot functions
perf record -g sleep 10 && perf report     # Sampling + flame graph data