# man > e2fsck(8)

---
type: CommandReference
command: e2fsck
mode: man
section: 8
source: man-pages
---

## Quick Reference

- `e2fsck /dev/sda1` — check filesystem interactively
- `e2fsck -p /dev/sda1` — autofix safe problems without prompting
- `e2fsck -n /dev/sda1` — read-only check, no modifications
- `e2fsck -f /dev/sda1` — force check even if filesystem appears clean
- `e2fsck -b 32768 /dev/sda1` — use alternative superblock
- `e2fsck -c /dev/sda1` — scan for bad blocks and add to list
- `e2fsck -y /dev/sda1` — assume "yes" to all questions
- `e2fsck -C 0 /dev/sda1` — show progress bar during check

## 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_

## Options

### Basic options

- `-a` — same as `-p` (backward compatibility)
- `-p` — automatically fix safe problems; exit with code 4 if manual intervention needed
- `-n` — non-interactive read-only check; no changes written
- `-y` — assume "yes" to all repair prompts
- `-f` — force check even if filesystem appears clean
- `-v` — verbose mode
- `-V` — print version and exit

### Filesystem-specific options

- `-b` _superblock_ — use alternative superblock (e.g., after primary corruption)
- `-B` _blocksize_ — force superblock search at specific block size
- `-j` _external-journal_ — path to external journal device
- `-c` — run badblocks(8) scan; add new bad blocks to list; use twice for non-destructive read-write test
- `-k` — preserve existing bad blocks list when combined with `-c`
- `-l` _filename_ — add block numbers from file to bad blocks list
- `-L` _filename_ — replace bad blocks list with blocks from file (clear first)
- `-z` _undo_file_ — write undo file before overwriting blocks (use e2undo(8) to restore); if empty string, write to `e2fsck-<device>.e2undo` in `E2FSPROGS_UNDO_DIR`

### I/O and progress

- `-C` _fd_ — write progress info to file descriptor; negative value suppresses initially (enable with SIGUSR1); `-C 0` prints completion bar on terminal
- `-F` — flush buffers before checking (for time trials)
- `-t` — print timing statistics per pass

### Directory and extent optimization

- `-D` — optimize all directories (re-index, sort, compress); also detects duplicate names
- `-E` _extended_options_ — comma-separated extended options (see below)

### Extended options (`-E`)

- `ea_ver=<1|2>` — set extended attribute version required
- `journal_only` — replay journal only, no further checks
- `fragcheck` — report discontiguous blocks during pass 1
- `discard` — discard free blocks after check (default: off)
- `nodiscard` — explicitly disable discard
- `no_optimize_extents` — do not offer to optimize extent tree
- `optimize_extents` — offer to optimize extent tree (default)
- `inode_count_fullmap` — use memory for speed on large hard-link filesystems (may require gigabytes)
- `no_inode_count_fullmap` — disable the above (default)
- `readahead_kb=<N>` — KiB for metadata readahead (0 to disable)
- `bmap2extent` — convert block-mapped files to extent-mapped
- `fixes_only` — only fix damaged metadata; incompatible with `-D` and `bmap2extent`
- `check_encoding` — force verification of encoded filenames in case-insensitive dirs
- `unshare_blocks` — unshare shared blocks (requires free space; implies `-f`)

## Examples

- Check filesystem interactively:
  ```shell
  e2fsck /dev/sda1
  
- Auto-repair safe problems (for boot scripts):
  ```shell
  e2fsck -p /dev/sda1
  
- Read-only check without modifications:
  ```shell
  e2fsck -n /dev/sda1
  
- Force check even if filesystem appears clean:
  ```shell
  e2fsck -f /dev/sda1
  
- Use backup superblock at block 32768:
  ```shell
  e2fsck -b 32768 /dev/sda1
  
- Scan for bad blocks and add to list:
  ```shell
  e2fsck -c /dev/sda1
  
- Assume "yes" to all questions:
  ```shell
  e2fsck -y /dev/sda1
  
- Show progress bar during check:
  ```shell
  e2fsck -C 0 /dev/sda1
  
## See Also

[e2fsck.conf(5)](https://man7.org/linux/man-pages/man5/e2fsck.conf.5.html), [badblocks(8)](https://man7.org/linux/man-pages/man8/badblocks.8.html), [dumpe2fs(8)](https://man7.org/linux/man-pages/man8/dumpe2fs.8.html), [debugfs(8)](https://man7.org/linux/man-pages/man8/debugfs.8.html), [e2image(8)](https://man7.org/linux/man-pages/man8/e2image.8.html), [mke2fs(8)](https://man7.org/linux/man-pages/man8/mke2fs.8.html), [tune2fs(8)](https://man7.org/linux/man-pages/man8/tune2fs.8.html)

## Exit Codes

The exit code is the sum of the following:

- `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