# btrfs-check(8) - man - phpman

> **TLDR:** Check or repair a btrfs filesystem.
>
- Check a btrfs filesystem:
  `sudo btrfs {{c|check}} {{path/to/partition}}`
- Check and repair a btrfs filesystem (dangerous):
  `sudo btrfs {{c|check}} --repair {{path/to/partition}}`
- Show the progress of the check:
  `sudo btrfs {{c|check}} {{-p|--progress}} {{path/to/partition}}`
- Verify the checksum of each data block (if the filesystem is good):
  `sudo btrfs {{c|check}} --check-data-csum {{path/to/partition}}`
- Use the `n`-th superblock (`n` can be 0, 1, or 2):
  `sudo btrfs {{c|check}} {{-s|--super}} {{n}} {{path/to/partition}}`
- Rebuild the checksum tree:
  `sudo btrfs {{c|check}} --repair --init-csum-tree {{path/to/partition}}`
- Rebuild the extent tree:
  `sudo btrfs {{c|check}} --repair --init-extent-tree {{path/to/partition}}`

*Source: tldr-pages*

---

[BTRFS-CHECK(8)](https://www.chedong.com/phpMan.php/man/BTRFS-CHECK/8/markdown)                              Btrfs Manual                              [BTRFS-CHECK(8)](https://www.chedong.com/phpMan.php/man/BTRFS-CHECK/8/markdown)



## NAME
       btrfs-check - check or repair a btrfs filesystem

## SYNOPSIS
       **btrfs** **check** [options] _<device>_

## DESCRIPTION
       The filesystem checker is used to verify structural integrity of a filesystem and attempt to
       repair it if requested. It is recommended to unmount the filesystem prior to running the
       check, but it is possible to start checking a mounted filesystem (see _--force_).

       By default, **btrfs** **check** will not modify the device but you can reaffirm that by the option
       _--readonly_.

       **btrfsck** is an alias of **btrfs** **check** command and is now deprecated.

           **Warning**
           Do not use _--repair_ unless you are advised to do so by a developer or an experienced
           user, and then only after having accepted that no _fsck_ successfully repair all types of
           filesystem corruption. Eg. some other software or hardware bugs can fatally damage a
           volume.

       The structural integrity check verifies if internal filesystem objects or data structures
       satisfy the constraints, point to the right objects or are correctly connected together.

       There are several cross checks that can detect wrong reference counts of shared extents,
       backreferences, missing extents of inodes, directory and inode connectivity etc.

       The amount of memory required can be high, depending on the size of the filesystem, similarly
       the run time. Check the modes that can also affect that.

## SAFE OR ADVISORY OPTIONS
       -b|--backup
           use the first valid set of backup roots stored in the superblock

           This can be combined with _--super_ if some of the superblocks are damaged.

### --check-data-csum
           verify checksums of data blocks

           This expects that the filesystem is otherwise OK, and is basically an offline _scrub_ that
           does not repair data from spare copies.

       --chunk-root _<bytenr>_
           use the given offset _bytenr_ for the chunk tree root

       -E|--subvol-extents _<subvolid>_
           show extent state for the given subvolume

       -p|--progress
           indicate progress at various checking phases

       -Q|--qgroup-report
           verify qgroup accounting and compare against filesystem accounting

       -r|--tree-root _<bytenr>_
           use the given offset _bytenr_ for the tree root

### --readonly
           (default) run in read-only mode, this option exists to calm potential panic when users
           are going to run the checker

       -s|--super _<superblock>_
           use 'superblock’th superblock copy, valid values are 0, 1 or 2 if the respective
           superblock offset is within the device size

           This can be used to use a different starting point if some of the primary superblock is
           damaged.

       --clear-space-cache v1|v2
           completely wipe all free space cache of given type

           For free space cache _v1_, the _clear_cache_ kernel mount option only rebuilds the free space
           cache for block groups that are modified while the filesystem is mounted with that
           option. Thus, using this option with _v1_ makes it possible to actually clear the entire
           free space cache.

           For free space cache _v2_, the _clear_cache_ kernel mount option destroys the entire free
           space cache. This option, with _v2_ provides an alternative method of clearing the free
           space cache that doesn’t require mounting the filesystem.

### --clear-ino-cache
           remove leftover items pertaining to the deprecated inode map feature

## DANGEROUS OPTIONS
### --repair
           enable the repair mode and attempt to fix problems where possible

               **Note**
               there’s a warning and 10 second delay when this option is run without _--force_ to give
               users a chance to think twice before running repair, the warnings in documentation
               have shown to be insufficient

### --init-csum-tree
           create a new checksum tree and recalculate checksums in all files

               **Note**
               Do not blindly use this option to fix checksum mismatch problems.

### --init-extent-tree
           build the extent tree from scratch

               **Note**
               Do not use unless you know what you’re doing.

       --mode _<MODE>_
           select mode of operation regarding memory and IO

           The _MODE_ can be one of:

           _original_
               The metadata are read into memory and verified, thus the requirements are high on
               large filesystems and can even lead to out-of-memory conditions. The possible
               workaround is to export the block device over network to a machine with enough
               memory.

           _lowmem_
               This mode is supposed to address the high memory consumption at the cost of increased
               IO when it needs to re-read blocks. This may increase run time.

                   **Note**
                   _lowmem_ mode does not work with _--repair_ yet, and is still considered
                   experimental.

### --force
           allow work on a mounted filesystem. Note that this should work fine on a quiescent or
           read-only mounted filesystem but may crash if the device is changed externally, eg. by
           the kernel module. Repair without mount checks is not supported right now.

           This option also skips the delay and warning in the repair mode (see _--repair_).

## EXIT STATUS
       **btrfs** **check** returns a zero exit status if it succeeds. Non zero is returned in case of
       failure.

## AVAILABILITY
       **btrfs** is part of btrfs-progs. Please refer to the btrfs wiki **<http://btrfs.wiki.kernel.org>** for
       further details.

## SEE ALSO
       [**mkfs.btrfs**(8)](https://www.chedong.com/phpMan.php/man/mkfs.btrfs/8/markdown), [**btrfs-scrub**(8)](https://www.chedong.com/phpMan.php/man/btrfs-scrub/8/markdown), [**btrfs-rescue**(8)](https://www.chedong.com/phpMan.php/man/btrfs-rescue/8/markdown)



Btrfs v5.16.2                                02/16/2022                               [BTRFS-CHECK(8)](https://www.chedong.com/phpMan.php/man/BTRFS-CHECK/8/markdown)
