Linux 101 : Repairing a filesystem



To check a filesystem with the "fsck" tool, we need to unmount it.
To see the "mounted" filesystems on a Linux machine, we use the below command:


We could then unmount a specific filesystem using the command:


"XXX" represents the partition name - sda1, sdb2, ... -.

For example, we have a "/dir-1" directory on the "/dev/sda2" partition, to check it and repair the files in this filesystem including the "/dir-1" directory, we use the following command:


  • -y : it assumes a "yes" answer, when the command asks us whether we want to repair errors.
  • -C : gives us a visual cue as to the progress of the scan.
Superblocks:

The superblock holds information about the filesystem, its blocks, its inodes, ...

Sometimes the superblock gets damaged and because it holds important information about the filesystem, the filesystems creates backups of the superblocks

We could tell the "fsck" tool to use one of these "backup" superblocks to repair a damaged one. 

To know the location of these "backupsuperblocks, we use the below command:


The "dumpe2fs" command displays the superblock information for the filesystem present on the specified partition/device.

We can pick one superblock backup and use it to restore the damaged one as below:


  • -f : we use it to force the system to check the filesystem even if it seems "healthy".
  • -b : tells the "e2fsck" command to use a different superblock specified by its location when the primary superblock gets corrupted. 

Remark:

Below are the different locations of the backup superblocks based on the filesystem bloc size:
  • Filesystems with 1k blocksizes, location is at 8193.
  • Filesystems with 2k blocksizes, location is at 16384.
  • Filesystems with 4k blocksizes, location is at 32768.
We can determine the block size of a filesystem using the below command - for example for the filesystem on the "/dev/sda2" device - :

Comments

Leave as a comment:

Archive