Linux Internals

Kernel Panic on a VPS: Causes, kdump and Recovery

By NileVPS Team · Published · 5 min read

اقرأ المقال بالعربي

A kernel panic is the Linux kernel deciding that it can no longer run safely and stopping everything on purpose. Unlike an application crash, there is no process to restart: SSH drops, services vanish and the server either freezes on an error screen or reboots. On a VPS the recovery path is predictable once you know where to look. This guide covers the common causes, how to read the panic message, how to set up kdump so the next crash leaves evidence, and how to get the server booting again.

What actually happens during a panic

The kernel calls its panic() routine when it hits a condition it cannot recover from: corrupted internal structures, a failure to start the first user-space process, or a fatal error inside kernel code. It prints a message and a stack trace to the console, optionally triggers a crash dump, and then halts or reboots depending on the kernel.panic setting. If you want a refresher on what code runs in kernel space and why a bug there is so serious, read what the kernel is.

A related event is an oops: a kernel bug that kills the offending task but leaves the system running. An oops can become a panic if kernel.panic_on_oops=1 is set, which many production setups choose so a damaged kernel does not keep running silently.

Common causes on a VPS

Message on consoleLikely causeFirst move
VFS: Unable to mount root fs on unknown-block(0,0)Missing or broken initramfs after a kernel upgradeBoot the previous kernel, rebuild initramfs
Attempted to kill init!/sbin/init (systemd) crashed or is missing, often a broken root filesystem or bad library updateBoot an older kernel or restore a snapshot, check the root filesystem
Out of memory and no killable processesMemory exhausted with vm.panic_on_oom set, or nothing left to killReview memory limits and workload size
BUG: soft lockup / hard LOCKUP followed by panicA CPU stuck in kernel code; panic on lockup is enabledUpdate the kernel, check third-party modules
Oops then panicDriver or module bug, sometimes out-of-tree modules (DKMS)Remove or rebuild the module, update the kernel

Note that a bad line in /etc/fstab usually drops you into systemd emergency mode rather than panicking. That is a different problem with a gentler fix.

Step 1: read the message from the console

When SSH is gone, open the browser console from your control panel. It shows the server's virtual screen, so a panic that froze the system is still visible there. Copy the first lines of the message, not just the last ones: the line that starts with Kernel panic - not syncing: names the reason, and the call trace below it often names the module involved.

If the server rebooted on its own and came back, look at the previous boot's kernel log:

journalctl -k -b -1 --no-pager | tail -n 100

This only works if the journal is persistent. On systems where it lives in memory, enable persistence:

sudo mkdir -p /var/log/journal
sudo systemctl restart systemd-journald

Step 2: get the server booting again

  1. Pick an older kernel. Reboot from the console and hold Shift (BIOS) or press Esc (UEFI) to reach the GRUB menu. Under "Advanced options" select the previous kernel version.
  2. Rebuild the initramfs once you are in:
# Debian / Ubuntu
sudo update-initramfs -u -k all
sudo update-grub

# RHEL / Rocky / AlmaLinux
sudo dracut -f --regenerate-all
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
  1. Check free space in /boot. A full /boot partition is a classic reason for a half-written initramfs: df -h /boot. Remove old kernels with sudo apt autoremove --purge or sudo dnf remove --oldinstallonly.
  2. Restore a snapshot if the system will not boot with any kernel and you cannot repair it quickly. Taking a snapshot before kernel upgrades makes this a few-minute fix instead of a rebuild.

Step 3: set up kdump for next time

kdump reserves a small region of RAM for a second "capture" kernel. When the main kernel panics, it jumps into the capture kernel, which writes a memory image to disk. That image tells you exactly where the crash happened.

On Debian or Ubuntu:

sudo apt install kdump-tools
# answer "yes" to enable kdump, then reboot so the crashkernel= memory is reserved
sudo reboot
kdump-config show

On RHEL-family systems:

sudo dnf install kexec-tools
sudo kdumpctl reset-crashkernel
sudo systemctl enable --now kdump
sudo reboot

Confirm memory was reserved with cat /sys/kernel/kexec_crash_size (a non-zero value means it worked). Keep in mind the reservation is taken away from normal use, which matters on small plans with 1-2 GB of RAM.

To test, and only on a server you can afford to reboot:

echo 1 | sudo tee /proc/sys/kernel/sysrq
echo c | sudo tee /proc/sysrq-trigger

After the reboot, dumps appear under /var/crash/. Each folder usually contains a dmesg text file you can read right away; deeper analysis with the crash utility needs the matching kernel debug symbols.

Make panics less disruptive

  • Set kernel.panic = 10 in /etc/sysctl.d/99-panic.conf so the server reboots ten seconds after a panic instead of hanging forever.
  • Consider kernel.panic_on_oops = 1 so a damaged kernel does not keep running.
  • Keep at least one known-good older kernel installed.
  • Avoid out-of-tree modules you do not need, and rebuild DKMS modules after each kernel update.
  • Snapshot before major upgrades.

If you want a test server to practice these steps safely, a small plan from our pricing page is enough.

FAQ

Can a kernel panic be caused by my application?

Not directly. Ordinary programs run in user space and cannot crash the kernel by themselves. They can, however, exhaust memory when vm.panic_on_oom is enabled, or trigger a latent bug in a driver or kernel module. The root cause is still inside the kernel or its configuration.

Will I lose data after a kernel panic?

Data already written to disk is normally safe, and journaling filesystems such as ext4 and XFS replay their journal on the next boot. Writes that were still in memory at the moment of the panic can be lost, which is why databases rely on their own durable write settings.

Is kdump worth enabling on a small VPS?

It depends on memory. kdump permanently reserves RAM for the capture kernel, so on a very small plan you may prefer to rely on persistent journal logs and the console output. On servers where an unexplained crash would be costly, the evidence a dump provides is usually worth the reserved memory.

Related guides