Skip to main content

Linux Kernel

The Linux kernel is the core of the operating system. It manages hardware, memory, processes, and networking, and gives applications controlled access to them through system calls.

Understanding the Linux Kernel

What Does the Linux Kernel Do?

The kernel sits between hardware and software. It schedules which process runs on which CPU, manages memory, talks to disks and network cards through drivers, and enforces permissions. Everything else, including bash, nginx, Docker, and Python, runs on top of it in user space. DevOps engineers touch the kernel constantly through sysctl settings, kernel modules, dmesg, and the /proc and /sys filesystems.

How Kernel Space and User Space Are Separated

The CPU enforces the split: the kernel runs in a privileged mode with full hardware access, while applications run in a restricted mode. They cross the boundary only through system calls such as read and write. This is why a buggy application cannot directly corrupt kernel memory.

flowchart TD A[User space: nginx, postgres, docker] -->|system calls| B[Kernel: scheduler, memory, VFS, network stack, drivers] B --> C[Hardware: CPU, RAM, disk, NIC]

Practical Kernel Commands

Bash
uname -r # kernel version
dmesg -T | tail -20 # kernel messages with readable times
dmesg -T | grep -i -E 'oom|error|fail'
sysctl net.ipv4.tcp_syncookies # read a parameter
sudo sysctl -w vm.swappiness=10 # change now (lost at reboot)
# Persist settings
echo 'vm.swappiness = 10' | sudo tee /etc/sysctl.d/99-custom.conf
sudo sysctl --system # reload all sysctl files
lsmod # loaded modules
sudo modprobe br_netfilter # load a module
echo br_netfilter | sudo tee /etc/modules-load.d/k8s.conf # load at boot
cat /proc/cmdline # boot parameters
grep -E 'MemTotal|MemAvailable|SwapTotal' /proc/meminfo

Troubleshooting the Kernel

Symptom Command What to Check
Apps dying unexpectedly dmesg -T | grep -i oom OOM killer activity
Module missing lsmod | grep name Load with modprobe
High system CPU top (sy column) Time spent in kernel
Network tuning sysctl -a | grep net.ipv4 Kernel network settings
Tip

dmesg -T | grep -i oom is the first command when processes vanish without an application error. The kernel logs which process it killed and how much memory it used.

Remember

Changes made with sysctl -w are temporary. Write them to /etc/sysctl.d/ to survive reboot. Kubernetes setups often need persistent values such as net.bridge.bridge-nf-call-iptables=1.

Security

Only load kernel modules from trusted sources. A module runs with full kernel privileges, so a malicious or buggy one can compromise the whole system.

Frequently Asked Questions

How is the kernel/user space split enforced?

The CPU provides privilege levels. Kernel code runs with unrestricted hardware access, and applications run with restricted access. They interact only through system calls, which switch privilege levels in a controlled way.

How is a kernel panic different from an application crash?

An application crash is contained and the kernel cleans up after it. A kernel panic means the kernel itself hit an unrecoverable error, so the whole machine halts and normally needs a reboot.

Is the kernel the same as the operating system?

The kernel is the core of it. A full Linux distribution adds the shell, libraries, package manager, and tools around the kernel.

Found a mistake, an outdated step or a broken link?