E2FSCK(8)

๐ŸŒธ E2FSCK(8) ๐ŸŒธ โ€” the System Manager's Manual page, but make it make sense

okay bestie, gather round ๐Ÿ’– you're reading e2fsck, section 8 of the manual, and I'm gonna walk you through it like we're texting at 2am. no cap, every single detail is staying in here.


โœจ NAME โœจ

e2fsck โ€” check a Linux ext2/ext3/ext4 file system ๐Ÿฆ‹


โœจ SYNOPSIS โœจ

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

โœจ DESCRIPTION โœจ

so e2fsck is the girl who checks up on the ext2/ext3/ext4 family of file systems. that's her whole job. ๐Ÿ’…

for ext3 and ext4 file systems that use a journal โ€” if the system got shut down uncleanly but with no errors, then normally, after replaying the committed transactions in the journal, the file system should be marked as clean. so basically, for file systems that use journaling, e2fsck will normally just replay the journal and dip out โ€” unless its superblock is like "hmm actually we need more checking." ๐Ÿ™ˆ

device is a block device (e.g., /dev/sdc1) or a file containing the file system.

โš ๏ธ okay this part is IMPORTANT, like genuinely. in general it is not safe to run e2fsck on mounted file systems. the only exception is if the -n option is specified, and -c, -l, or -L options are not specified. but even if it is safe to do so, the results printed by e2fsck are not valid if the file system is mounted. if e2fsck asks whether or not you should check a file system which is mounted, the only correct answer is ``no''. only experts who really know what they're doing should even consider answering that question any other way. like, i'm not joking. ๐Ÿซถ

if e2fsck is run in interactive mode (meaning that none of -y, -n, or -p are specified), the program will ask the user to fix each problem found in the file system. here's the vibe check on the responses:

  • a response of 'y' will fix the error ๐Ÿฉน
  • 'n' will leave the error unfixed ๐Ÿ™ƒ
  • 'a' will fix the problem and all subsequent problems ๐Ÿ‘‘

and pressing Enter will proceed with the default response, which is printed before the question mark. pressing Control-C terminates e2fsck immediately. ๐Ÿ’€


โœจ OPTIONS โœจ

  • -a โ€” this option does the same thing as the -p option. it's provided for backwards compatibility only; it is suggested that people use the -p option whenever possible. she's legacy, she's nostalgic, she's fine ๐ŸŒธ
  • -b superblock โ€” instead of using the normal superblock, use an alternative superblock specified by superblock. this option is normally used when the primary superblock has been corrupted. ๐Ÿ˜ญ the location of backup superblocks is dependent on the file system's blocksize, the number of blocks per group, and features such as sparse_super.

additional backup superblocks can be determined by using the mke2fs program using the -n option to print out where the superblocks exist, supposing mke2fs is supplied with arguments that are consistent with the file system's layout (e.g. blocksize, blocks per group, sparse_super, etc.).

if an alternative superblock is specified and the file system is not opened read-only, e2fsck will make sure that the primary superblock is updated appropriately upon completion of the file system check. โœจ

  • -B blocksize โ€” normally, e2fsck will search for the superblock at various different block sizes in an attempt to find the appropriate block size. this search can be fooled in some cases ๐Ÿ™ˆ. this option forces e2fsck to only try locating the superblock at a particular blocksize. if the superblock is not found, e2fsck will terminate with a fatal error. ๐Ÿ’€
  • -c โ€” this option causes e2fsck to use the badblocks(8) program to do a read-only scan of the device in order to find any bad blocks. if any bad blocks are found, they are added to the bad block inode to prevent them from being allocated to a file or directory. and if this option is specified twice, then the bad block scan will be done using a non-destructive read-write test. ๐Ÿ”ฅ
  • -C fd โ€” this option causes e2fsck to write completion information to the specified file descriptor so that the progress of the file system check can be monitored. this option is typically used by programs which are running e2fsck. if the file descriptor number is negative, then the absolute value of the file descriptor will be used, and the progress information will be suppressed initially โ€” it can later be enabled by sending the e2fsck process a SIGUSR1 signal. if the file descriptor specified is 0, e2fsck will print a completion bar as it goes about its business. this requires that e2fsck is running on a video console or terminal. ๐Ÿ“Š
  • -d โ€” print debugging output (useless unless you are debugging e2fsck). ๐Ÿ’€ literally useless for the rest of us
  • -D โ€” optimize directories in file system. this option causes e2fsck to try to optimize all directories, either by re-indexing them if the file system supports directory indexing, or by sorting and compressing directories for smaller directories, or for file systems using traditional linear directories.

even without the -D option, e2fsck may sometimes optimize a few directories --- for example, if directory indexing is enabled and a directory is not indexed and would benefit from being indexed, or if the index structures are corrupted and need to be rebuilt. the -D option forces all directories in the file system to be optimized. this can sometimes make them a little smaller and slightly faster to search, but in practice, you should rarely need to use this option. ngl, lowkey optional ๐ŸŽ€

