In enterprise production environments, edge deployments, and cloud instances, high availability is paramount. However, when an Ubuntu server encounters a catastrophic fatal error—such as hardware memory faults, driver deadlocks, or filesystem corruption—the Linux kernel triggers a “kernel panic”. Under default settings, the kernel halts execution, dumps debug registers to the console, and freezes indefinitely until a system administrator manually power-cycles the machine.
For headless, remote, or collocated servers without instant physical access, this indefinite freeze leads to prolonged downtime. By configuring the kernel’s built-in panic timer via sysctl, you can instruct Ubuntu to wait a brief specified duration and then automatically trigger an immediate hardware reboot.
Step 1: Check the Current Kernel Panic Setting
The kernel panic reboot behaviour is governed by the kernel.panic kernel parameter. To inspect the value currently configured on your system, open your terminal and run:
sysctl kernel.panic
Understanding the returned value:
kernel.panic = 0: Default behaviour. The system hangs indefinitely upon encountering a panic.kernel.panic = <positive integer>: The number of seconds the kernel will wait before automatically issuing a system reboot.kernel.panic = -1: The system will reboot immediately without any delay.
Step 2: Test the Configuration at Runtime
You can temporarily test a 10-second reboot delay without making permanent modifications:
sudo sysctl -w kernel.panic=10
A 10-second delay is optimal because it allows administrators or remote logging consoles enough time to record the kernel backtrace before the machine reboots.
Step 3: Make the Automatic Reboot Configuration Permanent
Settings applied via sysctl -w revert upon the next restart. To ensure your Ubuntu server retains this configuration permanently across all reboots:
- Open the system configuration file in a terminal text editor:
sudo nano /etc/sysctl.d/99-panic-reboot.conf
- Add the following configuration lines:
# Automatically reboot 10 seconds after a kernel panic
kernel.panic = 10
# Automatically panic and reboot if a kernel hang or lockup occurs
kernel.panic_on_oops = 1
- Press Ctrl + O and Enter to save, then press Ctrl + X to exit.
- Apply the newly created configuration file immediately into the active kernel:
sudo sysctl -p /etc/sysctl.d/99-panic-reboot.conf
Your Ubuntu server is now hardened against permanent lockups; whenever a kernel-level panic occurs, the operating system will restart cleanly after 10 seconds, restoring network and application services.