{
    "content": [
        {
            "type": "text",
            "text": "# btrfs-filesystem(8) (man)\n\n**Summary:** btrfs-filesystem - command group that primarily does work on the whole filesystems\n\n**Synopsis:** btrfs filesystem <subcommand> <args>\n\n## Examples\n\n- `Recursively defragment files under dir/, print files as they are processed. The file names`\n- `will be printed in batches, similarly the amount of data triggered by defragmentation will be`\n- `proportional to last N printed files. The system dirty memory throttling will slow down the`\n- `defragmentation but there can still be a lot of IO load and the system may stall for a`\n- `moment.`\n- `Recursively defragment files under dir/, be verbose and wait until all blocks are flushed`\n- `before processing next file. You can note slower progress of the output and lower IO load`\n- `(proportional to currently defragmented file).`\n- `Recursively defragment files under dir/, be verbose, wait until all blocks are flushed and`\n- `force file compression.`\n- `Recursively defragment files under dir/, be verbose and try to merge extents to be about`\n- `64MiB. As stated above, the success rate depends on actual free space fragmentation and the`\n- `final result is not guaranteed to meet the target even if run repeatedly.`\n- `Shrink size of the filesystem’s device id 1 by 1GiB. The first syntax expects a device with`\n- `id 1 to exist, otherwise fails. The second is equivalent and more explicit. For a`\n- `single-device filesystem it’s typically not necessary to specify the devid though.`\n- `Let’s assume that devid 1 exists and the filesystem does not occupy the whole block device,`\n- `eg. it has been enlarged and we want to grow the filesystem. By simply using max as size we`\n- `will achieve that.`\n- `Note`\n- `There are two ways to minimize the filesystem on a given device. The btrfs`\n- `inspect-internal min-dev-size command, or iteratively shrink in steps.`\n\n## See Also\n\n- btrfs-subvolume(8)\n- mkfs.btrfs(8)\n- BTRFS-FILESYSTEM(8)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (2 lines)\n- **DESCRIPTION** (5 lines)\n- **SUBCOMMAND** (383 lines)\n- **EXAMPLES** (1 lines) — 8 subsections\n  - $ btrfs filesystem defrag -v -r dir/ (6 lines)\n  - $ btrfs filesystem defrag -v -r -f dir/ (4 lines)\n  - $ btrfs filesystem defrag -v -r -f -clzo dir/ (3 lines)\n  - $ btrfs filesystem defrag -v -r -t 64M dir/ (4 lines)\n  - $ btrfs filesystem resize -1G /path (1 lines)\n  - $ btrfs filesystem resize 1:-1G /path (4 lines)\n  - $ btrfs filesystem resize max /path (1 lines)\n  - $ btrfs filesystem resize 1:max /path (8 lines)\n- **EXIT STATUS** (3 lines)\n- **AVAILABILITY** (3 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nbtrfs-filesystem - command group that primarily does work on the whole filesystems\n\n### SYNOPSIS\n\nbtrfs filesystem <subcommand> <args>\n\n### DESCRIPTION\n\nbtrfs filesystem is used to perform several whole filesystem level tasks, including all the\nregular filesystem operations like resizing, space stats, label setting/getting, and\ndefragmentation. There are other whole filesystem tasks like scrub or balance that are\ngrouped in separate commands.\n\n### SUBCOMMAND\n\ndf [options] <path>\nShow a terse summary information about allocation of block group types of a given mount\npoint. The original purpose of this command was a debugging helper. The output needs to\nbe further interpreted and is not suitable for quick overview.\n\nAn example with description:\n\n•   device size: 1.9TiB, one device, no RAID\n\n•   filesystem size: 1.9TiB\n\n•   created with: mkfs.btrfs -d single -m single\n\n$ btrfs filesystem df /path\nData, single: total=1.15TiB, used=1.13TiB\nSystem, single: total=32.00MiB, used=144.00KiB\nMetadata, single: total=12.00GiB, used=6.45GiB\nGlobalReserve, single: total=512.00MiB, used=0.00B\n\n•   Data, System and Metadata are separate block group types.  GlobalReserve is an\nartificial and internal emergency space, see below.\n\n•   single — the allocation profile, defined at mkfs time\n\n•   total — sum of space reserved for all allocation profiles of the given type, ie. all\nData/single. Note that it’s not total size of filesystem.\n\n•   used — sum of used space of the above, ie. file extents, metadata blocks\n\nGlobalReserve is an artificial and internal emergency space. It is used eg. when the\nfilesystem is full. Its total size is dynamic based on the filesystem size, usually not\nlarger than 512MiB, used may fluctuate.\n\nThe GlobalReserve is a portion of Metadata. In case the filesystem metadata is exhausted,\nGlobalReserve/total + Metadata/used = Metadata/total. Otherwise there appears to be some\nunused space of Metadata.\n\nOptions\n\n-b|--raw\nraw numbers in bytes, without the B suffix\n\n-h|--human-readable\nprint human friendly numbers, base 1024, this is the default\n\n-H\nprint human friendly numbers, base 1000\n\n--iec\nselect the 1024 base for the following options, according to the IEC standard\n\n--si\nselect the 1000 base for the following options, according to the SI standard\n\n-k|--kbytes\nshow sizes in KiB, or kB with --si\n\n-m|--mbytes\nshow sizes in MiB, or MB with --si\n\n-g|--gbytes\nshow sizes in GiB, or GB with --si\n\n-t|--tbytes\nshow sizes in TiB, or TB with --si\n\nIf conflicting options are passed, the last one takes precedence.\n\ndefragment [options] <file>|<dir> [<file>|<dir>...]\nDefragment file data on a mounted filesystem. Requires kernel 2.6.33 and newer.\n\nIf -r is passed, files in dir will be defragmented recursively (not descending to\nsubvolumes, mount points and directory symlinks). The start position and the number of\nbytes to defragment can be specified by start and length using -s and -l options below.\nExtents bigger than value given by -t will be skipped, otherwise this value is used as a\ntarget extent size, but is only advisory and may not be reached if the free space is too\nfragmented. Use 0 to take the kernel default, which is 256kB but may change in the\nfuture. You can also turn on compression in defragment operations.\n\nWarning\nDefragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with Linux\nstable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the reflinks of\nCOW data (for example files copied with cp --reflink, snapshots or de-duplicated\ndata). This may cause considerable increase of space usage depending on the broken up\nreflinks.\n\nNote\nDirectory arguments without -r do not defragment files recursively but will\ndefragment certain internal trees (extent tree and the subvolume tree). This has been\nconfusing and could be removed in the future.\nFor start, len, size it is possible to append units designator: 'K', 'M', 'G', 'T', 'P',\nor 'E', which represent KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not\nmatter).\n\nOptions\n\n-c[<algo>]\ncompress file contents while defragmenting. Optional argument selects the compression\nalgorithm, zlib (default), lzo or zstd. Currently it’s not possible to select no\ncompression. See also section EXAMPLES.\n\n-r\ndefragment files recursively in given directories, does not descend to subvolumes or\nmount points\n\n-f\nflush data for each file before going to the next file.\n\nThis will limit the amount of dirty data to current file, otherwise the amount\naccumulates from several files and will increase system load. This can also lead to\nENOSPC if there’s too much dirty data to write and it’s not possible to make the\nreservations for the new data (ie. how the COW design works).\n\n-s <start>[kKmMgGtTpPeE]\ndefragmentation will start from the given offset, default is beginning of a file\n\n-l <len>[kKmMgGtTpPeE]\ndefragment only up to len bytes, default is the file size\n\n-t <size>[kKmMgGtTpPeE]\ntarget extent size, do not touch extents bigger than size, default: 32M\n\nThe value is only advisory and the final size of the extents may differ, depending on\nthe state of the free space and fragmentation or other internal logic. Reasonable\nvalues are from tens to hundreds of megabytes.\n\n-v\n(deprecated) alias for global -v option\n\ndu [options] <path> [<path>..]\nCalculate disk usage of the target files using FIEMAP. For individual files, it will\nreport a count of total bytes, and exclusive (not shared) bytes. We also calculate a set\nshared value which is described below.\n\nEach argument to btrfs filesystem du will have a set shared value calculated for it. We\ndefine each set as those files found by a recursive search of an argument (recursion\ndescends to subvolumes but not mount points). The set shared value then is a sum of all\nshared space referenced by the set.\n\nset shared takes into account overlapping shared extents, hence it isn’t as simple as\nadding up shared extents.\n\nOptions\n\n-s|--summarize\ndisplay only a total for each argument\n\n--raw\nraw numbers in bytes, without the B suffix.\n\n--human-readable\nprint human friendly numbers, base 1024, this is the default\n\n--iec\nselect the 1024 base for the following options, according to the IEC standard.\n\n--si\nselect the 1000 base for the following options, according to the SI standard.\n\n--kbytes\nshow sizes in KiB, or kB with --si.\n\n--mbytes\nshow sizes in MiB, or MB with --si.\n\n--gbytes\nshow sizes in GiB, or GB with --si.\n\n--tbytes\nshow sizes in TiB, or TB with --si.\n\nlabel [<device>|<mountpoint>] [<newlabel>]\nShow or update the label of a filesystem. This works on a mounted filesystem or a\nfilesystem image.\n\nThe newlabel argument is optional. Current label is printed if the argument is omitted.\n\nNote\nthe maximum allowable length shall be less than 256 chars and must not contain a\nnewline. The trailing newline is stripped automatically.\n\nresize [options] [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>\nResize a mounted filesystem identified by path. A particular device can be resized by\nspecifying a devid.\n\nWarning\nIf path is a file containing a BTRFS image then resize does not work as expected and\ndoes not resize the image. This would resize the underlying filesystem instead.\nThe devid can be found in the output of btrfs filesystem show and defaults to 1 if not\nspecified. The size parameter specifies the new size of the filesystem. If the prefix +\nor - is present the size is increased or decreased by the quantity size. If no units are\nspecified, bytes are assumed for size. Optionally, the size parameter may be suffixed by\none of the following unit designators: 'K', 'M', 'G', 'T', 'P', or 'E', which represent\nKiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).\n\nIf max is passed, the filesystem will occupy all available space on the device respecting\ndevid (remember, devid 1 by default).\n\nThe resize command does not manipulate the size of underlying partition. If you wish to\nenlarge/reduce a filesystem, you must make sure you can expand the partition before\nenlarging the filesystem and shrink the partition after reducing the size of the\nfilesystem. This can done using fdisk(8) or parted(8) to delete the existing partition\nand recreate it with the new desired size. When recreating the partition make sure to use\nthe same starting partition offset as before.\n\nGrowing is usually instant as it only updates the size. However, shrinking could take a\nlong time if there are data in the device area that’s beyond the new end. Relocation of\nthe data takes time.\n\nSee also section EXAMPLES.\n\nOptions\n\n--enqueue\nwait if there’s another exclusive operation running, otherwise continue\n\nshow [options] [<path>|<uuid>|<device>|<label>]\nShow the btrfs filesystem with some additional info about devices and space allocation.\n\nIf no option none of path/uuid/device/label is passed, information about all the BTRFS\nfilesystems is shown, both mounted and unmounted.\n\nOptions\n\n-m|--mounted\nprobe kernel for mounted BTRFS filesystems\n\n-d|--all-devices\nscan all devices under /dev, otherwise the devices list is extracted from the\n/proc/partitions file. This is a fallback option if there’s no device node manager\n(like udev) available in the system.\n\n--raw\nraw numbers in bytes, without the B suffix\n\n--human-readable\nprint human friendly numbers, base 1024, this is the default\n\n--iec\nselect the 1024 base for the following options, according to the IEC standard\n\n--si\nselect the 1000 base for the following options, according to the SI standard\n\n--kbytes\nshow sizes in KiB, or kB with --si\n\n--mbytes\nshow sizes in MiB, or MB with --si\n\n--gbytes\nshow sizes in GiB, or GB with --si\n\n--tbytes\nshow sizes in TiB, or TB with --si\n\nsync <path>\nForce a sync of the filesystem at path, similar to the sync(1) command. In addition, it\nstarts cleaning of deleted subvolumes. To wait for the subvolume deletion to complete use\nthe btrfs subvolume sync command.\n\nusage [options] <path> [<path>...]\nShow detailed information about internal filesystem usage. This is supposed to replace\nthe btrfs filesystem df command in the long run.\n\nThe level of detail can differ if the command is run under a regular or the root user\n(due to use of restricted ioctl). For both there’s a summary section with information\nabout space usage:\n\n$ btrfs filesystem usage /path\nWARNING: cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root\nOverall:\nDevice size:                   1.82TiB\nDevice allocated:              1.17TiB\nDevice unallocated:          669.99GiB\nDevice missing:                  0.00B\nUsed:                          1.14TiB\nFree (estimated):            692.57GiB      (min: 692.57GiB)\nFree (statfs, df)            692.57GiB\nData ratio:                       1.00\nMetadata ratio:                   1.00\nGlobal reserve:              512.00MiB      (used: 0.00B)\nMultiple profiles:                  no\n\n•   Device size — sum of raw device capacity available to the filesystem\n\n•   Device allocated — sum of total space allocated for data/metadata/system profiles,\nthis also accounts space reserved but not yet used for extents\n\n•   Device unallocated — the remaining unallocated space for future allocations\n(difference of the above two numbers)\n\n•   Device missing — sum of capacity of all missing devices\n\n•   Used — sum of the used space of data/metadata/system profiles, not including the\nreserved space\n\n•   Free (estimated) — approximate size of the remaining free space usable for data,\nincluding currently allocated space and estimating the usage of the unallocated space\nbased on the block group profiles, the min is the lower bound of the estimate in case\nmultiple profiles are present\n\n•   Free (statfs, df) — the amount of space available for data as reported by the statfs\nsyscall, also returned as Avail in the output of df. The value is calculated in a\ndifferent way and may not match the estimate in some cases (eg. multiple profiles).\n\n•   Data ratio — ratio of total space for data including redundancy or parity to the\neffectively usable data space, eg. single is 1.0, RAID1 is 2.0 and for RAID5/6 it\ndepends on the number of devices\n\n•   Metadata ratio — dtto, for metadata\n\n•   Global reserve — portion of metadata currently used for global block reserve, used\nfor emergency purposes (like deletion on a full filesystem)\n\n•   Multiple profiles — what block group types (data, metadata) have more than one\nprofile (single, raid1, ...), see btrfs(5) section FILESYSTEMS WITH MULTIPLE BLOCK\nGROUP PROFILES.\n\nAnd on a zoned filesystem there are two more lines in the Device section:\n\nDevice zone unusable:          5.13GiB\nDevice zone size:            256.00MiB\n\n•   Device zone unusable — sum of of space that’s been used in the past but now is not\ndue to COW and not referenced anymory, the chunks have to be reclaimed and zones\nreset to make it usable again\n\n•   Device zone size — the reported zone size of the host-managed device, same for all\ndevices\n\nThe root user will also see stats broken down by block group types:\n\nData,single: Size:1.15TiB, Used:1.13TiB (98.26%)\n/dev/sdb        1.15TiB\n\nMetadata,single: Size:12.00GiB, Used:6.45GiB (53.75%)\n/dev/sdb       12.00GiB\n\nSystem,single: Size:32.00MiB, Used:144.00KiB (0.44%)\n/dev/sdb       32.00MiB\n\nUnallocated:\n/dev/sdb      669.99GiB\n\nData is block group type, single is block group profile, Size is total size occupied by\nthis type, Used is the actually used space, the percent is ratio of Used/Size. The\nUnallocated is remaining space.\n\nOptions\n\n-b|--raw\nraw numbers in bytes, without the B suffix\n\n-h|--human-readable\nprint human friendly numbers, base 1024, this is the default\n\n-H\nprint human friendly numbers, base 1000\n\n--iec\nselect the 1024 base for the following options, according to the IEC standard\n\n--si\nselect the 1000 base for the following options, according to the SI standard\n\n-k|--kbytes\nshow sizes in KiB, or kB with --si\n\n-m|--mbytes\nshow sizes in MiB, or MB with --si\n\n-g|--gbytes\nshow sizes in GiB, or GB with --si\n\n-t|--tbytes\nshow sizes in TiB, or TB with --si\n\n-T\nshow data in tabular format\n\nIf conflicting options are passed, the last one takes precedence.\n\n### EXAMPLES\n\n#### $ btrfs filesystem defrag -v -r dir/\n\nRecursively defragment files under dir/, print files as they are processed. The file names\nwill be printed in batches, similarly the amount of data triggered by defragmentation will be\nproportional to last N printed files. The system dirty memory throttling will slow down the\ndefragmentation but there can still be a lot of IO load and the system may stall for a\nmoment.\n\n#### $ btrfs filesystem defrag -v -r -f dir/\n\nRecursively defragment files under dir/, be verbose and wait until all blocks are flushed\nbefore processing next file. You can note slower progress of the output and lower IO load\n(proportional to currently defragmented file).\n\n#### $ btrfs filesystem defrag -v -r -f -clzo dir/\n\nRecursively defragment files under dir/, be verbose, wait until all blocks are flushed and\nforce file compression.\n\n#### $ btrfs filesystem defrag -v -r -t 64M dir/\n\nRecursively defragment files under dir/, be verbose and try to merge extents to be about\n64MiB. As stated above, the success rate depends on actual free space fragmentation and the\nfinal result is not guaranteed to meet the target even if run repeatedly.\n\n#### $ btrfs filesystem resize -1G /path\n\n#### $ btrfs filesystem resize 1:-1G /path\n\nShrink size of the filesystem’s device id 1 by 1GiB. The first syntax expects a device with\nid 1 to exist, otherwise fails. The second is equivalent and more explicit. For a\nsingle-device filesystem it’s typically not necessary to specify the devid though.\n\n#### $ btrfs filesystem resize max /path\n\n#### $ btrfs filesystem resize 1:max /path\n\nLet’s assume that devid 1 exists and the filesystem does not occupy the whole block device,\neg. it has been enlarged and we want to grow the filesystem. By simply using max as size we\nwill achieve that.\n\nNote\nThere are two ways to minimize the filesystem on a given device. The btrfs\ninspect-internal min-dev-size command, or iteratively shrink in steps.\n\n### EXIT STATUS\n\nbtrfs filesystem 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\nbtrfs-subvolume(8), mkfs.btrfs(8),\n\n\n\nBtrfs v5.16.2                                02/16/2022                          BTRFS-FILESYSTEM(8)\n\n"
        }
    ],
    "structuredContent": {
        "command": "btrfs-filesystem",
        "section": "8",
        "mode": "man",
        "summary": "btrfs-filesystem - command group that primarily does work on the whole filesystems",
        "synopsis": "btrfs filesystem <subcommand> <args>",
        "flags": [],
        "examples": [
            "Recursively defragment files under dir/, print files as they are processed. The file names",
            "will be printed in batches, similarly the amount of data triggered by defragmentation will be",
            "proportional to last N printed files. The system dirty memory throttling will slow down the",
            "defragmentation but there can still be a lot of IO load and the system may stall for a",
            "moment.",
            "Recursively defragment files under dir/, be verbose and wait until all blocks are flushed",
            "before processing next file. You can note slower progress of the output and lower IO load",
            "(proportional to currently defragmented file).",
            "Recursively defragment files under dir/, be verbose, wait until all blocks are flushed and",
            "force file compression.",
            "Recursively defragment files under dir/, be verbose and try to merge extents to be about",
            "64MiB. As stated above, the success rate depends on actual free space fragmentation and the",
            "final result is not guaranteed to meet the target even if run repeatedly.",
            "Shrink size of the filesystem’s device id 1 by 1GiB. The first syntax expects a device with",
            "id 1 to exist, otherwise fails. The second is equivalent and more explicit. For a",
            "single-device filesystem it’s typically not necessary to specify the devid though.",
            "Let’s assume that devid 1 exists and the filesystem does not occupy the whole block device,",
            "eg. it has been enlarged and we want to grow the filesystem. By simply using max as size we",
            "will achieve that.",
            "Note",
            "There are two ways to minimize the filesystem on a given device. The btrfs",
            "inspect-internal min-dev-size command, or iteratively shrink in steps."
        ],
        "see_also": [
            {
                "name": "btrfs-subvolume",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-subvolume/8/json"
            },
            {
                "name": "mkfs.btrfs",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/mkfs.btrfs/8/json"
            },
            {
                "name": "BTRFS-FILESYSTEM",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/BTRFS-FILESYSTEM/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SUBCOMMAND",
                "lines": 383,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 1,
                "subsections": [
                    {
                        "name": "$ btrfs filesystem defrag -v -r dir/",
                        "lines": 6
                    },
                    {
                        "name": "$ btrfs filesystem defrag -v -r -f dir/",
                        "lines": 4
                    },
                    {
                        "name": "$ btrfs filesystem defrag -v -r -f -clzo dir/",
                        "lines": 3
                    },
                    {
                        "name": "$ btrfs filesystem defrag -v -r -t 64M dir/",
                        "lines": 4
                    },
                    {
                        "name": "$ btrfs filesystem resize -1G /path",
                        "lines": 1
                    },
                    {
                        "name": "$ btrfs filesystem resize 1:-1G /path",
                        "lines": 4
                    },
                    {
                        "name": "$ btrfs filesystem resize max /path",
                        "lines": 1
                    },
                    {
                        "name": "$ btrfs filesystem resize 1:max /path",
                        "lines": 8
                    }
                ]
            },
            {
                "name": "EXIT STATUS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AVAILABILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}