xref: /freebsd/sbin/fsck_ffs/fsck_ffs.8 (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1.\"
2.\" Copyright (c) 1980, 1989, 1991, 1993
3.\"	The Regents of the University of California.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\" 3. Neither the name of the University nor the names of its contributors
14.\"    may be used to endorse or promote products derived from this software
15.\"    without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.\"	@(#)fsck.8	8.4 (Berkeley) 5/9/95
30.\"
31.Dd May 3, 2019
32.Dt FSCK_FFS 8
33.Os
34.Sh NAME
35.Nm fsck_ffs ,
36.Nm fsck_ufs
37.Nd file system consistency check and interactive repair
38.Sh SYNOPSIS
39.Nm
40.Op Fl BCdEFfnpRrSyZz
41.Op Fl b Ar block
42.Op Fl c Ar level
43.Op Fl m Ar mode
44.Ar filesystem
45.Ar ...
46.Sh DESCRIPTION
47The specified disk partitions and/or file systems are checked.
48In "preen" or "check clean" mode the clean flag of each file system's
49superblock is examined and only those file systems that are not marked clean
50are checked.
51File systems are marked clean when they are unmounted,
52when they have been mounted read-only, or when
53.Nm
54runs on them successfully.
55If the
56.Fl f
57option is specified, the file systems
58will be checked regardless of the state of their clean flag.
59.Pp
60The kernel takes care that only a restricted class of innocuous file system
61inconsistencies can happen unless hardware or software failures intervene.
62These are limited to the following:
63.Pp
64.Bl -item -compact -offset indent
65.It
66Unreferenced inodes
67.It
68Link counts in inodes too large
69.It
70Missing blocks in the free map
71.It
72Blocks in the free map also in files
73.It
74Counts in the super-block wrong
75.El
76.Pp
77These are the only inconsistencies that
78.Nm
79with the
80.Fl p
81option will correct; if it encounters other inconsistencies, it exits
82with an abnormal return status and an automatic reboot will then fail.
83For each corrected inconsistency one or more lines will be printed
84identifying the file system on which the correction will take place,
85and the nature of the correction.
86After successfully correcting a file system,
87.Nm
88will print the number of files on that file system,
89the number of used and free blocks,
90and the percentage of fragmentation.
91.Pp
92If sent a
93.Dv QUIT
94signal,
95.Nm
96will finish the file system checks, then exit with an abnormal
97return status that causes an automatic reboot to fail.
98This is useful when you want to finish the file system checks during an
99automatic reboot,
100but do not want the machine to come up multiuser after the checks complete.
101.Pp
102If
103.Nm
104receives a
105.Dv SIGINFO
106(see the
107.Dq status
108argument for
109.Xr stty 1 )
110signal, a line will be written to the standard output indicating
111the name of the device currently being checked, the current phase
112number and phase-specific progress information.
113.Pp
114Without the
115.Fl p
116option,
117.Nm
118audits and interactively repairs inconsistent conditions for file systems.
119If the file system is inconsistent the operator is prompted for concurrence
120before each correction is attempted.
121It should be noted that some of the corrective actions which are not
122correctable under the
123.Fl p
124option will result in some loss of data.
125The amount and severity of data lost may be determined from the diagnostic
126output.
127The default action for each consistency correction
128is to wait for the operator to respond
129.Li yes
130or
131.Li no .
132If the operator does not have write permission on the file system
133.Nm
134will default to a
135.Fl n
136action.
137.Pp
138The following flags are interpreted by
139.Nm :
140.Bl -tag -width indent
141.It Fl B
142A check is done on the specified and possibly active file system.
143The set of corrections that can be done is limited to those done
144when running in preen mode (see the
145.Fl p
146flag).
147If unexpected errors are found,
148the file system is marked as needing a foreground check and
149.Nm
150exits without attempting any further cleaning.
151.It Fl b
152Use the block specified immediately after the flag as
153the super block for the file system.
154An alternate super block is usually located at block 32 for UFS1,
155and block 192 for UFS2.
156.Pp
157See the
158.Fl N
159flag of
160.Xr newfs 8 .
161.It Fl C
162Check if file system was dismounted cleanly.
163If so, skip file system checks (like "preen").
164However, if the file system was not cleanly dismounted, do full checks,
165as if
166.Nm
167was invoked without
168.Fl C .
169.It Fl c
170Convert the file system to the specified level.
171Note that the level of a file system can only be raised.
172There are currently four levels defined:
173.Bl -tag -width indent
174.It 0
175The file system is in the old (static table) format.
176.It 1
177The file system is in the new (dynamic table) format.
178.It 2
179The file system supports 32-bit uid's and gid's,
180short symbolic links are stored in the inode,
181and directories have an added field showing the file type.
182.It 3
183If maxcontig is greater than one,
184build the free segment maps to aid in finding contiguous sets of blocks.
185If maxcontig is equal to one, delete any existing segment maps.
186.El
187.Pp
188In interactive mode,
189.Nm
190will list the conversion to be made
191and ask whether the conversion should be done.
192If a negative answer is given,
193no further operations are done on the file system.
194In preen mode,
195the conversion is listed and done if
196possible without user interaction.
197Conversion in preen mode is best used when all the file systems
198are being converted at once.
199The format of a file system can be determined from the
200first line of output from
201.Xr dumpfs 8 .
202.Pp
203This option implies the
204.Fl f
205flag.
206.It Fl d
207Enable debugging messages.
208.It Fl E
209Clear unallocated blocks, notifying the underlying device that they
210are not used and that their contents may be discarded.
211This is useful for filesystems which have been mounted on systems
212without TRIM support, or with TRIM support disabled, as well as
213filesystems which have been copied from one device to another.
214.Pp
215See the
216.Fl E
217and
218.Fl t
219flags of
220.Xr newfs 8 ,
221and
222the
223.Fl t
224flag of
225.Xr tunefs 8 .
226.It Fl F
227Determine whether the file system needs to be cleaned immediately
228in foreground, or if its cleaning can be deferred to background.
229To be eligible for background cleaning it must have been running
230with soft updates, not have been marked as needing a foreground check,
231and be mounted and writable when the background check is to be done.
232If these conditions are met, then
233.Nm
234exits with a zero exit status.
235Otherwise it exits with a non-zero exit status.
236If the file system is clean,
237it will exit with a non-zero exit status so that the clean status
238of the file system can be verified and reported during the foreground
239checks.
240Note that when invoked with the
241.Fl F
242flag, no cleanups are done.
243The only thing that
244.Nm
245does is to determine whether a foreground or background
246check is needed and exit with an appropriate status code.
247.It Fl f
248Force
249.Nm
250to check
251.Sq clean
252file systems when preening.
253.It Fl m
254Use the mode specified in octal immediately after the flag as the
255permission bits to use when creating the
256.Pa lost+found
257directory rather than the default 1777.
258In particular, systems that do not wish to have lost files accessible
259by all users on the system should use a more restrictive
260set of permissions such as 700.
261.It Fl n
262Assume a no response to all questions asked by
263.Nm
264except for
265.Ql CONTINUE? ,
266which is assumed to be affirmative;
267do not open the file system for writing.
268.It Fl p
269Preen file systems (see above).
270.It Fl R
271Instruct fsck_ffs to restart itself if it encounters certain errors that
272warrant another run.
273It will limit itself to a maximum of 10 restarts in a given run in order
274to avoid an endless loop with extremely corrupted filesystems.
275.It Fl r
276Free up excess unused inodes.
277Decreasing the number of preallocated inodes reduces the
278running time of future runs of
279.Nm
280and frees up space that can allocated to files.
281The
282.Fl r
283option is ignored when running in preen mode.
284.It Fl S
285Surrender on error.
286With this flag enabled, a hard error returned on disk i/o will cause
287.Nm
288to abort instead of continuing on and possibly tripping over more i/o errors.
289.It Fl y
290Assume a yes response to all questions asked by
291.Nm ;
292this should be used with great caution as this is a free license
293to continue after essentially unlimited trouble has been encountered.
294.It Fl Z
295Similar to
296.Fl E ,
297but overwrites unused blocks with zeroes.
298If both
299.Fl E
300and
301.Fl Z
302are specified, blocks are first zeroed and then erased.
303.It Fl z
304Clear unused directory space.
305The cleared space includes deleted file names and name padding.
306.El
307.Pp
308Inconsistencies checked are as follows:
309.Pp
310.Bl -enum -compact
311.It
312Blocks claimed by more than one inode or the free map.
313.It
314Blocks claimed by an inode outside the range of the file system.
315.It
316Incorrect link counts.
317.It
318Size checks:
319.Bl -item -offset indent -compact
320.It
321Directory size not a multiple of DIRBLKSIZ.
322.It
323Partially truncated file.
324.El
325.It
326Bad inode format.
327.It
328Blocks not accounted for anywhere.
329.It
330Directory checks:
331.Bl -item -offset indent -compact
332.It
333File pointing to unallocated inode.
334.It
335Inode number out of range.
336.It
337Directories with unallocated blocks (holes).
338.It
339Dot or dot-dot not the first two entries of a directory
340or having the wrong inode number.
341.El
342.It
343Super Block checks:
344.Bl -item -offset indent -compact
345.It
346More blocks for inodes than there are in the file system.
347.It
348Bad free block map format.
349.It
350Total free block and/or free inode count incorrect.
351.El
352.El
353.Pp
354Orphaned files and directories (allocated but unreferenced) are,
355with the operator's concurrence, reconnected by
356placing them in the
357.Pa lost+found
358directory.
359The name assigned is the inode number.
360If the
361.Pa lost+found
362directory does not exist, it is created.
363If there is insufficient space its size is increased.
364.Pp
365The full foreground
366.Nm
367checks for many more problems that may occur after an
368unrecoverable disk write error.
369Thus, it is recommended that you perform foreground
370.Nm
371on your systems periodically and whenever you encounter
372unrecoverable disk write errors or file-system\-related panics.
373.Sh FILES
374.Bl -tag -width /etc/fstab -compact
375.It Pa /etc/fstab
376contains default list of file systems to check.
377.El
378.Sh EXIT STATUS
379.Ex -std
380.Pp
381Specific non-zero exit status values used are:
382.Bl -tag -width indent
383.It 1
384Usage error (missing or invalid command arguments).
385.It 2
386The
387.Fl p
388option was used and a
389.Dv SIGQUIT
390was received, indicating that the system should be returned to single
391user mode after the file system check.
392.It 3
393The file system superblock cannot be read.
394This could indicate that the file system device does not exist or is not yet
395ready.
396.It 4
397A mounted file system was modified; the system should be rebooted.
398.It 5
399The
400.Fl B
401option was used and soft updates are not enabled on the file system.
402.It 6
403The
404.Fl B
405option was used and the kernel lacks needed support.
406.It 7
407The
408.Fl F
409option was used and the file system is clean.
410.It 8
411General error exit.
412.It 16
413The file system could not be completely repaired.
414The file system may be able to be repaired by running
415.Nm
416on the file system again.
417.El
418.Sh DIAGNOSTICS
419The diagnostics produced by
420.Nm
421are fully enumerated and explained in Appendix A of
422.Rs
423.%T "Fsck \- The UNIX File System Check Program"
424.Re
425.Sh SEE ALSO
426.Xr fs 5 ,
427.Xr fstab 5 ,
428.Xr fsck 8 ,
429.Xr fsdb 8 ,
430.Xr newfs 8 ,
431.Xr reboot 8
432.Sh HISTORY
433A
434.Nm fsck
435utility appeared in
436.Bx 4.0 .
437It became
438.Nm
439in
440.Fx 5.0
441with the introduction of the filesystem independent wrapper as
442.Nm fsck .
443