Fsck

From TheBestLinux.com
Revision as of 18:44, 29 July 2021 by Jamie (talk | contribs)
Jump to navigation Jump to search

FSCK stands for File System ChecK, and does exactly that, checks a filesystem! This is one of the many beauties of Linux, in that most of the time, you can figure out what a command does by it's name, though that's definitely NOT always the case!

As there are many types of file systems on many operating systems, including Linux, there are many variations of fsck to support many different filesystems types, and a quick way to see which files systems are supported by the current Linux system you happen to be logged into right now, by typing this(note the DOT after "fsck."!) and then tapping the TAB key twice:

[jamie@fc33hw01.dawgland.com:~]$ fsck.
fsck.btrfs   fsck.ext2    fsck.ext4    fsck.hfs     fsck.msdos   fsck.vfat
fsck.cramfs  fsck.ext3    fsck.fat     fsck.minix   fsck.ntfs    fsck.xfs
[jamie@fc33hw01.dawgland.com:~]$ fsck.


As you can see, not only do my particular fsck packages installed support the most common and current Linux filesystems, EXT2, EXT3, EXT4, BTRFS and XFS.

Also, as you can see, Microsoft filesystems MSDOS, FAT, VFAT and NTFS are supported as well.

HFS is short for Hierarchical File System, and is used on MAC's.

CramFS is mostly used on embedded systems & Minix is used on the Minix operating system, and designed to be more UNIX-like.

Each fsck command has different switches and arguments. To see how to use a particular fsck tool, just type the entire fsck.xxx command by itself and hit the ENTER key, and it should give you the "Usage" page.

For instance, if you want to find out how to use the EXT4 filesystem, just type the command without any arguments or switches:

[jamie@fc33hw01.dawgland.com:~]$ fsck.ext4


This should produce the following usage output:

Usage: fsck.ext4 [-panyrcdfktvDFV] [-b superblock] [-B blocksize]
		[-l|-L bad_blocks_file] [-C fd] [-j external_journal]
		[-E extended-options] [-z undo_file] 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
 -z undo_file         Create an undo file
[jamie@fc33hw01.dawgland.com:~]$


Other fsck tools point you to a different location to get the usage page. For instance, here is what the fsck.btrfs command on a bland line by itself does:

[jamie@fc33hw01.dawgland.com:~]$ fsck.btrfs 
If you wish to check the consistency of a BTRFS filesystem or
repair a damaged filesystem, see btrfs(8) subcommand 'check'.
[jamie@fc33hw01.dawgland.com:~]$


Years of experience and the above hint indicating to see the 'check' subcommand tell me to type this command to get the usage for fsck.btrfs:

[jamie@fc33hw01.dawgland.com:~]$ btrfs check --help


Which produces the following usage output I am looking for:

[jamie@fc33hw01.dawgland.com:~]$ btrfs check --help
usage: btrfs check [options] <device>

    Check structural integrity of a filesystem (unmounted).

    Check structural integrity of an unmounted filesystem. Verify internal
    trees' consistency and item connectivity. In the repair mode try to
    fix the problems found. 
    WARNING: the repair mode is considered dangerous and should not be used
             without prior analysis of problems found on the filesystem.
    Options:
      starting point selection:
           -s|--super <superblock>     use this superblock copy
           -b|--backup                 use the first valid backup root copy
           -r|--tree-root <bytenr>     use the given bytenr for the tree root
           --chunk-root <bytenr>       use the given bytenr for the chunk tree root
      operation modes:
           --readonly                  run in read-only mode (default)
           --repair                    try to repair the filesystem
           --force                     skip mount checks, repair is not possible
           --mode <MODE>               allows choice of memory/IO trade-offs
                                       where MODE is one of:
                                       original - read inodes and extents to memory (requires
                                                  more memory, does less IO)
                                       lowmem   - try to use less memory but read blocks again
                                                  when needed (experimental)
      repair options:
           --init-csum-tree            create a new CRC tree
           --init-extent-tree          create a new extent tree
           --clear-space-cache v1|v2   clear space cache for v1 or v2
           --clear-ino-cache 	    clear ino cache leftover items
      check and reporting options:
           --check-data-csum           verify checksums of data blocks
           -Q|--qgroup-report          print a report on qgroup consistency
           -E|--subvol-extents <subvolid>
                                       print subvolume extents and sharing state
           -p|--progress               indicate progress

[jamie@fc33hw01.dawgland.com:~]$