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 separate 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 filesystem.
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 length 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
100 NOTE: Directory arguments without '-r' do not defragment files recursively but will
101 defragment certain internal trees (extent tree and the subvolume tree). This has been
102 confusing and could be removed in the future.
104 For 'start', 'len', 'size' it is possible to append
105 units designator: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
106 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
111 be verbose, print file names as they're submitted for defragmentation
113 compress file contents while defragmenting. Optional argument selects the compression
114 algorithm, 'zlib' (default) or 'lzo'. Currently it's not possible to select no
115 compression. See also section 'EXAMPLES'.
117 defragment files recursively in given directories
119 flush data for each file before going to the next file. This will limit the amount
120 of dirty data to current file, otherwise the amount cumulates from several files
121 and may increase system load.
122 -s <start>[kKmMgGtTpPeE]::::
123 defragmentation will start from the given offset, default is beginning of a file
124 -l <len>[kKmMgGtTpPeE]::::
125 defragment only up to 'len' bytes, default is the file size
126 -t <size>[kKmMgGtTpPeE]::::
127 target extent size, do not touch extents bigger than 'size'
129 *du* [options] <path> [<path>..]::
130 Calculate disk usage of the target files using FIEMAP. For individual
131 files, it will report a count of total bytes, and exclusive (not
132 shared) bytes. We also calculate a 'set shared' value which is
135 Each argument to 'btrfs fi du' will have a 'set shared' value
136 calculated for it. We define each 'set' as those files found by a
137 recursive search of an argument. The 'set shared' value
138 then is a sum of all shared space referenced by the set.
140 'set shared' takes into account overlapping shared extents, hence it
141 isn't as simple as adding up shared extents.
146 display only a total for each argument
148 raw numbers in bytes, without the 'B' suffix.
150 print human friendly numbers, base 1024, this is the default
152 select the 1024 base for the following options, according to the IEC standard.
154 select the 1000 base for the following options, according to the SI standard.
156 show sizes in KiB, or kB with --si.
158 show sizes in MiB, or MB with --si.
160 show sizes in GiB, or GB with --si.
162 show sizes in TiB, or TB with --si.
164 *label* [<dev>|<mountpoint>] [<newlabel>]::
165 Show or update the label of a filesystem. This works on a mounted filesystem or
168 The 'newlabel' argument is optional. Current label is printed if the the argument
171 NOTE: the maximum allowable length shall be less than 256 chars and must not contain
172 a newline. The trailing newline is stripped automatically.
174 // Some wording are extracted by the resize2fs man page
175 *resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>::
176 Resize a mounted filesystem identified by 'path'. A particular device
177 can be resized by specifying a 'devid'.
179 WARNING: If 'path' is a file containing a BTRFS image then resize does not work
180 as expected and does not resize the image. This would resize the underlying
183 The 'devid' can be found in the output of *btrfs filesystem show* and
184 defaults to 1 if not specified.
185 The 'size' parameter specifies the new size of the filesystem.
186 If the prefix '+' or '-' is present the size is increased or decreased
187 by the quantity 'size'.
188 If no units are specified, bytes are assumed for 'size'.
189 Optionally, the size parameter may be suffixed by one of the following
190 units designators: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
191 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
193 If 'max' is passed, the filesystem will occupy all available space on the
194 device respecting 'devid' (remember, devid 1 by default).
196 The resize command does not manipulate the size of underlying
197 partition. If you wish to enlarge/reduce a filesystem, you must make sure you
198 can expand the partition before enlarging the filesystem and shrink the
199 partition after reducing the size of the filesystem. This can done using
200 `fdisk`(8) or `parted`(8) to delete the existing partition and recreate
201 it with the new desired size. When recreating the partition make sure to use
202 the same starting partition offset as before.
204 Growing is usually instant as it only updates the size. However, shrinking could
205 take a long time if there are data in the device area that's beyond the new
206 end. Relocation of the data takes time.
208 See also section 'EXAMPLES'.
210 *show* [options] [<path>|<uuid>|<device>|<label>]::
211 Show the btrfs filesystem with some additional info about devices and space
214 If no option none of 'path'/'uuid'/'device'/'label' is passed, information
215 about all the BTRFS filesystems is shown, both mounted and unmounted.
220 probe kernel for mounted BTRFS filesystems
222 scan all devices under /dev, otherwise the devices list is extracted from the
223 /proc/partitions file. This is a fallback option if there's no device node
224 manager (like udev) available in the system.
226 raw numbers in bytes, without the 'B' suffix
228 print human friendly numbers, base 1024, this is the default
230 select the 1024 base for the following options, according to the IEC standard
232 select the 1000 base for the following options, according to the SI standard
234 show sizes in KiB, or kB with --si
236 show sizes in MiB, or MB with --si
238 show sizes in GiB, or GB with --si
240 show sizes in TiB, or TB with --si
243 Force a sync of the filesystem at 'path'. This is done via a special ioctl and
244 will also trigger cleaning of deleted subvolumes. Besides that it's equivalent
245 to the `sync`(1) command.
247 *usage* [options] <path> [<path>...]::
248 Show detailed information about internal filesystem usage. This is supposed to
249 replace the *btrfs filesystem df* command in the long run.
251 The level of detail can differ if the command is run under a regular or the
252 root user (due to use of restricted ioctl). For both there's a summary section
253 with information about space usage:
255 -------------------------
256 $ btrfs fi usage /path
257 WARNING: cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root
260 Device allocated: 1.17TiB
261 Device unallocated: 669.99GiB
262 Device missing: 0.00B
264 Free (estimated): 692.57GiB (min: 692.57GiB)
267 Global reserve: 512.00MiB (used: 0.00B)
268 -------------------------
270 The root user will also see stats broken down by block group types:
272 -------------------------
273 Data,single: Size:1.15TiB, Used:1.13TiB
276 Metadata,single: Size:12.00GiB, Used:6.45GiB
279 System,single: Size:32.00MiB, Used:144.00KiB
284 -------------------------
289 raw numbers in bytes, without the 'B' suffix
290 -h|--human-readable::::
291 print human friendly numbers, base 1024, this is the default
293 print human friendly numbers, base 1000
295 select the 1024 base for the following options, according to the IEC standard
297 select the 1000 base for the following options, according to the SI standard
299 show sizes in KiB, or kB with --si
301 show sizes in MiB, or MB with --si
303 show sizes in GiB, or GB with --si
305 show sizes in TiB, or TB with --si
307 show data in tabular format
309 If conflicting options are passed, the last one takes precedence.
314 *$ btrfs filesystem defrag -v -r dir/*
316 Recursively defragment files under 'dir/', print files as they are processed.
317 The file names will be printed in batches, similarly the amount of data triggered
318 by defragmentation will be proportional to last N printed files. The system dirty
319 memory throttling will slow down the defragmentation but there can still be a lot
320 of IO load and the system may stall for a moment.
322 *$ btrfs filesystem defrag -v -r -f dir/*
324 Recursively defragment files under 'dir/', be verbose and wait until all blocks
325 are flushed before processing next file. You can note slower progress of the
326 output and lower IO load (proportional to currently defragmented file).
328 *$ btrfs filesystem defrag -v -r -f -clzo dir/*
330 Recursively defragment files under 'dir/', be verbose, wait until all blocks are
331 flushed and force file compression.
333 *$ btrfs filesystem defrag -v -r -t 64M dir/*
335 Recursively defragment files under 'dir/', be verbose and try to merge extents
336 to be about 64MiB. As stated above, the success rate depends on actual free
337 space fragmentation and the final result is not guaranteed to meet the target
338 even if run repeatedly.
340 *$ btrfs filesystem resize -1G /path*
342 *$ btrfs filesystem resize 1:-1G /path*
344 Shrink size of the filesystem's device id 1 by 1GiB. The first syntax expects a
345 device with id 1 to exist, otherwise fails. The second is equivalent and more
346 explicit. For a single-device filesystem it's typically not necessary to
347 specify the devid though.
349 *$ btrfs filesystem resize max /path*
351 *$ btrfs filesystem resize 1:max /path*
353 Let's assume that devid 1 exists, the filesystem does not occupy the whole block
354 device, eg. it has been enlarged and we wan the grow the filesystem. Simply using
355 'max' as size we will achieve that.
357 NOTE: There are two ways to minimize the filesystem on a given device. The
358 *btrfs inspect-internal min-dev-size* command, or iteratively shrink in steps.
362 *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
363 returned in case of failure.
367 *btrfs* is part of btrfs-progs.
368 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for