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