Part of Datorkirurgen AB – IT experts across Sweden

Kernel panic after an update? How we rescued a Linux server on AWS with a rescue instance, chroot and dracut, and how you avoid the same fault.

The server that did not come back

It started as a normal update of a web server running Amazon Linux 2023 on AWS. The update went through without error messages, and then we restarted the server. But it never came back. SSH did not respond, and the websites were down. In the AWS console, the system log showed a kernel panic, that is, a state where the Linux kernel stops because it cannot continue.

The screenshots in the article come from that rescue. The first one shows how SSH lost the connection when the server shut down, and then how all new attempts timed out. For the owner of the server, it is an unpleasant situation. Everything seems gone, even though the data in fact remains untouched on the disk. In other words, it is important to work calmly and methodically.

Kernel panic: the server shuts down and no longer responds to SSH after the restart
Kernel panic: the server shuts down and no longer responds to SSH after the restart. A real screenshot from the rescue. Addresses, users and key files are masked.

The cause: a kernel without initramfs

In a kernel panic, the first step is to read the system log in the AWS console. It said that the kernel could not mount the root file system. This therefore often indicates that the initramfs file is missing or broken. That file contains the drivers the kernel needs to find the disk. Without it, the kernel does not know where the operating system is, and therefore it stops.

The update had installed a new kernel, but generating the initramfs had failed without anyone noticing. This can happen if the disk is almost full, if the memory runs out during the installation or if something interrupts the process. In our case, moreover, the server was short of space in /boot. A limited fault, but with serious consequences.

How a missing initramfs leads to kernel panic at restart
How a missing initramfs leads to kernel panic at restart. Do you need help with Linux? Linux Service helps you in Nacka and Södermalm, on site or remotely.

The rescue: a temporary instance and chroot

First, we stopped the broken server and detached its disk. After that, we started a temporary rescue instance in the same zone and attached the disk to it as an extra volume. In this way, we could reach all the files from a working system. We mounted the disk under /mnt/rescue, and in addition we mounted the system directories /dev, /proc and /sys there.

With chroot, we then entered the old installation as if it were running. The listing of /boot confirmed the suspicion: the initramfs for the newest kernel was completely gone. We ran dracut --force for the right kernel version, and after that the file was in place. We also checked that the boot setting pointed to a kernel with a working initramfs.

Rescue after kernel panic with chroot, where the listing of boot shows that initramfs is missing
Rescue after kernel panic with chroot, where the listing of boot shows that initramfs is gone. An example from our work for clients in Stockholm.

Back in operation

When the file was in place, we left chroot and unmounted everything in the right order. Sometimes a volume refuses to unmount because something is still using it, and then a lazy unmount helps. The list of block devices then showed that the rescued disk was free to move. Finally, we attached it back to the original server and started it.

This time, the server came up immediately, and all the websites responded. Altogether, the whole rescue took about an hour. After that, we went through the cause and introduced measures: more disk space, swap, cleaning up old kernels and a fixed check of initramfs before every restart. More about that routine in the article on updating Amazon Linux 2023.

Unmounting and lsblk after the rescue, where the rescued disk is ready to be moved back
Unmounting and lsblk after the rescue, where the rescued disk is ready to be moved back. Linux Service, part of Datorkirurgen AB, helps businesses across Sweden with servers, scripts and databases.

How to avoid the same fault

The most important thing is to check the kernel before a restart. List the kernels, check that initramfs exists for the newest one and see which kernel is selected. In addition, there should be plenty of space on the disk and in /boot before the update starts. Always take a snapshot of the disk first, since it gives a quick way back.

In the cloud, moreover, it is a good idea to practise the rescue routine in advance. If you know how to detach a disk and use chroot, a real crisis becomes considerably less stressful. We are happy to help with an exercise on a test server. See also disk space, journald and swap, which often lie behind this type of fault.

Preventive check of the kernel and initramfs before a restart
Preventive check of the kernel and initramfs before a restart. This is how Linux Service, part of Datorkirurgen AB, works for businesses in Stockholm and remotely.

Contact Linux Service in the event of a kernel panic

Linux Service is part of Datorkirurgen AB and has restored servers for more than 30 years, both in data centres and in the cloud. We provide emergency help with kernel panic, broken updates and servers that do not start. AWS describes the rescue instance method in its documentation for EC2.

Therefore, contact us directly if your server has stopped responding. Do not touch the disk, and do not restart more times than necessary. We take over remotely, rescue data and services and then tell you what happened. Moreover, you receive suggestions on how to avoid the same thing.

Frequently asked questions about kernel panic

Questions about kernel panic

Kernel panic: rescue with chroot

More about prevention and getting help

Website developed by Datorkirurgen AB · Privacy policy