Linux "btrfsck" Command Line Options and Examples
check or repair a btrfs filesystem

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.


Usage:

btrfs check [options]






Command Line Options:

-b|--backup
use the first valid set of backup roots stored in the superblockThis can be combined with --super if some of the superblocks are damaged.
btrfsck -b|--backup ...
--check-data-csum
verify checksums of data blocksThis expects that the filesystem is otherwise OK, and is basically and offline scrub but does not repair data from spare copies.
btrfsck --check-data-csum ...
--chunk-root
use the given offset bytenr for the chunk tree root
btrfsck --chunk-root ...
-E|--subvol-extents
show extent state for the given subvolume
btrfsck -E|--subvol-extents ...
-p|--progress
indicate progress at various checking phases
btrfsck -p|--progress ...
-Q|--qgroup-report
verify qgroup accounting and compare against filesystem accounting
btrfsck -Q|--qgroup-report ...
-r|--tree-root
use the given offset bytenr for the tree root
btrfsck -r|--tree-root ...
--readonly
(default) run in read-only mode, this option exists to calm potential panic when users are going to run the checker
btrfsck --readonly ...
-s|--super
use 'superblock’th superblock copy, valid values are 0, 1 or 2 if the respective superblock offset is within the device sizeThis can be used to use a different starting point if some of the primary superblock is damaged.
btrfsck -s|--super ...
--clear-space-cache
completely wipe all free space cache of given typeFor free space cache v1, the clear_cache kernel mount option only rebuilds the free space cache for block groups that aremodified while the filesystem is mounted with that option. Thus, using this option with v1 makes it possible to actually clearthe 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 providesan alternative method of clearing the free space cache that doesn’t require mounting the filesystem.DANGEROUS OPTIONS
btrfsck --clear-space-cache ...
--repair
enable the repair mode and attempt to fix problems where possible
btrfsck --repair ...
--init-csum-tree
create a new checksum tree and recalculate checksums in all filesNoteDo not blindly use this option to fix checksum mismatch problems.
btrfsck --init-csum-tree ...
--init-extent-tree
build the extent tree from scratchNoteDo not use unless you know what you’re doing.
btrfsck --init-extent-tree ...
--mode
select mode of operation regarding memory and IOThe MODE can be one of original and lowmem. The original mode is mostly unoptimized regarding memory consumption and can lead toout-of-memory conditions on large filesystems. The possible workaround is to export the block device over network to a machinewith enough memory. The low memory mode is supposed to address the memory consumption, at the cost of increased IO when it needsto re-read blocks when needed. This may increase run time.Notelowmem mode does not work with --repair yet, and is still considered experimental.
btrfsck --mode ...
--force
allow to work on a mounted filesystem. Note that this should work fine on a quiescent or read-only mounted filesystem but maycrash if the device is changed externally, eg. by the kernel module. Repair without mount checks is not supported right now.EXIT STATUSbtrfs check returns a zero exit status if it succeeds. Non zero is returned in case of failure.AVAILABILITYbtrfs is part of btrfs-progs. Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for further details.
btrfsck --force ...