Linux Kernel and Boot Process¶
The kernel is the core of the operating system, mediating between hardware and user programs. This entry covers kernel architecture, modules, the boot sequence, memory management, and init systems.
Key Facts¶
- Linux uses a modular kernel - modules load/unload without reboot
- Technically, "Linux" is the kernel; the OS = GNU programs + Linux kernel
- LTS kernel versions receive extended maintenance
- systemd is PID 1 on modern distros
Kernel Functions¶
- Device support - USB, webcams, input devices
- Data storage - RAM management, persistent storage, virtual FS
- Network access - physical and virtual networking
- Task scheduling - CPU time sharing, priorities
- Security - file permissions, resource access control
Kernel Version¶
Format: A.B.C[.D] (e.g., 5.4.20, 6.1.52)
Kernel Space vs User Space¶
- Kernel space - privileged, direct hardware access (drivers, FS)
- User space - restricted, user programs
- Communication via system calls
Boot Sequence¶
- BIOS/UEFI - hardware init, POST
- Partition table - find bootable device
- GRUB bootloader - loaded from boot sector
- Kernel - GRUB loads
vmlinuzfrom/boot - initrd/initramfs - temporary root FS for early boot
- systemd (PID 1) - starts all services
GRUB Configuration¶
# User config (edit this)
/etc/default/grub
# Generated config (do NOT edit directly)
/boot/grub/grub.cfg
# Regenerate after editing
sudo update-grub # Debian/Ubuntu
sudo grub2-mkconfig -o /boot/grub2/grub.cfg # RHEL
/boot Contents¶
vmlinuz- compressed kernel imageinitrd.img- initial RAM disk/boot/grub/- bootloader files
Kernel Modules¶
lsmod # list loaded modules
modinfo <module> # detailed info
sudo modprobe <module> # load (resolves dependencies)
sudo modprobe -r <module> # remove
sudo insmod /path/module.ko # load from file (no deps)
sudo rmmod <module> # remove
cat /proc/modules # module info file
Init Systems¶
| System | Description |
|---|---|
| SysV Init | Classic sequential, runlevels |
| Upstart | Event-based, parallel (Canonical) |
| systemd | Current standard, parallel, dependency-based |
Memory Management¶
Virtual Memory¶
- Memory page = 4 KB
- Kernel allocates on process request
- LRU (Least Recently Used) cache eviction
Swap¶
Extends virtual memory beyond physical RAM.
- Can be partition or file
- Attach/detach at runtime
- Used for hibernation state
OOM Killer¶
When RAM exhausted: OOM Killer terminates processes to free memory. Each process has an OOM score (higher = more likely to be killed).
Process Creation¶
- Name assigned
- Added to process list
- Priority determined
- Process control block (PCB) formed
- Resources allocated
Signals¶
| Signal | Number | Description |
|---|---|---|
| SIGHUP | 1 | Hangup / reload |
| SIGINT | 2 | Interrupt (Ctrl+C) |
| SIGKILL | 9 | Force kill |
| SIGTERM | 15 | Graceful terminate |
| SIGSTOP | 19 | Pause (Ctrl+Z) |
kill -l # list all signals
kill -9 PID # SIGKILL
kill -15 PID # SIGTERM (default)
killall process # kill by name
Boot Analysis¶
systemd-analyze # total boot time
systemd-analyze blame # time per service
systemd-analyze critical-chain # boot critical path
systemd-analyze plot > boot.svg # visual timeline
Gotchas¶
- Verify module stability before loading in production
insmoddoes not resolve dependencies;modprobedoes- Editing
/boot/grub/grub.cfgdirectly is overwritten byupdate-grub - OOM Killer selection is not always predictable - critical services can be killed
- Swap on SSD causes write wear; swap on HDD causes latency
See Also¶
- systemd and services - systemctl, service lifecycle
- disks and filesystems - Boot partition, LUKS, fstab
- process management - Process states, signals, kill
- monitoring and performance - Memory and load monitoring