xref: /freebsd/sbin/fsck/fsck.8 (revision afe61c15161c324a7af299a9b8457aba5afc92db)
1.\" Copyright (c) 1980, 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"	@(#)fsck.8	8.2 (Berkeley) 12/11/93
33.\"
34.Dd December 11, 1993
35.Dt FSCK 8
36.Os BSD 4
37.Sh NAME
38.Nm fsck
39.Nd filesystem consistency check and interactive repair
40.Sh SYNOPSIS
41.Nm fsck
42.Fl p
43.Op Fl m Ar mode
44.Nm fsck
45.Op Fl b Ar block#
46.Op Fl c Ar level
47.Op Fl l Ar maxparallel
48.Op Fl y
49.Op Fl n
50.Op Fl m Ar mode
51.Op Ar filesystem
52.Ar ...
53.Sh DESCRIPTION
54The first form of
55.Nm fsck
56preens a standard set of filesystems or the specified filesystems.
57It is normally used in the script
58.Pa /etc/rc
59during automatic reboot.
60Here
61.Nm fsck
62reads the table
63.Pa /etc/fstab
64to determine which filesystems to check.
65Only partitions in fstab that are mounted ``rw,'' ``rq'' or ``ro''
66and that have non-zero pass number are checked.
67Filesystems with pass number 1 (normally just the root filesystem)
68are checked one at a time.
69When pass 1 completes, all remaining filesystems are checked,
70running one process per disk drive.
71The disk drive containing each filesystem is inferred from the longest prefix
72of the device name that ends in a digit; the remaining characters are assumed
73to be the partition designator.
74.Pp
75The kernel takes care that only a restricted class of innocuous filesystem
76inconsistencies can happen unless hardware or software failures intervene.
77These are limited to the following:
78.Bl -item -compact
79.It
80Unreferenced inodes
81.It
82Link counts in inodes too large
83.It
84Missing blocks in the free map
85.It
86Blocks in the free map also in files
87.It
88Counts in the super-block wrong
89.El
90.Pp
91These are the only inconsistencies that
92.Nm fsck
93with the
94.Fl p
95option will correct; if it encounters other inconsistencies, it exits
96with an abnormal return status and an automatic reboot will then fail.
97For each corrected inconsistency one or more lines will be printed
98identifying the filesystem on which the correction will take place,
99and the nature of the correction.  After successfully correcting a filesystem,
100.Nm fsck
101will print the number of files on that filesystem,
102the number of used and free blocks,
103and the percentage of fragmentation.
104.Pp
105If sent a
106.Dv QUIT
107signal,
108.Nm fsck
109will finish the filesystem checks, then exit with an abnormal
110return status that causes an automatic reboot to fail.
111This is useful when you want to finish the filesystem checks during an
112automatic reboot,
113but do not want the machine to come up multiuser after the checks complete.
114.Pp
115Without the
116.Fl p
117option,
118.Nm fsck
119audits and interactively repairs inconsistent conditions for filesystems.
120If the filesystem is inconsistent the operator is prompted for concurrence
121before each correction is attempted.
122It should be noted that some of the corrective actions which are not
123correctable under the
124.Fl p
125option will result in some loss of data.
126The amount and severity of data lost may be determined from the diagnostic
127output.
128The default action for each consistency correction
129is to wait for the operator to respond
130.Li yes
131or
132.Li no .
133If the operator does not have write permission on the filesystem
134.Nm fsck
135will default to a
136.Fl n
137action.
138.Pp
139.Nm Fsck
140has more consistency checks than
141its predecessors
142.Em check , dcheck , fcheck ,
143and
144.Em icheck
145combined.
146.Pp
147The following flags are interpreted by
148.Nm fsck .
149.Bl -tag -width indent
150.It Fl b
151Use the block specified immediately after the flag as
152the super block for the filesystem.  Block 32 is usually
153an alternate super block.
154.It Fl l
155Limit the number of parallel checks to the number specified in the following
156argument.
157By default, the limit is the number of disks, running one process per disk.
158If a smaller limit is given, the disks are checked round-robin, one filesystem
159at a time.
160.It Fl m
161Use the mode specified in octal immediately after the flag as the
162permission bits to use when creating the
163.Pa lost+found
164directory rather than the default 1777.
165In particular, systems that do not wish to have lost files accessible
166by all users on the system should use a more restrictive
167set of permissions such as 700.
168.It Fl y
169Assume a yes response to all questions asked by
170.Nm fsck ;
171this should be used with great caution as this is a free license
172to continue after essentially unlimited trouble has been encountered.
173.It Fl n
174Assume a no response to all questions asked by
175.Nm fsck
176except for
177.Ql CONTINUE? ,
178which is assumed to be affirmative;
179do not open the filesystem for writing.
180.It Fl c
181Convert the filesystem to the specified level.
182Note that the level of a filesystem can only be raised.
183.Bl -tag -width indent
184There are currently three levels defined:
185.It 0
186The filesystem is in the old (static table) format.
187.It 1
188The filesystem is in the new (dynamic table) format.
189.It 2
190The filesystem supports 32-bit uid's and gid's,
191short symbolic links are stored in the inode,
192and directories have an added field showing the file type.
193.El
194.Pp
195In interactive mode,
196.Nm fsck
197will list the conversion to be made
198and ask whether the conversion should be done.
199If a negative answer is given,
200no further operations are done on the filesystem.
201In preen mode,
202the conversion is listed and done if
203possible without user interaction.
204Conversion in preen mode is best used when all the filesystems
205are being converted at once.
206The format of a filesystem can be determined from the
207first line of output from
208.Xr dumpfs 8 .
209.El
210.Pp
211If no filesystems are given to
212.Nm fsck
213then a default list of filesystems is read from
214the file
215.Pa /etc/fstab .
216.Pp
217.Bl -enum -indent indent -compact
218Inconsistencies checked are as follows:
219.It
220Blocks claimed by more than one inode or the free map.
221.It
222Blocks claimed by an inode outside the range of the filesystem.
223.It
224Incorrect link counts.
225.It
226Size checks:
227.Bl -item -indent indent -compact
228.It
229Directory size not a multiple of DIRBLKSIZ.
230.It
231Partially truncated file.
232.El
233.It
234Bad inode format.
235.It
236Blocks not accounted for anywhere.
237.It
238Directory checks:
239.Bl -item -indent indent -compact
240.It
241File pointing to unallocated inode.
242.It
243Inode number out of range.
244.It
245Dot or dot-dot not the first two entries of a directory
246or having the wrong inode number.
247.El
248.It
249Super Block checks:
250.Bl -item -indent indent -compact
251.It
252More blocks for inodes than there are in the filesystem.
253.It
254Bad free block map format.
255.It
256Total free block and/or free inode count incorrect.
257.El
258.El
259.Pp
260Orphaned files and directories (allocated but unreferenced) are,
261with the operator's concurrence, reconnected by
262placing them in the
263.Pa lost+found
264directory.
265The name assigned is the inode number.
266If the
267.Pa lost+found
268directory does not exist, it is created.
269If there is insufficient space its size is increased.
270.Pp
271Because of inconsistencies between the block device and the buffer cache,
272the raw device should always be used.
273.Sh FILES
274.Bl -tag -width /etc/fstab -compact
275.It Pa /etc/fstab
276contains default list of filesystems to check.
277.El
278.Sh DIAGNOSTICS
279The diagnostics produced by
280.Nm fsck
281are fully enumerated and explained in Appendix A of
282.Rs
283.%T "Fsck \- The UNIX File System Check Program"
284.Re
285.Sh SEE ALSO
286.Xr fstab 5 ,
287.Xr fs 5 ,
288.Xr fsdb 8 ,
289.Xr newfs 8 ,
290.Xr mkfs 8 ,
291.Xr reboot 8
292