I was astonished when I first saw a kernel panic. It was a rollercoaster ride of emotions. First panic, then confusion, and finally laughter. Why does a computer panic? It doesn’t feel emotions. However, I’m certain that many system administrators don’t approach kernel panic with the same humor as I do. It can be very scary and serious. Let’s talk about kernel panic and how to fix it.
What is a Kernel Panic and how can it be avoided?
The “kernel panic” error code may not be the most well-written error code. It is not clear what is happening other than that the kernel is malfunctioning. A kernel panic is not usually related to the kernel. Let’s quickly discuss the Linux boot process so we can understand that.
How does the Linux Boot Process work?
There are several steps involved in the Linux boot process. The BIOS/UEFI takes over when a computer turns on for the first time. The BIOS/UEFI’s job is to check the hardware and make sure that everything is working properly. Next, the priority goes to the bootloader to start the OS on the storage drives.
The MBR is the master boot record. It is created when the BIOS/UEFI passes priority over the bootloader. The MBR is a small partition located at the beginning of a primary storage drive on a computer. The MBR used to contain instructions and information for calling the files required to start the OS.
Learn how to become a security expert with SPOTO’s Cybersecurity Training
Start trainingThe MBR partition is small. It is not large enough for modern OSes to store the entire bootloader required to start the OS. This is especially true for multi-OS environments.
Grub2 is the most popular Linux bootloader today. Major Linux distributions have switched to Grub2 as their default bootloader. Grub2 is a Linux bootloader that can work with all types of hardware, including non-x86 based architectures and filesystems. Because it is too large, it cannot fit into all MBR partitions. The MBR does not call the Grub2 bootloader. It calls another bit of information, which contains the instructions to start Grub2.
The Grub2 bootloader is called by the MBR and mounts a file called either initrd (depending on which Linux OS it is). This file acts as a small virtual hard drive and contains enough files and information for the rest of the bootloader process. After the initrd file has been mounted, it mounts key system partitions such as the root filesystem or the boot partition. The Linux kernel is contained in the boot partition. Once these partitions have been mounted, the initrd files starts loading the Linux kernel. This is when the boot process goes wrong and causes a kernel panic.
The TLDR Version Of Why Kernel Panics Are Happening
Kernel panic is when the initrd cannot mount the root or boot partitions or the Linux kernel fails to load properly. A kernel panic can happen because:
A file system problem or corrupted initrd files may cause the /boot or root system to not be mounted.
The /boot, root filesystem moved locations and the initrd files can’t find them.
The initrd file didn’t reflect the fact that patches or kernel modules had been installed on a system.
Installed patches or kernel modules that cause problems with the computer system.
How do you fix a Kernel Panic?
There are many ways to stop a kernel panic. These methods might differ between Linux distributions. It would be too much to cover all possible solutions to a kernel panic issue. Instead, we will discuss the process of triaging and fixing kernel panic issues.
Fix 1: Have you recently installed updates?
It’s simple to install updates on Linux, but not in ful