Книга: Fedora™ Unleashed, 2008 edition

Verifying File Integrity in ext3 File Systems with the fsck Utility

Verifying File Integrity in ext3 File Systems with the fsck Utility

You assure file system integrity by using the fsck, or file system check, program — one of five commands in the library that are used to maintain and modify the ext3 file system.

When fsck is run, it performs a sequential analysis of the file system information available in the file system if it detects a directory that cannot be traced back to the root or an undeleted file with a zero link count. It places these directories and files in the /lost+found directory that is created on each physical partition by the file system formatting process. Some blocks are reserved for this and other uses of the super-user. It is possible to reduce this allocation to free additional space for regular users by providing special arguments to the formatting program mke2fs.

To run the fsck command, use the name of the file system as the argument. You must ensure that the file system you want to check is unmounted by using the umount command. If you want to fsck the file system at /dev/hdc, for example, do this:

# fsck /dev/hdc

TIP

If you are logged on as a regular user and su to root using su, you do not inherit root's environment and path, meaning that the preceding command does not work unless you use the full path: /usr/sbin/fsck.

Either type the full path each time, or become root with su -, which causes you to inherit root's environment and path; you have less to type.

The file system state is tracked in the ext3 file systems. A special field in the superblock tells the kernel that, after the file system is mounted read/write, it is marked as not clean; when it is properly unmounted, it is marked as clean. If a file system is not unmounted properly, it could contain corrupt data because all the file data might not have been written to it. (This is what the journaling file systems such as ext3 strive to eliminate.) When the system is booted, this flag is checked and if it is not clean, the program fsck is run. Internally, fsck is actually a wrapper program that runs the appropriate version of fsck for the file system in use: fsck.minix, fsck.ext2, fsck.ext3, fsck.reiserfs, fsck.msdos, or fsck.vfat. If the kernel detects an inconsistency in the superblock field, the file system is marked erroneous, and the file system check is forced even if other indicators suggest that fsck does not need to be run.

By default, the system runs fsck on a file system after a periodic number of reboots, regardless of the status of the clean flag. This behavior is triggered by a mount counter kept in the superblock or after a predetermined amount of time has elapsed since the last reboot (information also kept in the superblock). These parameters can be adjusted through the tune2fs command; this command can also be used to modify how the kernel handles the erroneous flag and, interestingly, the number of blocks reserved for the super-user, also known as root. This latter option is useful on very large or very small disks to make more disk space available to the user.

Оглавление книги


Генерация: 2.905. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз