Ict-innovation/LPI/104.2

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.

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.

$ df -h

Filesystem Size Used Avail Use% Mounted on

/dev/hda9 289M 254M 20M 93% /

/dev/hda2 23M 7.5M 14M 35% /boot

none 62M 0 61M 0% /dev/shm

/dev/hda5 1.4G 181M 1.1G 13% /share

/dev/hda7 787M 79M 669M 11% /tmp

/dev/hda3 4.3G 3.4G 813M 81% /usr

/dev/hda6 787M 121M 627M 17% /var

//192.168.123.2/share12G 8.8G 3.7G 71% /mnt/smb

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

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 <fstype> <device>

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

# fsck –t reiserfs /dev/sdb10

# fsck.reiserfs /dev/sdb10

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.

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.

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.