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.
The <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
The -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 -l
command 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.
I use a usb drive with “Parted Magic” or a live OS with “GParted” on it to check and repair filesystems. I find the terminal a bit dangerous for myself. With a GUI I know exactly what disk I am repairing.
@James,
GUI is always best for newbies, but when you are working on servers without GUI, here fsck plays important role in checking and repairing file systems for errors…
Does that work on NTFS file systems? How about FAT32, EXTFAT, FAT16, BTRFS, ZFS, or ReiserFS-4? What file systems does it NOT work for, if any?
What things will it fix, and what will it NOT fix?
This article leaves a LOT of questions unanswered!
@William,
The fsck utility supports all the Unix file systems. If you have NTFSProgs installed, you could be able to perform fsck on the NTFS file system as well…
The fsck tool is used to fix potential system errors and generate reports.
Probably worth mentioning that (I think) fsck does not exist for Btrfs and ZFS filesystems.
@Bill,
There is an fsck.btrfs tool that is used to check the consistency of a btrfs filesystem, and optionally repairs them…
For ZFS, it really does not need an fsck tool because the data on the disk is always perfect. If you still need fsck equivalent for ZFS there is a tool called fsck.zfs.
Creating ‘forcefsck‘ empty file at the root of a block device not working?
After reboot, the system will check the file system on the block device mounted on
'/'
before mounting.@Mikhail,
Thanks for the tip, I will check and see whether it works or not…