Skip to content
$ lynuxpro
← Linux

LESSON 21 OF 26 · ADVANCED · 17 MIN

Boot process, kernel and sysctl

In one minute

  • What happens between pressing the power button and seeing the login prompt, plus how to change the kernel's settings while it is running (with sysctl).
  • When a server does not come back after a reboot, you need to know which stage broke. And databases, busy web servers and every Kubernetes node need a few kernel settings changed.
  • The machine starts in stages, like a relay race: firmware → bootloader (GRUB) → kernel → systemd → services. Each stage hands over to the next. Once running, the kernel has hundreds of settings you can read and change with sysctl.
  • 👉 A server will not boot, a server crashed and you need to know why, or you are setting up a Kubernetes node or a database server.

Think of it like: starting a car. Turn the key (firmware), the starter motor spins (GRUB), the engine runs (kernel), then the dashboard, radio and lights come on (systemd and services).

The boot sequence

Firmware (BIOS / UEFI) → Bootloader (GRUB) → Kernel + initramfs → systemd (PID 1) → Targets and services → Login
OUTPUTterminalutf-8 · 1L
StageWhat happensWhere problems show up
FirmwareChecks the hardware and finds the boot diskConsole only
GRUBLoads the kernel and passes it settings/boot/grub/grub.cfg
KernelFinds the hardwaredmesg, journalctl -k
initramfsA tiny starter system that loads the drivers needed to find the real disk, then hands over"Cannot find root device" errors
systemdMounts the disks in /etc/fstab and starts servicessystemctl --failed, journalctl -b

Remember it: Firmware → GRUB → Kernel → Systemd: "Five Great Kids Start".

Looking at the boot

👉 The server boots slowly, or it crashed and you want to know why.

uname -rdmesg | tail -n 5systemd-analyze
SHELLbashutf-8 · 3L
systemd-analyze                 # total boot time split by stagesystemd-analyze blame | head    # slowest servicessystemd-analyze critical-chain  # what the boot waited onjournalctl -b -1 -p err         # errors from the previous bootlast reboot                     # reboot history
OUTPUTterminalutf-8 · 5L

journalctl -b -1 is how you find out why a server crashed or rebooted. It shows the logs from the boot before the current one. This only works if the journal is saved to disk (persistent).

systemd targets

A target is a group of services that make up one "mode" of the machine.

TargetMeaning
multi-user.targetNormal server mode, no desktop
graphical.targetWith a desktop
rescue.targetOne user, few services, for repairs
emergency.targetThe bare minimum, disk read-only
systemctl get-defaultsudo systemctl set-default multi-user.target
OUTPUTterminalutf-8 · 2L

Kernel settings at boot

GRUB passes settings to the kernel as it starts. See the current ones:

cat /proc/cmdline
SHELLbashutf-8 · 1L
BOOT_IMAGE=/boot/vmlinuz-6.8.0-49-generic root=UUID=3f1c...e2 ro console=ttyS0 quiet
OUTPUTterminalutf-8 · 1L

How to change them for good: edit GRUB_CMDLINE_LINUX in /etc/default/grub, then run sudo update-grub (Debian) or sudo grub2-mkconfig -o /boot/grub2/grub.cfg (RHEL).

👉 For example, console=ttyS0 for cloud serial consoles, or switching on cgroup v2 for Kubernetes.

Kernel modules

A module is a piece of the kernel (a driver or feature) that can be loaded while the system runs, like a plug-in.

👉 Setting up Kubernetes nodes, or adding hardware support.

lsmod
SHELLbashutf-8 · 1L
lsmod | grep br_netfiltersudo modprobe br_netfilter           # load nowecho br_netfilter | sudo tee /etc/modules-load.d/k8s.conf   # load at every bootmodinfo overlay                      # describe a module
OUTPUTterminalutf-8 · 4L

Every Kubernetes node needs two modules:

  • overlay, for container filesystems.
  • br_netfilter, so pod traffic passes through the firewall rules.

Forgetting them is a classic reason a new cluster does not work.

sysctl: changing the running kernel

The kernel has hundreds of settings, kept under /proc/sys. sysctl reads and changes them.

The defaults suit a general machine. Routers, databases and very busy servers need a few changes.

sysctl net.ipv4.ip_forwardsudo sysctl -w net.ipv4.ip_forward=1
SHELLbashutf-8 · 2L
net.ipv4.ip_forward = 1
OUTPUTterminalutf-8 · 1L
  • sysctl -w changes the value now, but the change is lost on reboot.
  • To keep it, put it in a file under /etc/sysctl.d/, then run sudo sysctl --system.

