Skip to main content
Engineering LibreTexts

04-D.11.1: File System Management - ext Filesystem Tools

  • Page ID
    26847
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Linux File System Management Tools

    ext Utilities

    e2fsprogs (sometimes called the e2fs programs) is a set of utilities for maintaining the ext2, ext3 and ext4 file systems. Since those file systems are often the default for Linux distributions, it is commonly considered to be essential software.

    Despite what its name might suggest, e2fsprogs works not only with ext2, but also with ext3 and ext4. Although ext3's journaling capability can reduce the need to use e2fsck, it is sometimes still necessary to help protect against kernel bugs or bad hardware.

    This is a list of the more commonly used Linux commands.
    dumpe2fs - which prints superblock and block group information.
    e2fsck - an fsck program that checks for and corrects inconsistencies.
    resize2fs - which can expand and shrink ext2, ext3 and ext4 file systems. On-line support was added in 2006. 
    tune2fs - used to modify file system parameters.

    The dumpe2fs Command

    The dumpe2fs command is used to print the super block and blocks group information for the filesystem present on device.

    • Can be used with ext2/ext3/ext4 filesystem for information.
    • The printed information may be old or inconsistent when it is used with a mounted filesystem.
    • Don’t forget to unmount your partition before using this command. When used with a mounted filesystem, the printed information may be old or inconsistent.

    Syntax:

    dumpe2fs [ OPTIONS] [ -o superblock=superblock ] [ -o blocksize=block-size ] device
    

    Command Options:

    Options Option Meaning
    -b Print the blocks which are reserved as bad in the filesystem.
    -f Force dumpe2fs to display a filesystem even though it may have some filesystem feature flags which dumpe2fs may not understand (and which can cause some of dumpe2fs's display to be suspect).
    -i Display the filesystem data from an image file created by e2image, using device as the pathname to the image file.
    -x Print the detailed group information block numbers in hexadecimal format.

    The command outputs a LOT of information; here is just the first 15 lines of a typical output.

    pbmac@pbmac-server $ dumpe2fs /dev/sda1
    Filesystem volume name:   /
    Last mounted on:          /
    Filesystem UUID:          6e73a278-7609-4612-b1dc-5e7451bb3f0d
    Filesystem magic number:  0xEF53
    Filesystem revision #:    1 (dynamic)
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super 
                              large_file huge_file uninit_bg dir_nlink extra_isize
    Filesystem flags:         signed_directory_hash 
    Default mount options:    user_xattr acl
    Filesystem state:         clean
    Errors behavior:          Continue
    Filesystem OS type:       Linux
    Inode count:              577088
    Block count:              2304000 

    The e2fsck Command

    The e2fsck command is used to check the integrity of the ext2/ext3/ext4 family of file systems. The command checks for correctness and validity of the filesystem. For ext3 and ext4 filesystems that use a journal, if the system has been shut down uncleanly without any errors, normally after replaying the committed transactions in the journal, the file system should be marked as clean. Hence, for filesystems that use journaling, e2fsck will normally replay the journal and exit, unless its superblock indicates that further checking is required.

    Syntax:

    e2fsck [ OPTIONS ] [ -b superblock ] [ -B blocksize ] [ -l|-L bad_blocks_file ] 
    [ -C fd ] [ -j external-journal ] [ -E extended_options ] device
    

    Command Options:

    Options - only a partial listing Option Meaning
    -b superblock Instead of using the normal superblock, use an alternative superblock specified by superblock.
    -B blocksize Normally, e2fsck will search for the superblock at various different block sizes in an attempt to find the appropriate block size.
    -l filename Add the block numbers listed in the file specified by filename to the list of bad blocks.
    -L filename Set the bad blocks list to be the list of blocks specified by filename.
    -c This option causes e2fsck to use badblocks(8) program to do a read-only scan of the device in order to find any bad blocks.
    -C fd This option causes e2fsck to write completion information to the specified file descriptor so that the progress of the filesystem check can be monitored.
    -E extended_options Set e2fsck extended options. Extended options are comma separated, and may take an argument using the equals ('=') sign.
    -j external-journal Set the pathname where the external-journal for this filesystem can be found.

    Note that in general it is not safe to run e2fsck on mounted filesystems. The only exception is if the -n option is specified, and -c, -l, or -L options are not specified. However, even if it is safe to do so, the results printed by e2fsck are not valid if the filesystem is mounted. If e2fsck asks whether or not you should check a filesystem which is mounted, the only correct answer is "no'.' Only experts who really know what they are doing should consider answering this question in any other way.

    The fsck command is a front end to the e2fsck. So, when you run the fsck command it calls the appropriate command for the type of filesystem that is present on the system.

    Note that in general it is not safe to run e2fsck on mounted filesystems as you do not want to make changes to an active filesystem.

    pbmac@pbmac-server $ fsck -n /dev/sda5 
    fsck from util-linux 2.31.1
    e2fsck 1.44.1 (24-Mar-2018)
    Warning!  /dev/sda5 is mounted.
    Warning: skipping journal recovery because doing a read-only filesystem check.
    /var: clean, 422698/5120000 files, 5994387/20480000 blocks
    

    Since this is a live system and the filesystem is mounted we use the -n option to assume an answer of 'no' to all questions (which might attempt to alter the filesystem). Notice the output shows the version of fsck AND e2fsck. On the last line, we see that this filesystem is 'clean.'

    The resize2fs Command

    The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on device. If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel and the file system supports on-line resizing. (Modern Linux 2.6 kernels will support on-line resize for file systems mounted using ext3 and ext4; ext3 file systems will require the use of file systems with the resize_inode feature enabled.)

    Syntax:

    resize2fs [ OPTIONS ] [ -d debug-flags ] [ -S RAID-stride ] device [ size ]
    

    Command Options:

    Options Option Meaning
    -f Forces resize2fs to proceed with the filesystem resize operation, overriding some safety checks which resize2fs normally enforces.
    -F Flush the filesystem device's buffer caches before beginning. Only really useful for doing resize2fs time trials.
    -M Shrink the filesystem to the minimum size.
    -p Prints out a percentage completion bar for each resize2fs operation, so that the user can keep track of what the program is doing.
    -P Print the minimum size of the filesystem and exit.

    The resize2fs program does not manipulate the size of partitions. If you wish to enlarge a filesystem, you must make sure you can expand the size of the underlying partition first.

    pbmac@pbmac-server $ resize2fs /dev/sdb1
    resize2fs 1.44.1 (24-Mar-2018)
    Resizing the filesystem on /dev/sdb1 to 1048576 (4k) blocks.
    The filesystem on /dev/sdb1 is now 1048576 (4k) blocks long.

    The tune2fs Command

    tune2fs allows the system administrator to adjust various tunable filesystem parameters on Linux ext2, ext3, or ext4 filesystems. The current values of these options can be displayed by using the -l option to tune2fs program, or by using the dumpe2fs program.

    Syntax:

    tune2fs [OPTIONS] device

    Command Options:

    Options Option Meaning
    -c max-mount-counts Adjust the number of mounts after which the filesystem will be checked by e2fsck.
    -C mount-count Set the number of times the filesystem has been mounted.
    -i interval-between-checks[d|m|w] Adjust the maximal time between two filesystem checks.
    -r reserved-blocks-count Set the number of reserved filesystem blocks.

    Superblocks

    In many of the descriptions in this section we have used the word 'superblock'. The first block in the cylinder group is a superblock, which contains the metadata that defines the other filesystem structures and locates them on the physical disk. Some of the additional groups in the partition will have backup superblocks, but not all. A damaged superblock can be replaced by using a disk utility such as dd to copy the contents of a backup superblock to the primary superblock. It does not happen often.

    The image to the right shows the structure of a cylinder group in the EXT filesystems.

    structure of a cylinder group in the EXT filesystems: first there is the Superblock, then the Group Descriptor, the Reserved Group Descriptor Blocks, the Block bitmap, Inode bitmap, the Inode Table, and then the data blocks
    Figure \(\PageIndex{1}\): The structure of a cylinder group in the EXT filesystems. ("The structure of a cylinder group in the EXT filesystems" by David BothOpenSource.com is licensed under CC BY-SA 4.0)

    The fsck Command

    Linux runs fsck automatically at startup on partitions that are marked for this in /etc/fstab, which is the file containing information about the filesystems that are permanently mounted on the system. The normal behavior is to perform just a quick cursory examination of a partition if it’s been unmounted cleanly. Despite this operation, the Linux boot process isn’t delayed because of a filesystem check unless the system wasn’t shut down properly. If a filesystem is marked unclean for some reason, that means a lengthy check of the filesystem is probably required.

    NOTE: fsck is basically a front end to a variety of file system checking tools. It will determine the appropriate tools to use in order to properly run a file system check on a given files system.

    Syntax:

    fsck [OPTIONS...] [ARGUMENTS...]

    When errors are detected on the filesystems, most of the time the fsck command needs your authorization in order to perform any modification on the filesystem. So it will ask you questions every time it finds an error and will try to modify it.

    There are numerous options for the fsck command. Since this command has a lot of power and can possibly alter the disk configuration, make sure you consult the man page and that you are confident in what you are doing.

    Adapted from:
    "An introduction to Linux's EXT4 filesystem" by David Roth, OpenSource.com is licensed under CC BY-SA 4.0
    "How to Use fsck Command in Linux" by Alain Francois, LinoXide is licensed under CC BY 3.0


    04-D.11.1: File System Management - ext Filesystem Tools is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?