Corruption of initramfs can be occur by many ways for example after patching CentOS 7 Linux OS or installing a buggy device driver in server you found CentOS 7 Linux server has become unbootable. You may also encouter below kernel panic error because server initramfs got damaged .
CentOS 7 Linux Kernel Panic screen
Now in such situation specially server which is in production environment could cause outage which canand you can’t take risk of loosing data by rebuilding it from scratch so question comes in mind how to recover the server without letting data loss and facing huge outage?
In this tutorial I will demonstrate you how to recover the CentOS 7 Linux initramfs boot image in such scenario also where server does not have old or previous kernel to boot into it.
What is initramfs and how it is critical for Linux system in boot process?
During Linux booting initramfs load itself 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.
7,090 total views, 16 views today