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