Table of Contents
In this article I will share step by step tutorial to repair filesystem in rescue mode in RHEL/CentOS 7/8 Linux. It happens many time that our file system on the partition gets corrupted so as a Linux Administrator we have to make sure that the file system is repaired assuming it is in a state to be repaired). But nevertheless we must tru to repair file system.
Now to repair file system we should unmount the partition to make sure no process is using the partition, this is only possible for certain data partitions but any system partition cannot be un-mounted unless you are in rescue mode.
Also it is possible that your Linux node is not reachable so in such cases it becomes mandatory to boot into rescue mode and then perform repair of your file system.
So let us check how we can repair file system in rescue mode. I have verified these steps on RHEL/CentOS 7/8 environment, but the snippets will be from CentOS 8.0 Linux node installed as a Virtual Machine on Oracle Virtualbox.
Step 1: Boot into rescue mode in CentOS/RHEL 7/8 Linux
You can use Live DVD to boot into rescue mode which you had used to install your RHEL/CentOS 7/8 Linux node. Since I have already explained these steps in another article, I will be very brief here:
Install Red Hat Enterprise Linux 8.0.0 Test this media & install Red Hat Enterprise Linux 8.0.0 Troubleshooting <--- Select
On the next screen you will get below list of options
Install Red Hat Enterprise Linux 7.0 in basic graphics mode Rescue a Red Hat Enterprise Linux system <--- Select Run a memory test Boot from local drive Return to main menu
In the next screen press "3" to skip to shell so that we can manually mount required file system
Step 2: Activate partitions (logical volume/raid)
This step can be optional if you do not of raid devices or logical volumes.
If using Software RAID then initialize raid array first
# mdadm --examine --scan # mdadm --assemble --scan
If using LVM, activate the volumes in order to scan them.
# vgchange -ay
Next you can list your logical volumes and volume group using
# lvs <-- To list logical volumes # vgs <-- To list volume groups
Step 3: Repair filesystem in rescue mode
Now since we have our partitions and logical volumes in the rescue mode and since we have not mounted them, they are not in use by system processes. So we can safely repair filesystem in rescue mode at this stage.
To repair ext4 filesystem (logical volumes)
We will use e2fsck to repair ext4 filesystem sitting on top of logical volume
# e2fsck -fv /dev/mapper/<vg>-<lv>
For example: check below image where we repair logical volumes
# e2fsck -fv /dev/mapper/rhel-root
To repair ext4 filesystem (normal partition)
We will again use e2fsck to repair ext4 filesystem sitting on top of normal partition
# e2fsck -fv /dev/<sd device>
For example: check below image where we repair normal partition
# e2fsck -fv /dev/sda1
To repair software raid device
We will use e2fsck to repair ext4 filesystem sitting on top of raid device
For example: check below image where we repair software raid devices
# e2fsck -fv /dev/md0
To repair XFS Filesystem with xfs_repair
Now currently I don't have a XFS filesystem so I cannot show you the output of the steps to repair XFS filesystem. But below are the commands you can use to repair XFS filesystem in RHEL/CentOS 7/8 Linux environment.
# xfs_repair /dev/mapper/<vg>-<lv> or # xfs_repair /dev/<sd device> or # xfs_repair /dev/<md device>
Lastly after you repair filesystem in rescue mode you can now exit the rescue mode and boot the system normally. So, let me know your suggestions and feedback using the comment section.
Related Searches: Repair ext4 filesystem in Linux. How to repair xfs filesystem in RHEL/CentOS 7/8 Linux. How to repair filesystem in rescue mode in red hat enterprise Linux or CentOS 7/8