A corruption in the Linux file system causes the system to boot into emergency mode by default.
The following error message is displayed on boot up
Welcome to emergency mode! After logging in, type “journalctl -xb” to view system log, “systemctl reboot” to reboot, “systemctl default” or ^D to try again to boot into default mode.
Filesystems can be corrupted by
- Hardware Errors
- Media errors are common
- Disks are getting bigger and bigger
- To a much lesser degree, bugs in the filesystem
Filesystems are able to “repair” themselves since they consist of lists, links and reference counts that can be validated
- But not all information is always recovered, inodes that do not have a parent directory is common due to the directory structure being corrupted
The OS shows the following error:
Corruption detected. Unmount and run xfs_repair.
Corruption of in-memory data detected. Shutting down filesystem(s)
Please unmount the filesystem and rectify the problem(s)
Enter lvdisplay. This command would bring up the logical volumes present in the Linux machine, the common logical volumes (assuming no changes have been made) are root, home and swap.
To mount a logical volume the command mount /dev/ol/logical_volume_name needs to be entered.
If a logical volume’s metadata is corrupted, the following error is observed after trying to mount it.
XFS(dm-2) Metadata corruption detected at xfs_inode_buf_verify 0x75/0xd0 [xfs]
For the course of this blog it is assumed that the home logical volume is corrupted, so the error is encountered when the following command is executed
To fix this enter the command
xfs_repair -L /dev/mapper/ol-home
Where ol-home is the default partition created by Logical Volume Manager (LVM) on the home logical volume. To view the list of partitions the command fdisk –l can be used.
The –L option specifies Force Log Zeroing.
Forces xfs_repair to zero the log even if it is dirty (contains metadata changes).
It is important to understand that this option should be used only if data of that partition has been backed up before, using this in a mission-critical environment without prior testing would spell trouble as in certain cases, the inode tree could end up with even more corrupted metadata.
With fresh metadata, the inode tree of the filesystem is rebuilt and the /home directory can now be mounted by using:
The changes in the filesystem can be observed by checking the df-l
Reboot the OS for changes to show effect.