Linux fsck command (fixes file system)
The fsck command on Linux is actually a “wrapper” used to call other commands that are variations of fsck for various types of file systems.
You can see this with the ls command in the /usr/sbin directory:
-rwxr-xr-x 1 root root 433 Jan 24 2019 /usr/sbin/fsck.xfs
Depending on the file system, fsck invokes fsck. something appropriate to handle that file system.
The purpose of fsck is to check and correct the file system for errors. By default, fsck takes over the ext2 file system and, after checking the disk, asks the user if they wish to make the necessary corrections.
As a parameter, fsck accepts a device name (e.g.: /dev/hdc1, /dev/sdb2), a mount point (e.g./, /usr, /home), or a Label (e.g.: label=Root) or a UUID disk identification (e.g.: uuid=8868abf6-88c5-4a83-98b8-bfc24057f7bd).
A UUID is a unique number that identifies a disk, as if it were the “MAC Address of the disks”.
Frequently used options are:
- -A: Checks all the disks specified in the /etc/fstab file;
- -t: Specifies the type of file system that should be checked;
We may still have some options for the ext2 file system:
- -b: Superblock Specifies which superblock fsck will work with;
- -c: Checks bad blocks;
- -f: Forces the file system to be checked even if it appears to be intact;
- -p: Automatically repairs the file system;
- -y: Run fsck in no way interactive, not asking the user any questions;
A superblock is a special area on the disk containing important information about the file system parameters and their current state. Generally, the superblock is copied to various areas on the disk as a backup.
The fsck needs the disc to be disassembled to perform the checks and repairs:
Once the file system is unmounted:
Depending on the size and the numerous repairs that the partition requires, the fsck process can take hours.
To check the root system partition there are two options:
- Use a Linux pendrive to load another Linux and verify the partition;
- Use the “touch /forcefsck” command to create the forcefsck file, which forces Linux to check the root partition when the system boots
e2fsck command
The e2fsck command is used to check the ext2, ext3, and ext4 file system. It is the version of fsck for file systems based on the ext file system.
The options are common to fsck, since fsck invokes it when it comes to ext2, ext3, and ext4 partitions.
Example: