{
    "mode": "man",
    "parameter": "BTRFS-FILESYSTEM",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/BTRFS-FILESYSTEM/8/json",
    "generated": "2026-10-05T14:58:15Z",
    "synopsis": "btrfs filesystem <subcommand> <args>",
    "sections": {
        "NAME": {
            "content": "btrfs-filesystem - command group that primarily does work on the whole filesystems\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "btrfs filesystem <subcommand> <args>\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "btrfs  filesystem  is used to perform several whole filesystem level tasks, including all the\nregular filesystem operations like resizing, space stats, label setting/getting, and  defrag‐\nmentation.  There  are other whole filesystem tasks like scrub or balance that are grouped in\nseparate commands.\n",
            "subsections": []
        },
        "SUBCOMMAND": {
            "content": "",
            "subsections": [
                {
                    "name": "df [options] <path>",
                    "content": "Show a terse summary information about allocation of block  group  types  of  a  given\nmount  point.  The original purpose of this command was a debugging helper. The output\nneeds to be 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 arti‐\nficial 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,  i.e.\nall Data/single. Note that it's not total size of filesystem.\n\n• used -- sum of used space of the above, i.e. file extents, metadata blocks\n\nGlobalReserve is an artificial and internal emergency space. It is used e.g.  when the\nfilesystem  is  full.  Its total size is dynamic based on the filesystem size, usually\nnot larger than 512MiB, used may fluctuate.\n\nThe GlobalReserve is a portion of Metadata. In case the  filesystem  metadata  is  ex‐\nhausted, GlobalReserve/total + Metadata/used = Metadata/total. Otherwise there appears\nto be some unused 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     print human friendly numbers, base 1000\n\n--iec  select the 1024 base for the following options, according to the IEC standard\n\n--si   select 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"
                },
                {
                    "name": "defragment [options] <file>|<dir> [<file>|<dir>...]",
                    "content": "Defragment 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 sub‐\nvolumes,  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  be‐\nlow.   Extents  bigger than value given by -t will be skipped, otherwise this value is\nused as a target extent size, but is only advisory and may not be reached if the  free\nspace  is  too  fragmented.  Use 0 to take the kernel default, which is 256KiB but may\nchange in the future.  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\nof COW 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\nup reflinks.\n\nNOTE:\nDirectory arguments without -r do not defragment files recursively but will defrag‐\nment certain internal trees (extent tree and the subvolume  tree).  This  has  been\nconfusing and could be removed in the future.\n\nFor  start,  len, size it is possible to append units designator: K, M, G, T, P, or E,\nwhich represent KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).\n\nOptions\n\n-c[<algo>]\ncompress file contents while defragmenting. Optional argument selects the  com‐\npression algorithm, zlib (default), lzo or zstd. Currently it's not possible to\nselect no compression. See also section EXAMPLES.\n\n-r     defragment  files recursively in given directories, does not descend to subvol‐\numes or mount points\n\n-f     flush 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\nlead to ENOSPC if there's too much dirty data to write and it's not possible to\nmake the reservations for the new data (i.e. how the COW design works).\n\n-s <start>[kKmMgGtTpPeE]\ndefragmentation will start from the given offset, default  is  beginning  of  a\nfile\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: 32MiB\n\nThe  value  is  only advisory and the final size of the extents may differ, de‐\npending on the state of the free space  and  fragmentation  or  other  internal\nlogic. Reasonable values are from tens to hundreds of megabytes.\n\n--step SIZE\nPerform defragmention in the range in SIZE steps and flush (-f) after each one.\nThe  range  is  default  (the whole file) or given by -s and -l, split into the\nsteps or done in one go if the step is larger. Minimum range size is 256KiB.\n"
                },
                {
                    "name": "-v     (deprecated)",
                    "content": "",
                    "flag": "-v"
                },
                {
                    "name": "du [options] <path> [<path>..]",
                    "content": "Calculate 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\n'set shared' value which is described below.\n\nEach argument to btrfs filesystem du will have a set shared value calculated  for  it.\nWe  define  each set as those files found by a recursive search of an argument (recur‐\nsion descends to subvolumes but not mount points). The set shared value then is a  sum\nof all shared 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  raw numbers in bytes, without the B suffix.\n\n--human-readable\nprint human friendly numbers, base 1024, this is the default\n\n--iec  select the 1024 base for the following options, according to the IEC standard.\n\n--si   select 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"
                },
                {
                    "name": "label [<device>|<mountpoint>] [<newlabel>]",
                    "content": "Show 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 omit‐\nted.\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"
                },
                {
                    "name": "mkswapfile [-s size] file",
                    "content": "Create  a  new file that's suitable and formatted as a swapfile. Default size is 2GiB,\nfixed page size 4KiB, minimum size is 40KiB.\n\nA swapfile must be created in a specific way: NOCOW and preallocated.  Subvolume  con‐\ntaining a swapfile cannot be snapshotted and blocks of an activated swapfile cannot be\nbalanced.\n\nSwapfile  creation  can be achieved by standalone commands too. Activation needs to be\ndone by command swapon(8). See also command btrfs  inspect-internal  map-swapfile  and\nthe Swapfile feature description.\n\nNOTE:\nThe  command  is  a  simplified version of 'mkswap', if you want to set label, page\nsize, or other parameters please use 'mkswap' proper.\n\nOptions\n\n-s|--size SIZE\nCreate swapfile of a given size SIZE (accepting k/m/g/e/p suffix).\n\n-U|--uuid UUID\nspecify UUID to use, or a  special  value:  clear  (all  zeros),  random,  time\n(time-based random)\n"
                },
                {
                    "name": "resize [options] [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>",
                    "content": "Resize  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\nand does not resize the image. This would resize the underlying filesystem instead.\n\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 pre‐\nfix + or - is present the size is increased or decreased by the quantity size.  If  no\nunits  are  specified, bytes are assumed for size.  Optionally, the size parameter may\nbe suffixed by one of the following unit designators: K, M, G, T, P, or E, which  rep‐\nresent KiB, 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 re‐\nspecting devid (remember, devid 1 by default).\n\nThe resize command does not manipulate the size of underlying partition.  If you  wish\nto enlarge/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  parti‐\ntion  and  recreate  it with the new desired size.  When recreating the partition make\nsure to use the same starting partition offset as before.\n\nGrowing is usually instant as it only updates the size. However, shrinking could  take\na long time if there are data in the device area that's beyond the new end. Relocation\nof the data takes time.\n\nSee also section EXAMPLES.\n\nOptions\n\n--enqueue\nwait if there's another exclusive operation running, otherwise continue\n"
                },
                {
                    "name": "show [options] [<path>|<uuid>|<device>|<label>]",
                    "content": "Show  the  btrfs  filesystem with some additional info about devices and space alloca‐\ntion.\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 man‐\nager (like udev) available in the system.\n\n--raw  raw numbers in bytes, without the B suffix\n\n--human-readable\nprint human friendly numbers, base 1024, this is the default\n\n--iec  select the 1024 base for the following options, according to the IEC standard\n\n--si   select 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"
                },
                {
                    "name": "sync <path>",
                    "content": "Force  a  sync of the filesystem at path, similar to the sync(1) command. In addition,\nit starts cleaning of deleted subvolumes. To wait for the subvolume deletion  to  com‐\nplete use the btrfs subvolume sync command.\n"
                },
                {
                    "name": "usage [options] <path> [<path>...]",
                    "content": "Show 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\nDevice slack:                  1.00GiB\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, note that\nthis may not be the same as the total device size (the difference  is  accounted  as\nslack)\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  (dif‐\nference of the above two numbers)\n\n• Device missing -- sum of capacity of all missing devices\n\n• Device  slack -- sum of slack space on all devices (difference between entire device\nsize and the space occupied by filesystem)\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\nspace  based on the block group profiles, the min is the lower bound of the estimate\nin case multiple profiles are present\n\n• Free (statfs, df) -- the amount of space available  for  data  as  reported  by  the\nstatfs/statvfs  syscall,  also  returned  as Avail in the output of df. The value is\ncalculated in a different way and may not match the estimate  in  some  cases  (e.g.\nmultiple profiles).\n\n• Data  ratio  --  ratio of total space for data including redundancy or parity to the\neffectively usable data space, e.g. single is 1.0, RAID1 is 2.0 and for  RAID5/6  it\ndepends on the number of devices\n\n• Metadata ratio -- ditto, 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 pro‐\nfile (single, raid1, ...), see btrfs(5) section FILESYSTEMS WITH MULTIPLE 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 anymore, the chunks have to be reclaimed and zones re‐\nset 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\nby  this 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     print human friendly numbers, base 1000\n\n--iec  select the 1024 base for the following options, according to the IEC standard\n\n--si   select 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     show data in tabular format\n\nIf conflicting options are passed, the last one takes precedence.\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "",
            "subsections": [
                {
                    "name": "$ btrfs filesystem defrag -v -r dir/",
                    "content": "Recursively 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  mo‐\nment.\n"
                },
                {
                    "name": "$ btrfs filesystem defrag -v -r -f dir/",
                    "content": "Recursively defragment files under dir/, be verbose and wait until all blocks are flushed be‐\nfore processing next file. You can note slower progress of the output and lower IO load (pro‐\nportional to currently defragmented file).\n"
                },
                {
                    "name": "$ btrfs filesystem defrag -v -r -f -clzo dir/",
                    "content": "Recursively  defragment  files  under dir/, be verbose, wait until all blocks are flushed and\nforce file compression.\n"
                },
                {
                    "name": "$ btrfs filesystem defrag -v -r -t 64M dir/",
                    "content": "Recursively 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"
                },
                {
                    "name": "$ btrfs filesystem resize -1G /path",
                    "content": ""
                },
                {
                    "name": "$ btrfs filesystem resize 1:-1G /path",
                    "content": "Shrink 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 single-de‐\nvice filesystem it's typically not necessary to specify the devid though.\n"
                },
                {
                    "name": "$ btrfs filesystem resize max /path",
                    "content": ""
                },
                {
                    "name": "$ btrfs filesystem resize 1:max /path",
                    "content": "Let's assume that devid 1 exists and the filesystem does not occupy the whole  block  device,\ne.g.  it has been enlarged and we want to grow the filesystem. By simply using max as size we\nwill achieve that.\n"
                },
                {
                    "name": "NOTE:",
                    "content": "There are two ways to minimize the filesystem on a given device. The btrfs  inspect-inter‐\nnal min-dev-size command, or iteratively shrink in steps.\n"
                }
            ]
        },
        "EXIT STATUS": {
            "content": "btrfs  filesystem  returns a zero exit status if it succeeds. Non zero is returned in case of\nfailure.\n",
            "subsections": []
        },
        "AVAILABILITY": {
            "content": "btrfs   is   part   of   btrfs-progs.     Please    refer    to    the    documentation    at\nhttps://btrfs.readthedocs.io.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "btrfs-subvolume(8), mkfs.btrfs(8)\n\n\n6.6.3                                       Mar 31, 2024                         BTRFS-FILESYSTEM(8)",
            "subsections": []
        }
    },
    "summary": "btrfs-filesystem - command group that primarily does work on the whole filesystems",
    "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  mo‐",
        "ment.",
        "Recursively defragment files under dir/, be verbose and wait until all blocks are flushed be‐",
        "fore processing next file. You can note slower progress of the output and lower IO load (pro‐",
        "portional 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-de‐",
        "vice 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,",
        "e.g.  it has been enlarged and we want to grow the filesystem. By simply using max as size we",
        "will achieve that.",
        "There are two ways to minimize the filesystem on a given device. The btrfs  inspect-inter‐",
        "nal 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"
        }
    ]
}