The best tool for maintaining file systems is fsck, which checks and repairs Linux file systems. By default, fsck runs after 20 system reboots but should be run manually if your system runs for weeks or months with rebooting. The frequency of file system checks is changed by using the tune2fs command. Other utilities for performing file system maintenance include dumpe2fs and debugfs. The dumpe2fs utility prints the super block and blocks group information for the file system on the specified device. The debugfs utility is an interactive file system debugger.

 

Using the fsck Command

 

The fsck command accepts a device name, a mount point, a UUID, or a file system label as an argument. If no argument is given, fsck checks all file systems listed in /etc/fstab. Do not run fsck on mounted file systems, because it causes severe file system damage. To unmount the file system and run the fsck utility on /dev/xvdd1:

# umount /dev/xvdd1 

 

# fsck /dev/xvdd1
fsck from util-linux 2.23.2
E2fsck 1.42.9 )28-Dec-2013)
Test: clean, 11/65536 files, 8859/262139 blocks 

 

Notice that the fsck utility calls the e2fsck utility to check the file system. File system–specific commands are located in /sbin:

 # ls -l /sbin/*fsck*
lrwxrwxrwx. 1 root root      5 Sep 16  2017 /sbin/btrfsck -> btrfs
lrwxrwxrwx. 1 root root      8 Jan  7  2015 /sbin/dosfsck -> fsck.fat
-rwxr-xr-x. 4 root root 256368 Aug  3  2017 /sbin/e2fsck
-rwxr-xr-x. 1 root root  32880 Dec  1 23:28 /sbin/fsck
-rwxr-xr-x. 1 root root   1185 Aug  6  2017 /sbin/fsck.btrfs
-rwxr-xr-x. 1 root root  20032 Dec  1 23:28 /sbin/fsck.cramfs
-rwxr-xr-x. 4 root root 256368 Aug  3  2017 /sbin/fsck.ext2
-rwxr-xr-x. 4 root root 256368 Aug  3  2017 /sbin/fsck.ext3
-rwxr-xr-x. 4 root root 256368 Aug  3  2017 /sbin/fsck.ext4
-rwxr-xr-x. 1 root root  57496 Jun 10  2014 /sbin/fsck.fat
-rwxr-xr-x. 1 root root  75080 Dec  1 23:28 /sbin/fsck.minix
lrwxrwxrwx. 1 root root      8 Jan  7  2015 /sbin/fsck.msdos -> fsck.fat
lrwxrwxrwx. 1 root root      8 Jan  7  2015 /sbin/fsck.vfat -> fsck.fat
-rwxr-xr-x. 1 root root    433 Aug  4  2017 /sbin/fsck.xfs

 

If the file system is corrupted, you are prompted to respond to a series of questions during repair attempts. You can include the –y option to use “yes” as an answer to all questions. Additional options to fsck are given:

 

-s: Serialize fsck operations. This is a good idea if you are checking multiple file systems and the checkers are in an interactive mode.

-A: Walk through the /etc/fstab file and try to check all file systems in one run. This option is typically used from the /etc/rc system initialization file. The root file system is checked first. After that, file systems are checked in the order specified by the sixth field in the /etc/fstab file. File systems with a value of 0 in this field are skipped and are not checked.

-R: When checking all file systems with the –A flag, skip the root file system (in case it is already mounted read-write).

 

Using tune2fs

 

The tune2fs utility is mainly used to set file system check options, and to convert an ext2 file system to ext3. You should always use the e2fsck utility before and after using tune2fs. To convert an ext2 file system to ext3, enter:

# tune2fs -j block_device 

 

The block_device argument contains the ext2 file system that you want to convert. The –j option adds an ext3 journal to the file system. The most commonly used options to tune2fs are:

 

  • -c max-mount-counts: Adjust the maximum mount count between two file system checks.
  • -C mount-count: Set the number of times the file system has been mounted.
  • -i interval-between-checks[d|m|w]: Adjust the maximum time between two file system checks.
  • -m reserved-blocks-percentage: Set the percentage of reserved file system blocks.
  • -r reserved-blocks-count: Set the number of reserved file system blocks.

 

Use the tune2fs command to adjust various tunable file system parameters on ext2, ext3, and ext4 file systems. Current values are displayed by using the -l option. Example:

# tune2fs –l /dev/xvda1 

 

Alternatively, use the dumpe2fs command to display file system parameters:

# dumpe2fs /dev/xvda1

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)