{
    "content": [
        {
            "type": "text",
            "text": "# btrfs-check(8) (man)\n\n## TLDR\n\n> Check or repair a btrfs filesystem.\n\n- Check a btrfs filesystem:\n  `sudo btrfs {{c|check}} {{path/to/partition}}`\n- Check and repair a btrfs filesystem (dangerous):\n  `sudo btrfs {{c|check}} --repair {{path/to/partition}}`\n- Show the progress of the check:\n  `sudo btrfs {{c|check}} {{-p|--progress}} {{path/to/partition}}`\n- Verify the checksum of each data block (if the filesystem is good):\n  `sudo btrfs {{c|check}} --check-data-csum {{path/to/partition}}`\n- Use the `n`-th superblock (`n` can be 0, 1, or 2):\n  `sudo btrfs {{c|check}} {{-s|--super}} {{n}} {{path/to/partition}}`\n- Rebuild the checksum tree:\n  `sudo btrfs {{c|check}} --repair --init-csum-tree {{path/to/partition}}`\n- Rebuild the extent tree:\n  `sudo btrfs {{c|check}} --repair --init-extent-tree {{path/to/partition}}`\n\n*Source: tldr-pages*\n\n---\n\n**Summary:** btrfs-check - check or repair a btrfs filesystem\n\n**Synopsis:** btrfs check [options] <device>\n\n## See Also\n\n- mkfs.btrfs(8)\n- btrfs-scrub(8)\n- btrfs-rescue(8)\n- BTRFS-CHECK(8)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (2 lines)\n- **DESCRIPTION** (24 lines)\n- **SAFE OR ADVISORY OPTIONS** (5 lines) — 3 subsections\n  - --check-data-csum (20 lines)\n  - --readonly (22 lines)\n  - --clear-ino-cache (2 lines)\n- **DANGEROUS OPTIONS** (1 lines) — 4 subsections\n  - --repair (7 lines)\n  - --init-csum-tree (5 lines)\n  - --init-extent-tree (24 lines)\n  - --force (6 lines)\n- **EXIT STATUS** (3 lines)\n- **AVAILABILITY** (3 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nbtrfs-check - check or repair a btrfs filesystem\n\n### SYNOPSIS\n\nbtrfs check [options] <device>\n\n### DESCRIPTION\n\nThe filesystem checker is used to verify structural integrity of a filesystem and attempt to\nrepair it if requested. It is recommended to unmount the filesystem prior to running the\ncheck, but it is possible to start checking a mounted filesystem (see --force).\n\nBy default, btrfs check will not modify the device but you can reaffirm that by the option\n--readonly.\n\nbtrfsck is an alias of btrfs check command and is now deprecated.\n\nWarning\nDo not use --repair unless you are advised to do so by a developer or an experienced\nuser, and then only after having accepted that no fsck successfully repair all types of\nfilesystem corruption. Eg. some other software or hardware bugs can fatally damage a\nvolume.\n\nThe structural integrity check verifies if internal filesystem objects or data structures\nsatisfy the constraints, point to the right objects or are correctly connected together.\n\nThere are several cross checks that can detect wrong reference counts of shared extents,\nbackreferences, missing extents of inodes, directory and inode connectivity etc.\n\nThe amount of memory required can be high, depending on the size of the filesystem, similarly\nthe run time. Check the modes that can also affect that.\n\n### SAFE OR ADVISORY OPTIONS\n\n-b|--backup\nuse the first valid set of backup roots stored in the superblock\n\nThis can be combined with --super if some of the superblocks are damaged.\n\n#### --check-data-csum\n\nverify checksums of data blocks\n\nThis expects that the filesystem is otherwise OK, and is basically an offline scrub that\ndoes not repair data from spare copies.\n\n--chunk-root <bytenr>\nuse the given offset bytenr for the chunk tree root\n\n-E|--subvol-extents <subvolid>\nshow extent state for the given subvolume\n\n-p|--progress\nindicate progress at various checking phases\n\n-Q|--qgroup-report\nverify qgroup accounting and compare against filesystem accounting\n\n-r|--tree-root <bytenr>\nuse the given offset bytenr for the tree root\n\n#### --readonly\n\n(default) run in read-only mode, this option exists to calm potential panic when users\nare going to run the checker\n\n-s|--super <superblock>\nuse 'superblock’th superblock copy, valid values are 0, 1 or 2 if the respective\nsuperblock offset is within the device size\n\nThis can be used to use a different starting point if some of the primary superblock is\ndamaged.\n\n--clear-space-cache v1|v2\ncompletely wipe all free space cache of given type\n\nFor free space cache v1, the clearcache kernel mount option only rebuilds the free space\ncache for block groups that are modified while the filesystem is mounted with that\noption. Thus, using this option with v1 makes it possible to actually clear the entire\nfree space cache.\n\nFor free space cache v2, the clearcache kernel mount option destroys the entire free\nspace cache. This option, with v2 provides an alternative method of clearing the free\nspace cache that doesn’t require mounting the filesystem.\n\n#### --clear-ino-cache\n\nremove leftover items pertaining to the deprecated inode map feature\n\n### DANGEROUS OPTIONS\n\n#### --repair\n\nenable the repair mode and attempt to fix problems where possible\n\nNote\nthere’s a warning and 10 second delay when this option is run without --force to give\nusers a chance to think twice before running repair, the warnings in documentation\nhave shown to be insufficient\n\n#### --init-csum-tree\n\ncreate a new checksum tree and recalculate checksums in all files\n\nNote\nDo not blindly use this option to fix checksum mismatch problems.\n\n#### --init-extent-tree\n\nbuild the extent tree from scratch\n\nNote\nDo not use unless you know what you’re doing.\n\n--mode <MODE>\nselect mode of operation regarding memory and IO\n\nThe MODE can be one of:\n\noriginal\nThe metadata are read into memory and verified, thus the requirements are high on\nlarge filesystems and can even lead to out-of-memory conditions. The possible\nworkaround is to export the block device over network to a machine with enough\nmemory.\n\nlowmem\nThis mode is supposed to address the high memory consumption at the cost of increased\nIO when it needs to re-read blocks. This may increase run time.\n\nNote\nlowmem mode does not work with --repair yet, and is still considered\nexperimental.\n\n#### --force\n\nallow work on a mounted filesystem. Note that this should work fine on a quiescent or\nread-only mounted filesystem but may crash if the device is changed externally, eg. by\nthe kernel module. Repair without mount checks is not supported right now.\n\nThis option also skips the delay and warning in the repair mode (see --repair).\n\n### EXIT STATUS\n\nbtrfs check returns a zero exit status if it succeeds. Non zero is returned in case of\nfailure.\n\n### AVAILABILITY\n\nbtrfs is part of btrfs-progs. Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for\nfurther details.\n\n### SEE ALSO\n\nmkfs.btrfs(8), btrfs-scrub(8), btrfs-rescue(8)\n\n\n\nBtrfs v5.16.2                                02/16/2022                               BTRFS-CHECK(8)\n\n"
        }
    ],
    "structuredContent": {
        "command": "btrfs-check",
        "section": "8",
        "mode": "man",
        "summary": "btrfs-check - check or repair a btrfs filesystem",
        "synopsis": "btrfs check [options] <device>",
        "tldr_summary": "Check or repair a btrfs filesystem.",
        "tldr_examples": [
            {
                "description": "Check a btrfs filesystem",
                "command": "sudo btrfs {{c|check}} {{path/to/partition}}"
            },
            {
                "description": "Check and repair a btrfs filesystem (dangerous)",
                "command": "sudo btrfs {{c|check}} --repair {{path/to/partition}}"
            },
            {
                "description": "Show the progress of the check",
                "command": "sudo btrfs {{c|check}} {{-p|--progress}} {{path/to/partition}}"
            },
            {
                "description": "Verify the checksum of each data block (if the filesystem is good)",
                "command": "sudo btrfs {{c|check}} --check-data-csum {{path/to/partition}}"
            },
            {
                "description": "Use the `n`-th superblock (`n` can be 0, 1, or 2)",
                "command": "sudo btrfs {{c|check}} {{-s|--super}} {{n}} {{path/to/partition}}"
            },
            {
                "description": "Rebuild the checksum tree",
                "command": "sudo btrfs {{c|check}} --repair --init-csum-tree {{path/to/partition}}"
            },
            {
                "description": "Rebuild the extent tree",
                "command": "sudo btrfs {{c|check}} --repair --init-extent-tree {{path/to/partition}}"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "",
                "long": "--check-data-csum",
                "arg": null,
                "description": "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"
            },
            {
                "flag": "",
                "long": "--readonly",
                "arg": null,
                "description": "(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 clearcache 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 clearcache 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."
            },
            {
                "flag": "",
                "long": "--clear-ino-cache",
                "arg": null,
                "description": "remove leftover items pertaining to the deprecated inode map feature"
            },
            {
                "flag": "",
                "long": "--repair",
                "arg": null,
                "description": "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"
            },
            {
                "flag": "",
                "long": "--init-csum-tree",
                "arg": null,
                "description": "create a new checksum tree and recalculate checksums in all files Note Do not blindly use this option to fix checksum mismatch problems."
            },
            {
                "flag": "",
                "long": "--init-extent-tree",
                "arg": null,
                "description": "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."
            },
            {
                "flag": "",
                "long": "--force",
                "arg": null,
                "description": "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)."
            }
        ],
        "examples": [],
        "see_also": [
            {
                "name": "mkfs.btrfs",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/mkfs.btrfs/8/json"
            },
            {
                "name": "btrfs-scrub",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-scrub/8/json"
            },
            {
                "name": "btrfs-rescue",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-rescue/8/json"
            },
            {
                "name": "BTRFS-CHECK",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/BTRFS-CHECK/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "SAFE OR ADVISORY OPTIONS",
                "lines": 5,
                "subsections": [
                    {
                        "name": "--check-data-csum",
                        "lines": 20,
                        "long": "--check-data-csum"
                    },
                    {
                        "name": "--readonly",
                        "lines": 22,
                        "long": "--readonly"
                    },
                    {
                        "name": "--clear-ino-cache",
                        "lines": 2,
                        "long": "--clear-ino-cache"
                    }
                ]
            },
            {
                "name": "DANGEROUS OPTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "--repair",
                        "lines": 7,
                        "long": "--repair"
                    },
                    {
                        "name": "--init-csum-tree",
                        "lines": 5,
                        "long": "--init-csum-tree"
                    },
                    {
                        "name": "--init-extent-tree",
                        "lines": 24,
                        "long": "--init-extent-tree"
                    },
                    {
                        "name": "--force",
                        "lines": 6,
                        "long": "--force"
                    }
                ]
            },
            {
                "name": "EXIT STATUS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AVAILABILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}