Categories: Disks and Partitions

Linux fsck command (fixes file system) [Basic Guide]

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:

$ ls -l /usr/sbin/ *fsck* 
lrwxrwxrwx 1 root March 8 2019 /usr/sbin/dosfsck -> fsck.fat
-rwxr-xr-x 4 root 256424 Jul 26 2018 /usr/sbin/e2fsck
-rwxr-xr-x 1 root root 49896 Jul 26 2018 /usr/sbin/fsck k
-rwxr-xr-x 1 root root 37200 July 26 2018 /usr/sbin/fsck.cramfs
-rwxr-xr-x 4 root root 256424 July 26 2018 /usr/sbin/fsck.ext2
-rwxr-xr-x 4 root root 256424 Jul 26 2018 /usr/sbin/fsck.ext3 -rwxr-xr-x 4 root root 256424 July 26 2018 /usr/sbin/fsck.ext3
-rwxr-xr-x 4 root 256424 July 26 2018 /usr/sbin/fsck.ext3 sck.ext4
-rwxr-xr-x 1 root root 57424 ago 2 2018 /usr/sbin/fsck.fat
-rwxr-xr-x 1 root root 83536 July 26 2018 /usr/sbin/fsck.minix
lrwxrwx 1 root root March 8 2019 /usr/sbin/fsck.msdos -> fsck.fat lrwxrwxrwx 1 root March 8 2019 /usr/sbin/fsck.msdos -> fsck.fat
lrwxrwxrwx 1 root March 8 2019 /usr/sbin/fsck.vfat fsck.fat

-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:

# fsck /dev/xvdb1 
/dev/xvdb1 is in use.

Once the file system is unmounted:

# fsck.ext4 /dev/xvdb1 e2fsck 1.42.9 (28-Dec-2013) /dev/xvdb1: clean, 41436/524288 files, 374905/2096891 blocks

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:

  1. Use a Linux pendrive to load another Linux and verify the partition;
  2. 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:

$ sudo fsck.ext4 /dev/xvdb1 e2fsck 1.42.9 (28-Dec-2013) /dev/xvdb1: clean, 41436/524288 files, 374905/2096891 blocks

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.