Ict-innovation/LPI/104.2

= 104.2 Maintain the integrity of filesystems = Candidates should be able to maintain a standard filesystem, as well as the extra data associated with a journalling filesystem.

Key Knowledge Areas


 * Verify the integrity of filesystems.
 * Monitor free space and inodes.
 * Repair simple filesystem problems.

Once a filesystem has been created on your block device you will want to know how to monitor the filesystem and check it for errors, recovering from errors where possible. Fortunately the filesystem provide several command and utilities to aid in this process.

Monitoring Disk Usage
The df (disk free) and disk usage (du) commands can be used to report on the amount of free disk space and query how much space directories and files are using. df works on a device level, as opposed to a directory level.

The df tool shows used and available disk space. By default this is given in blocks of 1K.

The du command will display disk usage. This is done on a per directory basis. du cannot display available space since this information is only available at a device level.

The following command will list the current usage of the /etc directory in human readable units (using the -h switch) and will only print the grand total (using the -s switch):

File System Checking, Repair and Maintenance
As with filesystem monitoring there are numerous tools for maintaining a Linux filesystem which are provided by the creators of the respective filesystem.

If the file system is damaged or corrupt, then the fsck utility should be run against the partition (the minimum requirement is that the file system be unmounted or mounted read-only).

fsck acts as a front that automatically detects the file system type of a partition. Then as with mkfs, the tools fsck.ext2, fsck.ext3 fsck.ext4 or fsck.xfs will be called accordingly to carry out the system check and, if necessary, repair. Since ext3 is the main filesystem type for Linux there is a e2fsck command that only handles this filesystem type. You invoke the filesystem check as follows explicitly specify a file system type with the following syntax:

fsck –t

Example: Checking a reiserfs filesystem on the /dev/sdb10 device:

Ext File System Maintenance utilities

As the extended filesystem is the most widely used and deployed filesystem on Linux, the tools for ext filesystem support are more numerous and comprehensive than for other filesystems.

Ext File System Debug Commands

The debugfs and dumpe2fs are seldom used but can be useful in providing low level information about an ext2, ext3 or ext4 filesystem.

 debugfs [ -b blocksize ] [ -s superblock ] [ -f cmd_file ] [ -R request ] [ -V ] [ [ -w ] [ -c ] [ -i ] [ device ] ] 

The debugfs program is an interactive file system debugger. It can be  used  to examine and change the state of an ext2/3/4 file system.

Once in the debugfs shell, internal commands can then be used to change directory, examine inode data, remove files, create links, dump the ext3 journal logs etc. While this is a very powerful command, it should be used with caution, generally only after the fsck command has failed to make any headway.

dumpe2fs [ -bfhixV ] [ -ob superblock ] [ -oB blocksize ] device 

dumpe2fs prints the super block and block group information for the filesystem present on device.

tune2fs

tune2fs allows you to adjust various filesystem parameters on Linux extended filesystems. The following is a list of the most common parameters used to adjust extended filesystem settings:


 * -c sets the number of times a filesystem will be mounted before a filesystem check is forced. This is usually at next boot but can be run when a filesystem is manually unmounted.
 * -C sets the number of times the filesystem was mounted since it was last checked.
 * -L sets the volume label, this used to be used to uniquely identify hard disk partitions but is being replaced with UUIDs.
 * -i sets the maximum time between filesystem checks. A filesystem check will be forced when either the time expires or the maximum number of mounts has been exceeded, which ever comes first.
 * -j adds journaling to an ext2 filesysem making it an ext3 filesystem.

Running tune2fs -l will print out the current settings for a filesystem.

XFS File System Maintenance Utilities

The tools that come with XFS for filesystem integrity checking are xfs_info and xfs_metadump.

xfs_metdump is a filesystem debugging utility, that dumps xfs filesystem meta-data to a file. The file can then be used to debug the files or as a backup. Later the meta-data can be restored with the xfs_restore utility.

Used files, terms and utilities:* du
 * df
 * fsck
 * e2fsck
 * mke2fs
 * debugfs
 * dumpe2fs
 * tune2fs
 * xfs tools (such as xfs_metadump and xfs_info)

Previous Chapter | Next Chapter