Home » 2015 » March » 23 » FSCK : Checking and reparing filesystems in Linux

10:11 PM
FSCK : Checking and reparing filesystems in Linux

fsck - check and repair a Linux file system

FORMAT
       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.
  • fsck is run on a filesystem which is not currently mounted. Make sure you dont run FSCK on file system which is already mounted.
     
  • During system boot if one of the filesystem has it's filesystem flag in the Superblock set to  "unknown" ,it runs FSCK to check the filesystem inconsistency before mounting.

Note:- While fsck is running, the filesystem is not available to users.


  • If no filesystems are specified on the command line, and the -A option is not specified, fsck will default  to  checking  filesystems  in  /etc/fstab serially.  This is equivalent to the -As options.

 


The exit code returned by fsck is the sum of the following conditions:
            0    - No errors
            1    - File system errors corrected
            2    - System should be rebooted
            4    - File system errors left uncorrected
            8    - Operational error
            16   - Usage or syntax error
            32   - Fsck canceled by user request
            128  - Shared library error

  • The exit code returned when multiple file systems are checked is the bit-wise OR of the exit codes for each file system that is checked.

  • In  actuality, fsck is simply a front-end for the various file system checkers (fsck.fstype) available under Linux. 
  • The file system-specific checkers are present in /sbin, then in /etc/fs and /etc, and finally in the directories listed in the PATH environment variable.

USAGE:
Usage: fsck.ext3 [-panyrcdfvtDFV] [-b superblock] [-B blocksize]
[-I inode_buffer_blocks] [-P process_inode_size]
[-l|-L bad_blocks_file] [-C fd] [-j external_journal]
[-E extended-options] device

Emergency help:
-p      Automatic repair (no questions)
-n     Make no changes to the filesystem
-y     Assume "yes" to all questions
-c     Check for bad blocks and add them to the badblock list
-f     Force checking even if filesystem is marked clean
-v    Be verbose
-b    superblock Use alternative superblock
-B    blocksize Force blocksize when looking for superblock
-j      external_journal Set location of the external journal
-l      bad_blocks_file Add to badblocks list
-L     bad_blocks_file Set badblocks list


Options

-a     Automatically repair the file system without any questions (use this option with caution). 

Note that e2fsck(8) supports -a for backwards compatibility  only.   This option is mapped to e2fsck's -p option which is safe to use, unlike the -a option that some file system checkers support.

This does not require any human interaction. It will autoatically fix the damaged partition.

#>fsck -a /dev/sda1

 -y     Assume "yes" to all questions: For some filesystem-specific checkers, the -y option will cause the fs-specific fsck to always attempt to fix any detected filesystem corruption automatically. 

For example, if we have partition /dev/sda1 which is corrupted,

#>mount /dev/sda1

#>cd myfolder

#>ls -li

206033 ?rwSr-S-wT 16 root root  4096 Aug 21 21:11 Videos
      ? -?????????  ? ?    ?        ?            ? blog

For the two files Videos and blog, the attributes are invalid or unknown. So here, to fix this issue, we can use -y option which will give answer as "yes" to all questions.

#>fsck -y /dev/sda1

Note that not all filesystem-specific checkers implement this option.  In particular fsck.minix(8) and fsck.cramfs(8) does not support the -y option as of this writing.


 -M     Do not check mounted filesystems and return an exit code of 0 for mounted filesystems.

localhost:/dev:>mount|grep /dev/sd*
tmpfs on /dev/shm type tmpfs (rw,mode=1777)
localhost:/dev:>fsck -M /dev/xvda3
fsck from util-linux-ng 2.16
localhost:/dev:>echo $?
0


 -N     Don't execute, just show what would be done.

localhost:/dev:>fsck -N
fsck from util-linux-ng 2.16
[/sbin/fsck.ext3 (1) -- /] fsck.ext3 /dev/xvda3
[/sbin/fsck.ext2 (1) -- /boot] fsck.ext2 /dev/xvda1

 



-T     Don't show the title on startup.

localhost:/dev:>fsck -NT
[/sbin/fsck.ext3 (1) -- /] fsck.ext3 /dev/xvda3
[/sbin/fsck.ext2 (1) -- /boot] fsck.ext2 /dev/xvda1


Please note that the title is something like "fsck from util-linux-ng 2.16"

-V     Produce verbose output, including all file system-specific commands that are executed.


Note: You should never run fsck on a mounted file system otherwise it will create a severe damage. It may format the drive.


localhost:/etc:>fsck -A
fsck from util-linux-ng 2.16
e2fsck 1.41.9 (22-Aug-2009)
/dev/xvda3 is mounted.

WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.

Do you really want to continue (y/n)? no

check aborted.
e2fsck 1.41.9 (22-Aug-2009)
/dev/xvda1 is mounted.  e2fsck: Cannot continue, aborting.


 

 
 

Category: Open System-Linux | Views: 1382 | Added by: shanky | Tags: repairing linux fiesystem, file system check, checking and repair file system, filesystem, linux, fsck | Rating: 0.0/0

Related blogs


You may also like to see:


[2014-10-25][Open System-Linux]
XMLWF command in Linux to check/validate/parse an XML file
[2016-12-11][Open System-Linux]
Some great usage and example of find command in Linux
[2015-06-16][Open System-Linux]
Alien command : convert files from one form to another, install binary packages
[2014-09-13][Open System-Linux]
md5sum: calculate and check md5 message digest of a file in Linux
[2015-06-08][Open System-Linux]
CHAGE command in LINUX

Total comments: 0
avatar