the -D option will detect directory entries with duplicate names in a single directory, which e2fsck normally does not enforce for performance reasons. ๐Ÿ‘€

  • -E extended_options โ€” set e2fsck extended options. extended options are comma separated, and may take an argument using the equals ('=') sign. the following options are supported:
    • ea_ver=extended_attribute_version โ€” set the version of the extended attribute blocks which e2fsck will require while checking the file system. the version number may be 1 or 2. the default extended attribute version format is 2. โœจ
    • journal_only โ€” only replay the journal if required, but do not perform any further checks or repairs.
    • fragcheck โ€” during pass 1, print a detailed report of any discontiguous blocks for files in the file system. ๐Ÿง
    • discard โ€” attempt to discard free blocks and unused inode blocks after the full file system check (discarding blocks is useful on solid state devices and sparse / thin-provisioned storage). note that discard is done in pass 5 AFTER the file system has been fully checked and only if it does not contain recognizable errors. however there might be cases where e2fsck does not fully recognize a problem and hence in this case this option may prevent you from further manual data recovery. โš ๏ธ be careful with this one bestie
    • nodiscard โ€” do not attempt to discard free blocks and unused inode blocks. this option is exactly the opposite of the discard option. this is set as default.
    • no_optimize_extents โ€” do not offer to optimize the extent tree by eliminating unnecessary width or depth. this can also be enabled in the options section of /etc/e2fsck.conf.
    • optimize_extents โ€” offer to optimize the extent tree by eliminating unnecessary width or depth. this is the default unless otherwise specified in /etc/e2fsck.conf.
    • inode_count_fullmap โ€” trade off using memory for speed when checking a file system with a large number of hard-linked files. the amount of memory required is proportional to the number of inodes in the file system. for large file systems, this can be gigabytes of memory. (for example, a 40 TB file system with 2.8 billion inodes will consume an additional 5.7 GB memory if this optimization is enabled.) this optimization can also be enabled in the options section of /etc/e2fsck.conf. ๐Ÿ˜ญ the way that's so much memory
    • no_inode_count_fullmap โ€” disable the inode_count_fullmap optimization. this is the default unless otherwise specified in /etc/e2fsck.conf.
    • readahead_kb โ€” use this many KiB of memory to pre-fetch metadata in the hopes of reducing e2fsck runtime. by default, this is set to the size of two block groups' inode tables (typically 4 MiB on a regular ext4 file system); if this amount is more than 1/50th of total physical memory, readahead is disabled. set this to zero to disable readahead entirely. ๐Ÿƒโ™€๏ธ
    • bmap2extent โ€” convert block-mapped files to extent-mapped files. ๐Ÿ”„
    • fixes_only โ€” only fix damaged metadata; do not optimize htree directories or compress extent trees. this option is incompatible with the -D and -E bmap2extent options. ๐Ÿšซ
    • check_encoding โ€” force verification of encoded filenames in case-insensitive directories. this is the default mode if the file system has the strict flag enabled.
    • unshare_blocks โ€” if the file system has shared blocks, with the shared blocks read-only feature enabled, then this will unshare all shared blocks and unset the read-only feature bit. if there is not enough free space then the operation will fail. if the file system does not have the read-only feature bit, but has shared blocks anyway, then this option will have no effect. note when using this option, if there is no free space to clone blocks, there is no prompt to delete files and instead the operation will fail. ๐Ÿ’€

more of this page is coming bestie, don't go anywhere ๐Ÿ’œ

