6 btrfs-filesystem - command group of btrfs that usually work on the whole filesystem
10 *btrfs filesystem* <subcommand> <args>
14 *btrfs filesystem* is used to do the whole filesystem level tasks, including
15 all the regular filesystem operations like resizing, space stats, label
16 setting/getting, and defragmentation.
20 *df* [options] <path>::
21 Show a terse summary information about allocation of block group types of a given
22 mount point. The original purpose of this command was a debugging helper. The
23 output needs to be further interpreted and is not suitable for quick overview.
26 An example with description:
28 * device size: '1.9TiB', one device, no RAID
29 * filesystem size: '1.9TiB'
30 * created with: 'mkfs.btrfs -d single -m single'
33 ------------------------------
34 $ btrfs filesystem df /path
35 Data, single: total=1.15TiB, used=1.13TiB
36 System, single: total=32.00MiB, used=144.00KiB
37 Metadata, single: total=12.00GiB, used=6.45GiB
38 GlobalReserve, single: total=512.00MiB, used=0.00B
39 ------------------------------
42 * 'Data', 'System' and 'Metadata' are separeate block group types.
43 'GlobalReserve' is an artificial and internal emergency space, see below.
44 * 'single' -- the allocation profile, defined at mkfs time
45 * 'total' -- sum of space reserved for
46 all allocation profiles of the given type, ie. all Data/single. Note that it's
47 not total size of filesystem.
48 * 'used' -- sum of used space of the above, ie. file extents, metadata blocks
51 'GlobalReserve' is an artificial and internal emergency space. It is used eg.
52 when the filesystem is full. Its 'total' size is dynamic based on the
53 filesystem size, usually not larger than 512MiB, 'used' may fluctuate.
55 The global block reserve is accounted within Metadata. In case the filesystem
56 metadata are exhausted, 'GlobalReserve/total + Metadata/used = Metadata/total'.
61 raw numbers in bytes, without the 'B' suffix
62 -h|--human-readable::::
63 print human friendly numbers, base 1024, this is the default
65 print human friendly numbers, base 1000
67 select the 1024 base for the following options, according to the IEC standard
69 select the 1000 base for the following options, according to the SI standard
71 show sizes in KiB, or kB with --si
73 show sizes in MiB, or MB with --si
75 show sizes in GiB, or GB with --si
77 show sizes in TiB, or TB with --si
79 If conflicting options are passed, the last one takes precedence.
81 *defragment* [options] <file>|<dir> [<file>|<dir>...]::
82 Defragment file data on a mounted filesytem.
84 If '-r' is passed, files in dir will be defragmented recursively.
85 The start position and the number of bytes to defragment can be specified by
86 start and len using '-s' and '-l' options below.
87 Extents bigger than value given by '-t' will be skipped, otherwise this value
88 is used as a target extent size, but is only advisory and may not be reached
89 if the free space is too fragmented.
90 Use 0 to take the kernel default, which is 256kB but may change in the future.
91 You can also turn on compression in defragment operations.
93 WARNING: Defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as
94 with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up
95 the ref-links of COW data (for example files copied with `cp --reflink`,
96 snapshots or de-duplicated data).
97 This may cause considerable increase of space usage depending on the broken up
103 be verbose, print file names as they're submitted for defragmentation
105 compress file contents while defragmenting. Optional argument selects the compression
106 algorithm, 'zlib' (default) or 'lzo'. Currently it's not possible to select no
107 compression. See also section 'EXAMPLES'.
109 defragment files recursively in given directories
111 flush data for each file before going to the next file. This will limit the amount
112 of dirty data to current file, otherwise the amount cumulates from several files
113 and may increase system load.
114 -s <start>[kKmMgGtTpPeE]::::
115 defragmentation will start from the given offset, default is beginning of a file
116 -l <len>[kKmMgGtTpPeE]::::
117 defragment only up to 'len' bytes, default is the file size
118 -t <size>[kKmMgGtTpPeE]::::
119 target extent size, do not touch extents bigger than 'size'
121 For 'start', 'len', 'size' it is possible to append
122 units designator: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
123 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
125 NOTE: Directory arguments without '-r' do not defragment files recursively but will
126 defragment certain internal trees (extent tree and the subvolume tree). This has been
127 confusing and could be removed in the future.
129 *label* [<dev>|<mountpoint>] [<newlabel>]::
130 Show or update the label of a filesystem. This works on a mounted filesystem or
133 The 'newlabel' argument is optional. Current label is printed if the the argument
136 NOTE: the maximum allowable length shall be less than 256 chars and must not contain
137 a newline. The trailing newline is stripped automatically.
139 // Some wording are extracted by the resize2fs man page
140 *resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>::
141 Resize a mounted filesystem identified by 'path'. A particular device
142 can be resized by specifying a 'devid'.
144 WARNING: If 'path' is a file containing a BTRFS image then resize does not work
145 as expected and does not resize the image. This would resize the underlying
148 The 'devid' can be found in the output of *btrfs filesystem show* and
149 defaults to 1 if not specified.
150 The 'size' parameter specifies the new size of the filesystem.
151 If the prefix '+' or '-' is present the size is increased or decreased
152 by the quantity 'size'.
153 If no units are specified, bytes are assumed for 'size'.
154 Optionally, the size parameter may be suffixed by one of the following
155 units designators: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
156 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
158 If 'max' is passed, the filesystem will occupy all available space on the
159 device respecting 'devid' (remember, devid 1 by default).
161 The resize command does not manipulate the size of underlying
162 partition. If you wish to enlarge/reduce a filesystem, you must make sure you
163 can expand the partition before enlarging the filesystem and shrink the
164 partition after reducing the size of the filesystem. This can done using
165 `fdisk`(8) or `parted`(8) to delete the existing partition and recreate
166 it with the new desired size. When recreating the partition make sure to use
167 the same starting partition offset as before.
169 Growing is usually instant as it only updates the size. However, shrinking could
170 take a long time if there are data in the device area that's beyond the new
171 end. Relocation of the data takes time.
173 See also section 'EXAMPLES'.
175 *show* [options] [<path>|<uuid>|<device>|<label>]::
176 Show the btrfs filesystem with some additional info about devices and space
179 If no option none of 'path'/'uuid'/'device'/'label' is passed, information
180 about all the BTRFS filesystems is shown, both mounted and unmounted.
185 probe kernel for mounted BTRFS filesystems
187 scan all devices under /dev, otherwise the devices list is extracted from the
188 /proc/partitions file. This is a fallback option if there's no device node
189 manager (like udev) available in the system.
191 raw numbers in bytes, without the 'B' suffix
193 print human friendly numbers, base 1024, this is the default
195 select the 1024 base for the following options, according to the IEC standard
197 select the 1000 base for the following options, according to the SI standard
199 show sizes in KiB, or kB with --si
201 show sizes in MiB, or MB with --si
203 show sizes in GiB, or GB with --si
205 show sizes in TiB, or TB with --si
208 Force a sync of the filesystem at 'path'. This is done via a special ioctl and
209 will also trigger cleaning of deleted subvolumes. Besides that it's equivalent
210 to the `sync`(1) command.
212 *usage* [options] <path> [<path>...]::
213 Show detailed information about internal filesystem usage. This is supposed to
214 replace the *btrfs filesystem df* command in the long run.
216 The level of detail can differ if the command is run under a regular or the
217 root user (due to use of restricted ioctl). For both there's a summary section
218 with information about space usage:
220 -------------------------
221 $ btrfs fi usage /path
222 WARNING: cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root
225 Device allocated: 1.17TiB
226 Device unallocated: 669.99GiB
227 Device missing: 0.00B
229 Free (estimated): 692.57GiB (min: 692.57GiB)
232 Global reserve: 512.00MiB (used: 0.00B)
233 -------------------------
235 The root user will also see stats broken down by block group types:
237 -------------------------
238 Data,single: Size:1.15TiB, Used:1.13TiB
241 Metadata,single: Size:12.00GiB, Used:6.45GiB
244 System,single: Size:32.00MiB, Used:144.00KiB
249 -------------------------
254 raw numbers in bytes, without the 'B' suffix
255 -h|--human-readable::::
256 print human friendly numbers, base 1024, this is the default
258 print human friendly numbers, base 1000
260 select the 1024 base for the following options, according to the IEC standard
262 select the 1000 base for the following options, according to the SI standard
264 show sizes in KiB, or kB with --si
266 show sizes in MiB, or MB with --si
268 show sizes in GiB, or GB with --si
270 show sizes in TiB, or TB with --si
272 show data in tabular format
274 If conflicting options are passed, the last one takes precedence.
279 *$ btrfs filesystem defrag -v -r dir/*
281 Recursively defragment files under 'dir/', print files as they are processed.
282 The file names will be printed in batches, similarly the amount of data triggered
283 by defragmentation will be proportional to last N printed files. The system dirty
284 memory throttling will slow down the defragmentation but there can still be a lot
285 of IO load and the system may stall for a moment.
287 *$ btrfs filesystem defrag -v -r -f dir/*
289 Recusively defragment files under 'dir/', be verbose and wait until all blocks
290 are flushed before processing next file. You can note slower progress of the
291 output and lower IO load (proportional to currently defragmented file).
293 *$ btrfs filesystem defrag -v -r -f -clzo dir/*
295 Recusively defragment files under 'dir/', be verbose, wait until all blocks are
296 flushed and force file compression.
298 *$ btrfs filesystem defrag -v -r -t 64M dir/*
300 Recusively defragment files under 'dir/', be verbose and try to merge extents
301 to be about 64MiB. As stated above, the success rate depends on actual free
302 space fragmentation and the final result is not guaranteed to meet the target
303 even if run repeatedly.
305 *$ btrfs filesystem resize -1G /path*
307 *$ btrfs filesystem resize 1:-1G /path*
309 Shrink size of the filesystem's device id 1 by 1GiB. The first syntax expects a
310 device with id 1 to exist, otherwise fails. The second is equivalent and more
311 explicit. For a single-device filesystem it's typically not necessary to
312 specify the devid though.
314 *$ btrfs filesystem resize max /path*
316 *$ btrfs filesystem resize 1:max /path*
318 Let's assume that devid 1 exists, the filesystem does not occupy the whole block
319 device, eg. it has been enlarged and we wan the grow the filesystem. Simply using
320 'max' as size we will achieve that.
322 NOTE: There are two ways to minimize the filesystem on a given device. The
323 *btrfs inspect-internal min-dev-size* command, or iteratively shrink in steps.
327 *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
328 returned in case of failure.
332 *btrfs* is part of btrfs-progs.
333 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for