fsck, dfsck
PURPOSE
Checks file system consistency and interactively repairs
the file system.
SYNOPSIS
fsck [ [ -y -n -p ] [ -S cyl:skip ] [ -f ] [ -t file ] [ -b blocknum ]
[ -d blocknum ] [ -i inum ] [ filesystem ] ]
DESCRIPTION
Warning: Always run fsck on file systems after a system
crash. Corrective actions may result in some loss of
data. The default action for each consistency correction
is to wait for the operator to respond "yes" or "no". If
you do not have write permission for an affected file,
fsck defaults to a "no" response in spite of your actual
response.
The fsck command checks and interactively repairs incon-
sistent filesystems. It should be run on every file
system as part of system initialization (see "rc"). You
must have superuser authority to run fsck. Normally, the
file system is consistent, and fsck merely reports on the
number of files, used blocks and free blocks in the file
system. If the filesystem is inconsistent, fsck displays
information about the inconsistencies found and prompts
you for permission to repair them. fsck is conservative
in its repair efforts and tries to avoid actions that
might result in the loss of valid data. In certain
cases, however, fsck recommends the destruction of a
damaged file.
If you do not specify filesystem, fsck looks at
/etc/filesystems to find a list of file systems to check
by default. fsck can perform checks (on separate arms)
in parallel (running in parallel processes). This can
reduce the time required to check a large number of file
systems.
In /etc/filesystems, automatic checking may be enabled by
adding a line in the stanza, as follows:
check=true
If you specify the -p flag, fsck can perform multiple
checks at the same time. To tell fsck which file systems
are on the same drives change the check specification in
/etc/filesystems as follows:
"check="number
The number tells fsck which group contains a particular
file system. File systems on a single drive are placed
in the same group. Each group is checked in a separate
parallel process. File systems are checked, one at a
time, in the order that they appear in /etc/filesystems.
All "check=true" file systems are in group 1. fsck
attempts to check the root file system before any other
file system regardless of order specified on the command
line or in /etc/filesystems.
The fsck command checks for the following inconsisten-
cies:
o Blocks allocated to multiple files or to a file and
the free list.
o Blocks allocated to a file or on the free list
outside the range allowable block numbers.
o Discrepancies between the number of directory refer-
ences to a file and the link count in the file.
o Size checks:
- Incorrect number of blocks.
- Directory size not 16-byte aligned.
o Bad i-node format.
o Blocks not accounted for anywhere.
o Directory checks:
- File pointing to an i-node that is not allocated.
- I-node number out of range.
- Dot (.) link missing or not pointing to itself.
- Dot dot (..) link missing or not pointing to the
parent directory.
- Files that are not referenced or directories that
are not reachable.
o Superblock checks:
- More than 65535 i-nodes.
- More blocks for i-nodes than there are in the
file system.
o Bad free block list format.
o Total free block and/or free i-node count incorrect.
Orphaned files and directories (those that cannot be
reached) are, if you allow it, reconnected by placing
them in the lost+found subdirectory in the root direc-
tory. The name assigned is the i-node number. The only
restriction is that the directory lost+found must already
exist in the root directory of the file system being
checked and must have empty slots in which entries can be
made (accomplished by copying a number of files to the
directory and then removing them before you run fsck).
If you do not allow fsck to reattach an orphaned file, it
requests permission to destroy the file. When fsck dis-
plays i-node information, the NLTIME environment variable
controls the format of the modification time.
In addition to its messages, fsck records the outcome of
its checks and repairs through its exit value. This exit
value can be any sum of the following conditions:
0 All checked file systems are now ok.
2 fsck was interrupted before it could complete checks
or repairs.
4 fsck changed the mounted file system; the user must
restart the system immediately.
8 The file system contains unrepaired damage.
When the system is being started up normally, fsck runs
with the -p flag from /etc/rc (see "rc"). If fsck
detects and repairs errors on the root or other mounted
file systems, it displays a message on the console and
restarts the system, if possible. If it cannot restart
the system or if it detects errors that it cannot repair,
it displays appropriate messages on the console and
returns an exit value indicating that an immediate
restart is necessary.
Note: All statistics reported by fsck are in 512-byte
blocks, regardless of the actual block size of the file
system being checked. All user specifications should be
specified in 512-byte blocks.
dfsck
The dfsck command lets you simultaneously check two file
systems on two different drives. Use the flaglist1 and
flaglist2 arguments to pass flags and parameters for the
two sets of file systems. Use a - (minus) to separate
the file system groups if you specify flags as part of
the arguments.
The dfsck command permits you to interact with two fsck
commands at once. To aid in this, dfsck displays the
file system name with each message. When responding to a
question from dfsck, you must prefix your response with a
1 or a 2 to indicate whether the answer refers to the
first or second file system group.
Note: Do not use dfsckto check the root file system
(/dev/hd0).
FLAGS
-bblocknum Designates a block as bad. fsck searches for
any files that contain the specified block.
If it finds any such files, it asks permis-
sion to delete them. If it finds no such
files or is told to delete all such files,
the specified block is added to the bad block
list in i-node 1. This keeps the block out
of circulation so that it cannot be allocated
to any user file.
-dblocknum Searches for references to a specified disk
block. Whenever fsck encounters a file that
contains a specified block, it displays the
i-node number and all path names that refer
to it.
-f Performs a fast check. Under normal circum-
stances, the only file systems likely to be
affected by halting the system without shut-
ting down properly are those that were
mounted when the system stopped. the -f flag
tells fsck not to check file systems that
were cleanly unmounted. fsck determines this
by inspecting the s_fmod flag in the file
system superblock. this flag is set whenever
a file system is mounted and cleared when it
is cleanly unmounted. if a file system was
cleanly unmounted, it is unlikely to have any
problems. because most file systems are
cleanly unmounted, not checking those file
systems can reduce the checking time.
-iinum Searches for references to a specified
i-node. Whenever fsck encounters a directory
reference to a specified i-node number, it
displays the full path name of the reference.
-n Assumes a "no" response to all questions
asked by fsck; does not open filesystem for
writing.
-p Does not display messages about minor prob-
lems, but fixes them automatically. This
flag does not grant the wholesale license
that the -y flag does and is useful for per-
forming automatic checks when the system is
to be started normally. You should use this
flag whenever the system is being run auto-
matically as part of the system startup pro-
cedures.
-s[cyl:skip]
Ignores the actual free list and uncondi-
tionally reconstructs a new one. You can
specify an optional interleave specification
with this flag: cyl specifies the number of
blocks per cylinder; skip specifies the
number of blocks to skip. If you do not
specify cyl or skip, fsck uses the interleave
parameters in the superblock. The file
system should be unmounted while this is
done; if this is not possible, be sure that
you are running no programs and that you
perform a system restart immediately after-
wards so that the old copy of the superblock
in memory is not written to disk.
-S[cyl:skip]
Conditionally reconstructs the free list.
This flag is like the -s flag except that the
free list is rebuilt only if there are no
discrepancies discovered in the file system.
Using -S forces a "no" response to all
questions asked by fsck. Use this flag to
force free list reorganization on uncontam-
inated file systems.
-tfile Uses file as a scratch file if fsck cannot
obtain enough memory to keep its tables. If
you do not specify -t and fsck needs a
scratch file, it prompts you for the name of
the scratch file. However, if you have spec-
ified the -p flag, fsck fails. The file
chosen must not be on the file system being
checked. If it is not a special file, it is
removed when fsck ends.
-y Assumes a "yes" response to all questions
asked by fsck. This lets fsck take any
action that it considers necessary. Use this
flag only on severely damaged file systems.
EXAMPLES
1. To check all the default file systems:
fsck
This checks all the file systems marked "check=true"
in /etc/filesystems. This form of the fsck command
asks you for permission before making any changes to
a file system.
2. To fix minor problems with the default file systems
automatically:
fsck -p
3. To check a specific file system:
fsck /dev/hd1
This checks the unmounted file system located on the
"/dev/hd1" device.
4. To simultaneously check two file systems on two dif-
ferent drives:
dfsck -p /dev/hd1 - -p /dev/hd7
This checks both file systems simultaneously, if the
file systems on the devices "/dev/hd1" and "/dev/hd7"
are located on two different drives. You can also
specify the file system names that are found in the
/etc/filesystems file.
FILES
/etc/filesystems Contains default list of file systems
to check.
RELATED INFORMATION
The following commands: "rc," "fsdb," "istat,"
"mkfs," "ncheck," and "shutdown."
The filesystems and fs files in AIX Operating System
Technical Reference.
The discussion of fsck and dfsck in Managing the AIX
Operating System