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| Stage | What happens | Where problems show up |
|---|---|---|
| Firmware | Checks the hardware and finds the boot disk | Console only |
| GRUB | Loads the kernel and passes it settings | /boot/grub/grub.cfg |
| Kernel | Finds the hardware | dmesg, journalctl -k |
| initramfs | A tiny starter system that loads the drivers needed to find the real disk, then hands over | "Cannot find root device" errors |
| systemd | Mounts the disks in /etc/fstab and starts services | systemctl --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-analyzesystemd-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 historyjournalctl -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.
| Target | Meaning |
|---|---|
multi-user.target | Normal server mode, no desktop |
graphical.target | With a desktop |
rescue.target | One user, few services, for repairs |
emergency.target | The bare minimum, disk read-only |
systemctl get-defaultsudo systemctl set-default multi-user.targetKernel settings at boot
GRUB passes settings to the kernel as it starts. See the current ones:
cat /proc/cmdlineBOOT_IMAGE=/boot/vmlinuz-6.8.0-49-generic root=UUID=3f1c...e2 ro console=ttyS0 quietHow 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.
lsmodlsmod | 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 moduleEvery 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=1net.ipv4.ip_forward = 1sysctl -wchanges the value now, but the change is lost on reboot.- To keep it, put it in a file under
/etc/sysctl.d/, then runsudo 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 = 1Settings you will actually change
| Setting | Typical default | Why change it |
|---|---|---|
net.ipv4.ip_forward | 0 | Must be 1 on routers, Docker hosts and Kubernetes nodes (lets traffic pass through) |
net.core.somaxconn | 4096 | A longer waiting queue for very busy web servers |
net.ipv4.ip_local_port_range | 32768 60999 | More outgoing ports for proxies that open many connections |
net.ipv4.tcp_tw_reuse | 2 | Reuse closing connections for new outgoing ones |
net.netfilter.nf_conntrack_max | Depends on RAM | Raise on NAT gateways and busy Kubernetes nodes |
fs.file-max | Large | Limit on open files for the whole system |
fs.inotify.max_user_watches | 8192 to 65536 | Raise for file watchers, log agents and code editors |
vm.swappiness | 60 | Lower (1–10) on database servers to avoid swapping |
vm.max_map_count | 65530 | Elasticsearch and OpenSearch need 262144 |
vm.overcommit_memory | 0 | Redis 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 -nulimit -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"Too many open files" usually means LimitNOFILE is too low for that service.
Rescuing a server that will not boot
| What you see | Likely cause | How to recover |
|---|---|---|
| Drops into emergency mode | A bad line in /etc/fstab | Remount the disk read-write, fix fstab, reboot |
| Kernel panic after an update | The new kernel is broken | Pick the previous kernel in the GRUB menu |
| No SSH after a network change | A network config mistake | Use the cloud serial console or SSM |
| Root disk full | Services fail to start | Attach 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_forwardlsmodip_forwardis 0, so the node will not pass traffic through.br_netfilteris 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.cfgdirectly instead of/etc/default/grub. - No persistent journal, so you cannot see why the last boot failed.
Practice
- Show the running kernel version and the kernel's boot settings.
- Find the three slowest services at boot.
- Turn on IP forwarding now and permanently.
- Write the two modules and three sysctl lines every Kubernetes node needs.
Cheat sheet
| Command | What it does |
|---|---|
uname -r | Running kernel version |
systemd-analyze blame | Slowest services at boot |
journalctl -b -1 -p err | Errors from the previous boot |
lsmod / modprobe x | List / load kernel modules |
sysctl key / sysctl -w key=v | Read / change a kernel setting |
sysctl --system | Apply all files in /etc/sysctl.d/ |
ulimit -n | Open-files limit |
Key takeaways
- A server starts in stages: firmware, GRUB, kernel, then systemd starts the services.
journalctl -b -1shows what happened before the last crash or reboot.- Kernel modules are plug-ins. Kubernetes needs
overlayandbr_netfilter. sysctlchanges kernel settings. Put them in/etc/sysctl.d/to keep them after reboot.- Only change kernel settings when you have a clear reason.