brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: kernel.panic = 10 makes a headless Linux box reboot itself after a kernel panic

Linux
~/tips/tip-linux-kernel-panic-auto-reboot

sysctl kernel.panic

Have a remote server restart on its own instead of hanging forever after a panic.

After a kernel panic, the default is to stop and wait. On a desktop you see the message; on a server in a cupboard or a VPS, it just stays dead until someone presses reset.

sysctl kernel.panic

The kernel documentation explains the values: 0 means the kernel loops forever, a positive number reboots after that many seconds, and a negative number reboots right away. For a machine you cannot reach easily, I like a short delay:

echo 'kernel.panic = 10' | sudo tee /etc/sysctl.d/90-panic.conf
sudo sysctl -p /etc/sysctl.d/90-panic.conf

The ten seconds give a monitor or console a moment to show the message before the reboot wipes it.

A related setting is kernel.panic_on_oops. An oops is a serious kernel error that the kernel tries to survive. With panic_on_oops = 1 it panics instead, and together with kernel.panic the machine reboots into a clean state rather than running on in a damaged one. That is a trade off: you lose the running state but avoid odd half broken behaviour.

Automatic reboots hide the cause, because the panic message is gone after the restart. If panics happen more than once, set up a way to keep the message, such as a serial console, netconsole or kdump, and look in the logs of the previous boot. Rebooting is a stopgap for availability, not a fix for whatever crashes the kernel.

Further reading: Documentation for /proc/sys/kernel/

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link