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