Remember it: -w = works now, gone after reboot. A file in /etc/sysctl.d/ = forever.

# /etc/sysctl.d/99-k8s.confnet.ipv4.ip_forward = 1net.bridge.bridge-nf-call-iptables = 1net.bridge.bridge-nf-call-ip6tables = 1
OUTPUTterminalutf-8 · 4L

Settings you will actually change

SettingTypical defaultWhy change it
net.ipv4.ip_forward0Must be 1 on routers, Docker hosts and Kubernetes nodes (lets traffic pass through)
net.core.somaxconn4096A longer waiting queue for very busy web servers
net.ipv4.ip_local_port_range32768 60999More outgoing ports for proxies that open many connections
net.ipv4.tcp_tw_reuse2Reuse closing connections for new outgoing ones
net.netfilter.nf_conntrack_maxDepends on RAMRaise on NAT gateways and busy Kubernetes nodes
fs.file-maxLargeLimit on open files for the whole system
fs.inotify.max_user_watches8192 to 65536Raise for file watchers, log agents and code editors
vm.swappiness60Lower (1–10) on database servers to avoid swapping
vm.max_map_count65530Elasticsearch and OpenSearch need 262144
vm.overcommit_memory0Redis recommends 1

Only change what you have a reason to change. Measure before and after, and write why as a comment in the file.

Per-program limits: ulimit

sysctl sets limits for the whole system. ulimit sets limits for each program, such as how many files it may open.

👉 You see "Too many open files" in a busy app.

ulimit -n
SHELLbashutf-8 · 1L
ulimit -n                         # current open-files limit for this shell# permanent for a systemd service:LimitNOFILE=65536                 # in the [Service] section# for login sessions: /etc/security/limits.conf
OUTPUTterminalutf-8 · 4L

"Too many open files" usually means LimitNOFILE is too low for that service.

Rescuing a server that will not boot

What you seeLikely causeHow to recover
Drops into emergency modeA bad line in /etc/fstabRemount the disk read-write, fix fstab, reboot
Kernel panic after an updateThe new kernel is brokenPick the previous kernel in the GRUB menu
No SSH after a network changeA network config mistakeUse the cloud serial console or SSM
Root disk fullServices fail to startAttach the disk to a rescue server and clean it

In AWS, the EC2 serial console and Get system log show the boot output. As a last resort: stop the server, detach its disk, attach it to a rescue server, fix the files, and move the disk back.

Real-world scenario: Kubernetes pods cannot talk to each other

A new node joins the cluster, but pods on it cannot reach pods on other nodes.

sysctl net.ipv4.ip_forwardlsmod
SHELLbashutf-8 · 2L
  • ip_forward is 0, so the node will not pass traffic through.
  • br_netfilter is not loaded.

Fix: add both to /etc/modules-load.d/k8s.conf and /etc/sysctl.d/99-k8s.conf, apply with modprobe and sysctl --system, and build them into the node image so the next node is right from the start.

Common mistakes

  • Using only sysctl -w, so the setting disappears after a reboot.
  • Copying tuning settings from blogs without understanding or measuring them.
  • Editing grub.cfg directly instead of /etc/default/grub.
  • No persistent journal, so you cannot see why the last boot failed.

Practice

  1. Show the running kernel version and the kernel's boot settings.
  2. Find the three slowest services at boot.
  3. Turn on IP forwarding now and permanently.
  4. Write the two modules and three sysctl lines every Kubernetes node needs.

Cheat sheet

CommandWhat it does
uname -rRunning kernel version
systemd-analyze blameSlowest services at boot
journalctl -b -1 -p errErrors from the previous boot
lsmod / modprobe xList / load kernel modules
sysctl key / sysctl -w key=vRead / change a kernel setting
sysctl --systemApply all files in /etc/sysctl.d/
ulimit -nOpen-files limit

Key takeaways

  • A server starts in stages: firmware, GRUB, kernel, then systemd starts the services.
  • journalctl -b -1 shows what happened before the last crash or reboot.
  • Kernel modules are plug-ins. Kubernetes needs overlay and br_netfilter.
  • sysctl changes kernel settings. Put them in /etc/sysctl.d/ to keep them after reboot.
  • Only change kernel settings when you have a clear reason.