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