okay so quick lil note before we move on โ€” unshare_blocks implies the -f option, so all the passes actually run. no skipping, bestie. ๐Ÿซถ and if you also throw in -n, e2fsck will simulate trying to allocate enough space to deduplicate. if that lil simulation fails? the exit code goes non-zero. that's it, that's the tea. ๐Ÿ’…


  • -f โ€” force the check even if the file system looks all clean and innocent. don't trust the vibes, verify โœจ
  • -F โ€” flush the file system device's buffer caches before starting. ngl this is only really useful for doing e2fsck time trials (it's a benchmarking queen, not an everyday icon).
  • -j external-journal โ€” sets the pathname where the external-journal for this file system lives. point her at the right spot and she'll find it. ๐ŸŽ€
  • -k โ€” when you pair this with the -c option, any existing bad blocks in the bad blocks list get preserved, and any new bad blocks found by running badblocks(8) get added on top of that existing list. hoarding the bad blocks, honestly iconic.
  • -l filename โ€” adds the block numbers listed in the file named filename to the list of bad blocks. the format of this file is the same as the one badblocks(8) spits out. heads up though: the block numbers are based on the blocksize of the file system, so badblocks(8) must be given the file system's blocksize or your results are gonna be wrong. which is exactly why it's much simpler and safer to just use the -c option on e2fsck instead โ€” she'll make sure the correct parameters get passed to the badblocks program for you. let her cook. ๐Ÿ”ฅ
  • -L filename โ€” sets the bad blocks list to be the list of blocks specified by filename. (this is the same as the -l option, EXCEPT the bad blocks list gets cleared before the blocks in the file are added. out with the old, in with the new, periodt.)
  • -n โ€” opens the file system read-only and assumes an answer of no to literally every question. this lets e2fsck be used non-interactively. โš ๏ธ may not be specified at the same time as the -p or -y options. pick a lane bestie, she can't do both.
  • -p โ€” automatically repair ("preen") the file system. this makes e2fsck auto-fix any file system problems that can be safely fixed without a human in the mix. ๐Ÿงš if she hits a problem that might need the system administrator to take extra corrective action, she'll print a description of the problem and then exit with the value 4 logically or'ed into the exit code. (peep the EXIT CODE section for that whole situation.) this one is normally used by the system's boot scripts. โš ๏ธ may not be specified at the same time as the -n or -y options.
  • -r โ€” this option does absolutely nothing at all. it's here purely for backwards compatibility. a decorative little ghost. ๐Ÿ‘ป
  • -t โ€” print timing statistics for e2fsck. and if you use this option twice, you get extra timing statistics printed on a pass-by-pass basis. the more you know ๐Ÿ’…
  • -v โ€” verbose mode. she's gonna talk a LOT. ๐Ÿ’ฌ
  • -V โ€” print version information and exit. quick lil flex of what she's running.
  • -y โ€” assume an answer of yes to every single question; lets e2fsck be used non-interactively. (the yes-girl of the group chat, truly saying yes to everything ๐Ÿ’–) โš ๏ธ may not be specified at the same time as the -n or -p options.
  • -z undo_file โ€” before overwriting a file system block, write the old contents of that block to an undo file. this undo file can then be used with e2undo(8) to restore the old contents of the file system if something goes wrong. ๐Ÿ›Ÿ if the empty string is passed as the undo_file argument, the undo file gets written to a file named e2fsck-device.e2undo in the directory specified via the E2FSPROGS_UNDO_DIR environment variable.
WARNING: The undo file cannot be used to recover from a power or system crash. it's a safety net for oopsies, not for the entire grid going down, okay? know the limits. ๐Ÿ˜ญ

๐Ÿ’ฅ EXIT CODE ๐Ÿ’ฅ

the exit code e2fsck returns is the sum of the following conditions:

0    - No errors
1    - File system errors corrected
2    - File system errors corrected, system should
       be rebooted
4    - File system errors left uncorrected
8    - Operational error
16   - Usage or syntax error
32   - E2fsck canceled by user request
128  - Shared library error

slay, math checks out, go read your number. โœจ


๐Ÿ“ก SIGNALS ๐Ÿ“ก

here's what happens when you send these signals to e2fsck:

SIGUSR1

this signal makes e2fsck start displaying a completion bar or emitting progress information. (go look at the discussion of the -C option for the full lore.) ๐Ÿ“ถ

SIGUSR2

this signal makes e2fsck stop displaying a completion bar or emitting progress information. okay she's done performing, everyone go home. ๐ŸŽฌ


๐Ÿ› REPORTING BUGS ๐Ÿ›

almost any piece of software is gonna have bugs, that's just the reality of it. if you manage to find a file system that makes e2fsck crash, or one that e2fsck is unable to repair, please report it to the author. you're doing a public service bestie ๐Ÿซถ

please include as much information as possible in your bug report. ideally, include a complete transcript of the e2fsck run, so I can see exactly what error messages are displayed. (make sure the messages printed by e2fsck are in English โ€” if your system has been configured so that e2fsck's messages have been translated into another language, please set the LC_ALL environment variable to C so that the transcript of e2fsck's output will actually be useful to me.) if you have a writable file system where the transcript can be stored, the script(1) program is a handy way to save the output of e2fsck to a file. ๐Ÿ“

it is also useful to send the output of dumpe2fs(8). if a specific inode or inodes seems to be giving e2fsck trouble, try running the debugfs(8) command and send the output of the stat(1u) command run on the relevant inode(s). if the inode is a directory, the debugfs dump command will let you extract the contents of the directory inode, which can be sent to me after being first run through uuencode(1). the most useful data you can send to help reproduce the bug is a compressed raw image dump of the file system, generated using e2image(8). peep the e2image(8) man page for more details. ๐Ÿ”

always include the full version string which e2fsck displays when it is run, so I know which version you are running. ๐Ÿ‘‘


๐ŸŒฑ ENVIRONMENT ๐ŸŒฑ

E2FSCK_CONFIG

determines the location of the configuration file (see e2fsck.conf(5)). ๐Ÿ“


โœ๏ธ AUTHOR โœ๏ธ

this version of e2fsck was written by Theodore Ts'o <tytso@mit.edu>. king behavior, honestly ๐Ÿ‘‘


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

e2fsck.conf(5), badblocks(8), dumpe2fs(8), debugfs(8), e2image(8), mke2fs(8), tune2fs(8)


and that's the whole page, bestie!! ๐ŸŽ€ this was E2fsprogs version 1.47.4, dated March 2025 โ€” and if you're a proper nerd you'd find it filed under E2FSCK(8). go forth and fsck responsibly ๐Ÿ’…๐Ÿ’–

๐Ÿ“ฆ where this page comes from