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