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 perform several whole filesystem level tasks,
15 including all the regular filesystem operations like resizing, space stats,
16 label setting/getting, and defragmentation. There are other whole filesystem
17 taks like scrub or balance that are grouped in separate commands.
21 *df* [options] <path>::
22 Show a terse summary information about allocation of block group types of a given
23 mount point. The original purpose of this command was a debugging helper. The
24 output needs to be further interpreted and is not suitable for quick overview.
27 An example with description:
29 * device size: '1.9TiB', one device, no RAID
30 * filesystem size: '1.9TiB'
31 * created with: 'mkfs.btrfs -d single -m single'
34 ------------------------------
35 $ btrfs filesystem df /path
36 Data, single: total=1.15TiB, used=1.13TiB
37 System, single: total=32.00MiB, used=144.00KiB
38 Metadata, single: total=12.00GiB, used=6.45GiB
39 GlobalReserve, single: total=512.00MiB, used=0.00B
40 ------------------------------
43 * 'Data', 'System' and 'Metadata' are separate block group types.
44 'GlobalReserve' is an artificial and internal emergency space, see below.
45 * 'single' -- the allocation profile, defined at mkfs time
46 * 'total' -- sum of space reserved for
47 all allocation profiles of the given type, ie. all Data/single. Note that it's
48 not total size of filesystem.
49 * 'used' -- sum of used space of the above, ie. file extents, metadata blocks
52 'GlobalReserve' is an artificial and internal emergency space. It is used eg.
53 when the filesystem is full. Its 'total' size is dynamic based on the
54 filesystem size, usually not larger than 512MiB, 'used' may fluctuate.
56 The global block reserve is accounted within Metadata. In case the filesystem
57 metadata are exhausted, 'GlobalReserve/total + Metadata/used = Metadata/total'.
62 raw numbers in bytes, without the 'B' suffix
63 -h|--human-readable::::
64 print human friendly numbers, base 1024, this is the default
66 print human friendly numbers, base 1000
68 select the 1024 base for the following options, according to the IEC standard
70 select the 1000 base for the following options, according to the SI standard
72 show sizes in KiB, or kB with --si
74 show sizes in MiB, or MB with --si
76 show sizes in GiB, or GB with --si
78 show sizes in TiB, or TB with --si
80 If conflicting options are passed, the last one takes precedence.
82 *defragment* [options] <file>|<dir> [<file>|<dir>...]::
83 Defragment file data on a mounted filesystem.
85 If '-r' is passed, files in dir will be defragmented recursively.
86 The start position and the number of bytes to defragment can be specified by
87 start and length using '-s' and '-l' options below.
88 Extents bigger than value given by '-t' will be skipped, otherwise this value
89 is used as a target extent size, but is only advisory and may not be reached
90 if the free space is too fragmented.
91 Use 0 to take the kernel default, which is 256kB but may change in the future.
92 You can also turn on compression in defragment operations.
94 WARNING: Defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as
95 with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up
96 the ref-links of COW data (for example files copied with `cp --reflink`,
97 snapshots or de-duplicated data).
98 This may cause considerable increase of space usage depending on the broken up
101 NOTE: Directory arguments without '-r' do not defragment files recursively but will
102 defragment certain internal trees (extent tree and the subvolume tree). This has been
103 confusing and could be removed in the future.
105 For 'start', 'len', 'size' it is possible to append
106 units designator: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
107 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
112 be verbose, print file names as they're submitted for defragmentation
114 compress file contents while defragmenting. Optional argument selects the compression
115 algorithm, 'zlib' (default) or 'lzo'. Currently it's not possible to select no
116 compression. See also section 'EXAMPLES'.
118 defragment files recursively in given directories
120 flush data for each file before going to the next file.
122 This will limit the amount of dirty data to current file, otherwise the amount
123 cumulates from several files and will increase system load. This can also lead
124 to ENOSPC if there's too much dirty data to write and it's not possible to make
125 the reservations for the new data (ie. how the COW design works).
127 -s <start>[kKmMgGtTpPeE]::::
128 defragmentation will start from the given offset, default is beginning of a file
129 -l <len>[kKmMgGtTpPeE]::::
130 defragment only up to 'len' bytes, default is the file size
131 -t <size>[kKmMgGtTpPeE]::::
132 target extent size, do not touch extents bigger than 'size', default: 32M
134 The value is only advisory and the final size of the extents may differ,
135 depending on the state of the free space and fragmentation or other internal
136 logic. Reasonable values are from tens to hundreds of megabytes.
138 *du* [options] <path> [<path>..]::
139 Calculate disk usage of the target files using FIEMAP. For individual
140 files, it will report a count of total bytes, and exclusive (not
141 shared) bytes. We also calculate a 'set shared' value which is
144 Each argument to 'btrfs fi du' will have a 'set shared' value
145 calculated for it. We define each 'set' as those files found by a
146 recursive search of an argument. The 'set shared' value
147 then is a sum of all shared space referenced by the set.
149 'set shared' takes into account overlapping shared extents, hence it
150 isn't as simple as adding up shared extents.
155 display only a total for each argument
157 raw numbers in bytes, without the 'B' suffix.
159 print human friendly numbers, base 1024, this is the default
161 select the 1024 base for the following options, according to the IEC standard.
163 select the 1000 base for the following options, according to the SI standard.
165 show sizes in KiB, or kB with --si.
167 show sizes in MiB, or MB with --si.
169 show sizes in GiB, or GB with --si.
171 show sizes in TiB, or TB with --si.
173 *label* [<dev>|<mountpoint>] [<newlabel>]::
174 Show or update the label of a filesystem. This works on a mounted filesystem or
177 The 'newlabel' argument is optional. Current label is printed if the the argument
180 NOTE: the maximum allowable length shall be less than 256 chars and must not contain
181 a newline. The trailing newline is stripped automatically.
183 // Some wording are extracted by the resize2fs man page
184 *resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>::
185 Resize a mounted filesystem identified by 'path'. A particular device
186 can be resized by specifying a 'devid'.
188 WARNING: If 'path' is a file containing a BTRFS image then resize does not work
189 as expected and does not resize the image. This would resize the underlying
192 The 'devid' can be found in the output of *btrfs filesystem show* and
193 defaults to 1 if not specified.
194 The 'size' parameter specifies the new size of the filesystem.
195 If the prefix '+' or '-' is present the size is increased or decreased
196 by the quantity 'size'.
197 If no units are specified, bytes are assumed for 'size'.
198 Optionally, the size parameter may be suffixed by one of the following
199 units designators: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
200 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
202 If 'max' is passed, the filesystem will occupy all available space on the
203 device respecting 'devid' (remember, devid 1 by default).
205 The resize command does not manipulate the size of underlying
206 partition. If you wish to enlarge/reduce a filesystem, you must make sure you
207 can expand the partition before enlarging the filesystem and shrink the
208 partition after reducing the size of the filesystem. This can done using
209 `fdisk`(8) or `parted`(8) to delete the existing partition and recreate
210 it with the new desired size. When recreating the partition make sure to use
211 the same starting partition offset as before.
213 Growing is usually instant as it only updates the size. However, shrinking could
214 take a long time if there are data in the device area that's beyond the new
215 end. Relocation of the data takes time.
217 See also section 'EXAMPLES'.
219 *show* [options] [<path>|<uuid>|<device>|<label>]::
220 Show the btrfs filesystem with some additional info about devices and space
223 If no option none of 'path'/'uuid'/'device'/'label' is passed, information
224 about all the BTRFS filesystems is shown, both mounted and unmounted.
229 probe kernel for mounted BTRFS filesystems
231 scan all devices under /dev, otherwise the devices list is extracted from the
232 /proc/partitions file. This is a fallback option if there's no device node
233 manager (like udev) available in the system.
235 raw numbers in bytes, without the 'B' suffix
237 print human friendly numbers, base 1024, this is the default
239 select the 1024 base for the following options, according to the IEC standard
241 select the 1000 base for the following options, according to the SI standard
243 show sizes in KiB, or kB with --si
245 show sizes in MiB, or MB with --si
247 show sizes in GiB, or GB with --si
249 show sizes in TiB, or TB with --si
252 Force a sync of the filesystem at 'path'. This is done via a special ioctl and
253 will also trigger cleaning of deleted subvolumes. Besides that it's equivalent
254 to the `sync`(1) command.
256 *usage* [options] <path> [<path>...]::
257 Show detailed information about internal filesystem usage. This is supposed to
258 replace the *btrfs filesystem df* command in the long run.
260 The level of detail can differ if the command is run under a regular or the
261 root user (due to use of restricted ioctl). For both there's a summary section
262 with information about space usage:
264 -------------------------
265 $ btrfs fi usage /path
266 WARNING: cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root
269 Device allocated: 1.17TiB
270 Device unallocated: 669.99GiB
271 Device missing: 0.00B
273 Free (estimated): 692.57GiB (min: 692.57GiB)
276 Global reserve: 512.00MiB (used: 0.00B)
277 -------------------------
279 The root user will also see stats broken down by block group types:
281 -------------------------
282 Data,single: Size:1.15TiB, Used:1.13TiB
285 Metadata,single: Size:12.00GiB, Used:6.45GiB
288 System,single: Size:32.00MiB, Used:144.00KiB
293 -------------------------
298 raw numbers in bytes, without the 'B' suffix
299 -h|--human-readable::::
300 print human friendly numbers, base 1024, this is the default
302 print human friendly numbers, base 1000
304 select the 1024 base for the following options, according to the IEC standard
306 select the 1000 base for the following options, according to the SI standard
308 show sizes in KiB, or kB with --si
310 show sizes in MiB, or MB with --si
312 show sizes in GiB, or GB with --si
314 show sizes in TiB, or TB with --si
316 show data in tabular format
318 If conflicting options are passed, the last one takes precedence.
323 *$ btrfs filesystem defrag -v -r dir/*
325 Recursively defragment files under 'dir/', print files as they are processed.
326 The file names will be printed in batches, similarly the amount of data triggered
327 by defragmentation will be proportional to last N printed files. The system dirty
328 memory throttling will slow down the defragmentation but there can still be a lot
329 of IO load and the system may stall for a moment.
331 *$ btrfs filesystem defrag -v -r -f dir/*
333 Recursively defragment files under 'dir/', be verbose and wait until all blocks
334 are flushed before processing next file. You can note slower progress of the
335 output and lower IO load (proportional to currently defragmented file).
337 *$ btrfs filesystem defrag -v -r -f -clzo dir/*
339 Recursively defragment files under 'dir/', be verbose, wait until all blocks are
340 flushed and force file compression.
342 *$ btrfs filesystem defrag -v -r -t 64M dir/*
344 Recursively defragment files under 'dir/', be verbose and try to merge extents
345 to be about 64MiB. As stated above, the success rate depends on actual free
346 space fragmentation and the final result is not guaranteed to meet the target
347 even if run repeatedly.
349 *$ btrfs filesystem resize -1G /path*
351 *$ btrfs filesystem resize 1:-1G /path*
353 Shrink size of the filesystem's device id 1 by 1GiB. The first syntax expects a
354 device with id 1 to exist, otherwise fails. The second is equivalent and more
355 explicit. For a single-device filesystem it's typically not necessary to
356 specify the devid though.
358 *$ btrfs filesystem resize max /path*
360 *$ btrfs filesystem resize 1:max /path*
362 Let's assume that devid 1 exists, the filesystem does not occupy the whole block
363 device, eg. it has been enlarged and we wan the grow the filesystem. Simply using
364 'max' as size we will achieve that.
366 NOTE: There are two ways to minimize the filesystem on a given device. The
367 *btrfs inspect-internal min-dev-size* command, or iteratively shrink in steps.
371 *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
372 returned in case of failure.
376 *btrfs* is part of btrfs-progs.
377 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for