The cart is empty

The "Kernel panic - not syncing: VFS: Unable to mount root fs" error is one of the most frustrating errors you may encounter while using CentOS 7. This error typically indicates that the Linux kernel is unable to mount the root filesystem. The reasons can vary from corrupted initramfs files, misconfigured GRUB settings, to hardware issues. In this article, we will discuss several steps to help you fix this error.

Introduction

Before proceeding with any fixes, it's important to understand why this error occurs. The Linux kernel attempts to mount the root filesystem based on instructions in the GRUB configuration file, but if it encounters issues, it fails to complete this process, resulting in the mentioned error.

Step 1: Check GRUB Configuration

The first step is to check if the GRUB configuration is correct. You can do this from the rescue mode or using a live CD/DVD/USB of your distribution.

  1. Boot the system from the live media and open a terminal.
  2. Determine the disk and partition where your root filesystem resides using the fdisk -l command.
  3. Mount the root partition to a directory, for example, using mount /dev/sda1 /mnt, where /dev/sda1 is your root partition.
  4. Change the root directory to this partition using chroot /mnt.
  5. Open and inspect the GRUB configuration file (/etc/default/grub) and ensure it points to the correct device and partition for the root filesystem.

Step 2: Repair and Regenerate initramfs

If the GRUB configuration is fine, the issue may lie with a corrupted or incomplete initramfs. To repair and regenerate it, follow these steps:

  1. Still in the chroot environment, identify the current kernel using uname -r.
  2. Regenerate the initramfs for this kernel using the command dracut -f /boot/initramfs-$(uname -r).img $(uname -r).
  3. After regeneration, regenerate the GRUB configuration again using grub2-mkconfig -o /boot/grub2/grub.cfg.

Step 3: Check Disks and Filesystems

If the previous steps did not resolve the issue, you may have a faulty disk or filesystem.

  1. Perform a disk check using fsck on the root filesystem (e.g., fsck /dev/sda1). Ensure the disk is mounted read-only or disconnected to prevent data corruption.
  2. If fsck finds and repairs any errors, restart the system and check if the issue persists.

 

Fixing the "Kernel panic - not syncing: VFS: Unable to mount root fs" error requires careful diagnosis and may involve several different corrective actions. The key to success is a systematic approach and careful monitoring of system configuration changes. If none of the steps provided lead to a resolution, it's recommended to consult the CentOS community or a system administration expert who may provide further assistance.