Candidates should be able to properly maintain a Linux filesystem using system utilities. This objective includes manipulating standard filesystems.
Key Knowledge Areas:
The following is a partial list of used files, terms, and utilities:
Resources: Bandel97 ; the man pages for e2fsck , badblocks , dumpe2fs , debugfs and tune2fs .
Good disk maintenance requires periodic disk checks. Your best
, and should be run at least
monthly. Default checks will normally be run after 20 system
reboots, but if your system stays up for weeks or months at a
time, you'll want to force a check from time to time. Your best
bet is performing routine system backups and checking your
directories from time to time.
The frequency of the checks at system reboot can be changed with tune2fs . This utility can also be used to change the mount count, which will prevent the system from having to check all filesystems at the 20th reboot (which can take a long time).
The dumpe2fs utility will provide important information regarding hard disk operating parameters found in the superblock, and badblocks will perform surface checking. Finally, surgical procedures to remove areas grown bad on the disk can be accomplished using debugfs .
Fsck is called automatically at system startup. If the filesystem is marked “not clean” , or the maximum mount count is reached or the time between checks is exceeded, the filesystem is checked. To change the maximum mount count or the time between checks, use tune2fs .
Frequently used options to fsck include:
Walk through the
and try to check all filesystems in one run. This
option is typically used from the /etc/rc system
initialization file, instead of multiple commands for
checking a single filesystem.
The root filesystem will be checked first. After that,
filesystems will be checked in the order specified by
(the sixth) field
value of 0 are
skipped and are not checked at all. If there are
multiple filesystems with the same pass number, fsck
will attempt to check them in parallel, although it will
avoid running multiple filesystem checks on the same
Options which are not understood by fsck are passed to
the filesystem-specific checker. These arguments(=options) must not
arguments, as there is no way for fsck to be able to properly
guess which arguments take options and which don't. Options and
arguments which follow the
are treated as
filesystem-specific options to be passed to the filesystem-specific
The filesystem checker for the ext2 filesystem is called fsck.e2fs or e2fsck . Frequently used options include:
This option does the same thing as the -p option. It is provided for backwards compatibility only; it is suggested that people use -p option whenever possible.
This option causes e2fsck to write completion information to the specified file descriptor so that the progress of the filesystem check can be monitored. This option is typically used by programs which are running e2fsck. If the file descriptor specified is 0, e2fsck will print a completion bar as it goes about its business. This requires that e2fsck is running on a video console or terminal.
Open the filesystem read-only, and assume an answer of “no” to all questions. Allows e2fsck to be used non-interactively. (Note: if the -c, -l, or -L options are specified in addition to the -n option, then the filesystem will be opened read-write, to permit the bad-blocks list to be updated. However, no other changes will be made to the filesystem.)
command is used to create a Linux
filesystem. It can create different types of filesystems by
or by giving
is a front-end for the several
commands. Please read the mkfs man pages and section
the section called “Creating Filesystems”
for more information.
It is also possible to set the
to a specific value. This can be used to
'stagger' the mount counts of the different filesystems, which
ensures that at reboot not all filesystems will be checked at
the same time.
So for a system that contains 5 partitions and is booted approximately once a month you could do the following to stagger the mount counts:
tune2fs -c 5 -C 0
partition1tune2fs -c 5 -C 1
partition2tune2fs -c 5 -C 2
partition3tune2fs -c 5 -C 3
partition4tune2fs -c 5 -C 4
Frequently used options include:
Adjust the maximum mount count between two filesystem checks. If max-mount-counts is 0 then the number of times the filesystem is mounted will be disregarded by e2fsck(8) and the kernel. Staggering the mount-counts at which filesystems are forcibly checked will avoid all filesystems being checked at one time when using journalling filesystems.
You should strongly consider the consequences of disabling mount-count-dependent checking entirely. Bad disk drives, cables, memory and kernel bugs could all corrupt a filesystem without marking the filesystem dirty or in error. If you are using journalling on your filesystem, your filesystem will never be marked dirty, so it will not normally be checked. A filesystem error detected by the kernel will still force an fsck on the next reboot, but it may already be too late to prevent data loss at that point.
It is strongly recommended that either -c (mount-count-dependent) or -i (time-dependent) checking be enabled to force periodic full e2fsck(8) checking of the filesystem. Failure to do so may lead to filesystem corruption due to bad disks, cables or memory or kernel bugs to go unnoticed, until they cause data loss or corruption.
print the blocks which are reserved as bad in the filesystem.
only display the superblock information and not any of the block group descriptor detail information.
badblocks is a Linux utility to check for damaged sectors on a disk drive. It marks these sectors so that they are not used in the future and thus do not cause corruption of data. It is part of the e2fsprogs project.
It is strongly recommended that badblocks not be run directly but it
to be called by using the
write the list of bad blocks to
, you can modify the disk with
direct disk writes. Since this utility is so powerful, you
will normally want to invoke it as read-only until you are
ready to actually make changes and write them to the disk. To
in read-only mode, do not
use any switches. To open in read-write mode, add the
switch. You may also want to include
in the command line the device you wish to work on, as in
, etc. Once it is invoked, you
should see a debugfs prompt.
debugfs -b 1024 -s 8193 /dev/hda1
This means that the superblock at block 8193 will be used and the blocksize is 1024. Note that you have to specify the blocksize when you want to use a different superblock. The information about blocksize and backup superblocks can be found with:
The first command to try after invocation of debugfs , is params to show the mode (read-only or read-write), and the current file system. If you run this command without opening a filesystem, it will almost certainly dump core and exit. Two other commands, open and close , may be of interest when checking more than one filesystem. Close takes no argument, and appropriately enough, it closes the filesystem that is currently open. Open takes the device name as an argument. To see disk statistics from the superblock, the command stats will display the information by group. The command testb checks whether a block is in use. This can be used to test if any data is lost in the blocks marked as “ bad ” by the badblocks command. To get the filename for a block, first use the icheck command to get the inode and then ncheck to get the filename. The best course of action with bad blocks is to mark the block “bad ” and restore the file from backup.
To get a complete list of all commands, see the man page of debugfs or type ? , lr or list_requests .
The debugging tool for the ReiserFS filesystem. It has about the same functionality as debugfs but only for the ReiserFS filesystem.
The tuning tool for the ReiserFS filesystem. It has about the same functionality as tune2fs but only for the ReiserFS filesystem.
mkswap sets up a Linux swap area on a device or in a file. (After creating the swap area, you need to invoke the swapon command to start using it. Usually swap areas are listed in /etc/fstab so that they can be taken into use at boot time by a swapon -a command in some boot script.)
xfs_info shows the filesystem geometry. xfs_info is equivalent to invoking xfs_growfs with the -n option.
xfs_check checks whether an XFS filesystem is consistent. It is normally run only when there is reason to believe that the filesystem has a consistency problem.
xfs_repair repairs corrupt or damaged XFS filesystems. xfs_repair will attempt to find the raw device associated with the specified block device and will use the raw device instead. Regardless, the filesystem to be repaired must be unmounted, otherwise, the resulting filesystem may become inconsistent or corrupt.