fsck - Unix, Linux Command



NAME

fsck - check and repair a Linux file system

SYNOPSIS

fsck [-sAVRTMNP] [-C [fd]] [-t fstype] [filesys...] [--] [fs-specific-options]

DESCRIPTION

fsck is used to check and optionally repair one or more Linux file systems. filesys can be a device name (e.g. /dev/hdc1, /dev/sdb2), a mount point (e.g. /, /usr, /home), or an ext2 label or UUID specifier (e.g. UUID=8868abf6-88c5-4a83-98b8-bfc24057f7bd or LABEL=root). Normally, the fsck program will try to handle filesystems on different physical disk drives in parallel to reduce the total amount of time needed to check all of the filesystems.

OPTIONS

TAG DESCRIPTION
-s Serialize fsck operations. This is a good idea if you are checking multiple filesystems and the checkers are in an interactive mode. (Note: e2fsck(8) runs in an interactive mode by default. To make e2fsck(8) run in a non-interactive mode, you must either specify the -p or -a option, if you wish for errors to be corrected automatically, or the -n option if you do not.)
-t fslist Specifies the type(s) of file system to be checked. When the -A flag is specified, only filesystems that match fslist are checked. The fslist parameter is a comma-separated list of filesystems and options specifiers. All of the filesystems in this comma-separated list may be prefixed by a negation operator 'no' or '!', which requests that only those filesystems not listed in fslist will be checked. If all of the filesystems in fslist are not prefixed by a negation operator, then only those filesystems listed in fslist will be checked.
-A Walk through the /etc/fstab file and try to check all file systems in one run. This option is typically used from the /etc/rc system initialization file, instead of multiple commands for checking a single file system.
-C [ "fd" ] Display completion/progress bars for those filesystem checkers (currently only for ext2 and ext3) which support them. Fsck will manage the filesystem checkers so that only one of them will display a progress bar at a time. GUI front-ends may specify a file descriptor fd, in which case the progress bar information will be sent to that file descriptor.
-M Do not check mounted filesystems and return an exit code of 0 for mounted filesystems.
-N Don't execute, just show what would be done
-P When the -A flag is set, check the root filesystem in parallel with the other filesystems. This is not the safest thing in the world to do, since if the root filesystem is in doubt things like the e2fsck(8) executable might be corrupted! This option is mainly provided for those sysadmins who don't want to repartition the root filesystem to be small and compact (which is really the right solution).
-R When checking all file systems with the -A flag, skip the root file system (in case it's already mounted read-write).
-T Don't show the title on startup
-V Produce verbose output, including all file system-specific commands that are executed.

EXAMPLES

Example-1:

To Filesystem Check on a Disk Partition:

# fsck /dev/sda6

output:

fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
/dev/sda6: clean, 95/2240224 files, 3793506/4476416 blocks
 
Example-2:
 
To check all filesystems in one run, use option -A, ( to exclude root filesystem use -R option )
 
# fsck -AR
 
output:
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
/dev/sda6: clean, 95/2240224 files, 3793506/4476416 blocks
dosfsck 3.0.12, 29 Oct 2011, FAT32, LFN
/dev/sda7: 8 files, 50/1463400 clusters
Example-3:
 
To Check Only a Specific Filesystem Type using Option -t
 
# fsck -AR -t ext2 -y
output:
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
/dev/sda6: clean, 11/2240224 files, 70327/4476416 blocks

Example-4:

Don’t execute Fsck on Mounted Filesystem using Option -M

# mount | grep "/dev/sd*"
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
/dev/sda6 on /mydata type ext2 (rw)
/dev/sda7 on /backup type vfat (rw)
# fsck -M /dev/sda7  

(note: fsck will simply exit with the exit code 0)

output: # echo $? 0

Example-5:

Skip the Display Title using Option -T

# fsck -TAR

output:
e2fsck 1.42.9 (4-Feb-2014)
/dev/sda6: clean, 11/2240224 files, 70327/4476416 blocks
note: title 'fsck from util-linux 2.20.1 ' is skipped in the output.
 
Example-6:

Force a Filesystem Check Even if it’s Clean using Option -f

# fsck /dev/sda6
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014) 
/dev/sda6: clean, 95/2240224 files, 3793503/4476416 blocks

# fsck /dev/sda6 -f

output:
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda6: 95/2240224 files (7.4% non-contiguous), 3793503/4476416 blocks

Example-7:

Attempt to Fix Detected Problems Automatically using Option -y

# fsck -y /dev/sda6

output:
fsck from util-linux 2.20.1 e2fsck 1.42.9 (4-Feb-2014) /dev/sda6 contains a file system with errors, check forced. Pass 1: Checking inodes, blocks, and sizes Inode 2060353 is a unknown file type with mode 0137642 but it looks like it is really a directory. Fix? yes Pass 2: Checking directory structure Entry 'test' in / (2) has deleted/unused inode 49059. Clear? yes Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sda6: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sda6: 96/2240224 files (7.3% non-contiguous), 3793508/4476416 blocks
Example-7:
 
Avoid Repair, but Report Problems to Stdout using Option -n
 
# fsck -n /dev/sda6
output:
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
/dev/sda6 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Inode 2060353 is a unknown file type with mode 0173 but it looks 
like it is really a directory.
Fix? no
Inode 2060353, i_blocks is 8, should be 0.  Fix? no

Pass 2: Checking directory structure
Inode 2060353 (/Movies) has invalid mode (0173).
Clear? no

Inode 49057 (/fwh) has invalid mode (013).
Clear? no

Entry 'fwh' in / (2) has an incorrect filetype (was 1, should be 0).
Fix? no

Pass 3: Checking directory connectivity
Unconnected directory inode 65409 (???)
Connect to /lost+found? no

'..' in ... (65409) is ??? (2060353), should be  (0).
Fix? no

Unconnected directory inode 2076736 (???)
Connect to /lost+found? no

Pass 4: Checking reference counts
Inode 2 ref count is 4, should be 3.  Fix? no

Inode 65409 ref count is 3, should be 2.  Fix? no

Inode 2060353 ref count is 16, should be 15.  Fix? no

Unattached inode 2060354
Connect to /lost+found? no

Pass 5: Checking group summary information
Block bitmap differences:  -(164356--164357) -4149248
Fix? no

Directories count wrong for group #126 (1, counted=0).
Fix? no

/dev/sda6: ********** WARNING: Filesystem still has errors **********

/dev/sda6: 96/2240224 files (7.3% non-contiguous), 3793508/4476416 blocks
Print
Advertisements