An operating system user that is still a learner in the OS world can never escape the challenges the current elite users have overcome. The user impact of such challenges depends on the operating system flavor or distribution you are under.
For Linux users, you might think you are facing an impossible challenge only to realize that there are multiple valid solutions for every single OS problem faced.
[ You might also like: How to Backup Linux Filesystem Using dump Command ]
The Linux file system is a maze that most users hesitate to enter. It is because this file system is responsible for the performance consistency of your Linux operating system and any slight modification to its hierarchy or file system structure can be a nightmare for any user.
The FSCK Linux Command
The Linux operating system handles file system issues through the fsck command-line utility. It is a prepackaged file system check toolkit that interactively checks and repairs corrupted files that might affect the performance of your operating system.
$ man fsck
Most of the time, it is these corrupt files that are responsible for failed system boots and partition mounts.
FSCK Command Usage
The standard syntax for fsck command-line utility is as follows:
# fsck [OPTIONS] [FILESYSTEM]
You need to be a sudoer user or have sudo privileges to effectively use the FSCK tool.
FSCK adheres to some predefined rules.
- It references the /etc/fstab file when a user does not provide
[FILESYSTEM]as a command argument.
<pass> column for the
<mount point> (/) and
<type> (ext4) is set to 1 because its file system checks and repair are prioritized.
It is not recommended to use the fsck command with mounted partitions as there is a high likelihood of permanent file system damage.
Repairing A Corrupted Linux File System
The first step is to identify the device partition that holds the Linux file system you would like to check and repair.
$ sudo fdisk -l
The second step is to unmount the device whose file system you want to check and repair. e.g.
$ sudo umount /dev/sda5
The third step is to check and possibly repair the device’s file system using FSCK.
$ sudo fsck -p /dev/sda5
-p command option is for automatic repair without any user intervention.
The final step is to re-mount your device once the fsck file system check and repair is complete.
$ sudo mount /dev/sda5
Repairing Linux File System on Boot-Time
On a running machine, it is not possible to simultaneously check and repair your Linux file system while using the OS. In this case, we have the options of using a live CD/bootable usb drive or checking and repairing the Linux file system on boot (For installed Linux systems).
Linux File System Repair on Boot
1. Restart your machine, press [Esc] or [Shift] and select Advanced Options on the resulting boot menu.
2. Select Recovery Mode and choose the fsck option from the resulting list of menu options.
3. Hit [Enter] and choose the fsck menu option.
4. Choose Yes when asked whether to remount your OS root file system.
5. Once the file system check and repair is complete, direct your system to resume normal boot.
Live CD/USB File System Repair
- Boot into your machine from the live distribution (CD or USB).
- Open the Linux terminal and use
sudo fdisk -lcommand to find the targeted Linux root partition name.
- If the root partition is identified by a name like /dev/sda1, running the following command will check and possibly repair its associated file system.
$ sudo fsck -p /dev/sda1
FSCK is a very effective tool to get you started on understanding the nature and performance of your Linux system. The
man fsck command has more options on using the FSCK utility to check and optionally repair broken or corrupt Linux file systems.