Reboot Linux box after a kernel panic

If you want the server to get rebooted automatically after kernel hit by a pain error message, try adding panic=N to /etc/sysctl.conf file.

ADVERTISEMENTS

It specify kernel behavior on panic. By default, the kernel will not reboot after a panic, but this option will cause a kernel reboot after N seconds. For example following boot parameter will force to reboot Linux after 10 seconds.

Open /etc/sysctl.conf file

# vi /etc/sysctl.conf

When kernel panic’s, reboot after 10 second delay

kernel.panic = 10

Save and close the file. Alternatively, you may want to enable and use magic system request keys (SysRq).

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
4 comments… add one
  • Anonymous Nov 16, 2007 @ 15:47

    Thanks for this tip. My computer had a kernel panic for the first time a couple of weeks ago and I had no choice but to reboot it manually.

  • mangoo Nov 21, 2007 @ 18:36

    One can also add panic=10 to the kernel command line, it will have exactly the same effect.

    Of course, it’s possible to change it later with sysctl, or by writing to /proc:

    echo 10 > /proc/sys/kernel/panic

  • Rene Sep 23, 2009 @ 8:38

    Thanks for this tip! As indicated by mangoo: To take this change effect right now, issue the command
    sysctl -p to re-read the /etc/sysctl.conf
    Otherwise, this change is not active before the next reboot.

  • tsb Jun 20, 2013 @ 22:27

    It’s important to mention that there is another “key” named “panic_on_oops” that should also be defined to some amount of seconds to reboot kernel on an “oops” kind of panic. I had this situation and the console had frozen and not even SYSRQ could restart the machine. The crash dump couldn’t be saved because I had to remove power from device (embedded device without reset button) to restart it and the power off procedure avoids memory to be saved after panic.
    Making “echo 1 > /proc/sys/kernel/panic_on_oops” or “kernel.panic_on_oops=1” on /etc/sysctl.conf solved my problem of restarting after this oops panic.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.