After patching CentOS 7 Linux OS or installing any hardware driver in server you found CentOS 7 Linux server is not coming up after reboot. It is giving below kernel panic error now as server initramfs got damaged which is one of main reason of kernel panic (however there are multiple reasons of kernel panic like memory issue or hardware issue but these are beyond this topic).
CentOS 7 Linux Kernel Panic screen
Now you have a situation server is in production environment and you can’t take risk of loosing data by rebuilding it from scratch and what happen if server does not have old kernel to boot into it, so question comes in mind how to recover the server without letting data loss and facing huge outage?
Kernel panic is a condition which not only panic the Linux system it panic the System Administrator as well! :- ) Just joking!! There is say No Problem is big if we think it so. Every Problem has a solution! With a adequate knowledge and correct approach we can address this situation on time.
In this tutorial I will demonstrate you how to recover the CentOS 7 Linux initramfs boot image.
But what is initramfs and how it is critical for Linux system in boot process?
During booting initramfs it load in memory and mount the root filesystem, initramfs contains kernel modules and initial scripts which are require for booting Linux system to next stage of booting. The initramfs stay in /boot mount point or directory in image file format associated with installed kernel(s) version: initramfs-.img. Everytime when new kernel install in system new initramfs built. Utility dracut which can be use for managing and rebuilding initramfs in case of initramfs image get damage.
CentOS 7 Linux boot directory
You can see contents of current initramfs in CentOS 7 Linux system with command lsinitrd example below:
You might have noticed in above screenshot it is getting output of current booted kernel initramfs image. It contains combination of commands, system files and directories these are require during booting of system.
Recovery or Rebuild of damaged initramfs boot image
We will use dracut utility as I have mentioned above for recovering damaged initramfs for making CentOS7 Linux system bootable again.
- Reboot the system and boot into rescue kernel image.
- Login with root or sudo user credential.
- You can see from below screenshot existing initramfs file does not have any size visible which is a sign of its damage.
- Execute the below command for rebuilding new initramfs image associated with current kernel version.
# dracut -f /boot/initramfs-3.10.0-693.el7.x86_64.img $(uname -r)
- Post execution of dracut command you can see in below screenshot that initramfs has been rebuilt successfully with visible file size.
Also you can inspect the rebuilt initramfs image which is associated with current kernel version with below command:
# lsinitrd -k $(uname -r)
- Lets reboot the system in normal kernel and check system status:
Voila! CentOS 7 Linux system is up and running fine.
3,532 total views, 8 views today