961405ba78d70909059f89ea0c37f77e59e45ef2
[platform/upstream/btrfs-progs.git] / Documentation / btrfs-filesystem.asciidoc
1 btrfs-filesystem(8)
2 ===================
3
4 NAME
5 ----
6 btrfs-filesystem - command group othat primarily does work on the whole filesystems
7
8 SYNOPSIS
9 --------
10 *btrfs filesystem* <subcommand> <args>
11
12 DESCRIPTION
13 -----------
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 tasks like scrub or balance that are grouped in separate commands.
18
19 SUBCOMMAND
20 ----------
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.
25 +
26 --
27 An example with description:
28
29 * device size: '1.9TiB', one device, no RAID
30 * filesystem size: '1.9TiB'
31 * created with: 'mkfs.btrfs -d single -m single'
32 --
33 +
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 ------------------------------
41 +
42 --
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
50 --
51 +
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.
55 +
56 The GlobalReserve is a portion of Metadata. In case the filesystem metadata is
57 exhausted, 'GlobalReserve/total + Metadata/used = Metadata/total'. Otherwise
58 there appears to be some unused space of Metadata.
59 +
60 `Options`
61 +
62 -b|--raw::::
63 raw numbers in bytes, without the 'B' suffix
64 -h|--human-readable::::
65 print human friendly numbers, base 1024, this is the default
66 -H::::
67 print human friendly numbers, base 1000
68 --iec::::
69 select the 1024 base for the following options, according to the IEC standard
70 --si::::
71 select the 1000 base for the following options, according to the SI standard
72 -k|--kbytes::::
73 show sizes in KiB, or kB with --si
74 -m|--mbytes::::
75 show sizes in MiB, or MB with --si
76 -g|--gbytes::::
77 show sizes in GiB, or GB with --si
78 -t|--tbytes::::
79 show sizes in TiB, or TB with --si
80 +
81 If conflicting options are passed, the last one takes precedence.
82
83 *defragment* [options] <file>|<dir> [<file>|<dir>...]::
84 Defragment file data on a mounted filesystem. Requires kernel 2.6.33 and newer.
85 +
86 If '-r' is passed, files in dir will be defragmented recursively.
87 The start position and the number of bytes to defragment can be specified by
88 start and length using '-s' and '-l' options below.
89 Extents bigger than value given by '-t' will be skipped, otherwise this value
90 is used as a target extent size, but is only advisory and may not be reached
91 if the free space is too fragmented.
92 Use 0 to take the kernel default, which is 256kB but may change in the future.
93 You can also turn on compression in defragment operations.
94 +
95 WARNING: Defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as
96 with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up
97 the reflinks of COW data (for example files copied with `cp --reflink`,
98 snapshots or de-duplicated data).
99 This may cause considerable increase of space usage depending on the broken up
100 reflinks.
101 +
102 NOTE: Directory arguments without '-r' do not defragment files recursively but will
103 defragment certain internal trees (extent tree and the subvolume tree). This has been
104 confusing and could be removed in the future.
105 +
106 For 'start', 'len', 'size' it is possible to append
107 units designator: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
108 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
109 +
110 `Options`
111 +
112 -v::::
113 be verbose, print file names as they're submitted for defragmentation
114 -c[<algo>]::::
115 compress file contents while defragmenting. Optional argument selects the compression
116 algorithm, 'zlib' (default), 'lzo' or 'zstd'. Currently it's not possible to select no
117 compression. See also section 'EXAMPLES'.
118 -r::::
119 defragment files recursively in given directories
120 -f::::
121 flush data for each file before going to the next file.
122 +
123 This will limit the amount of dirty data to current file, otherwise the amount
124 accumulates from several files and will increase system load. This can also lead
125 to ENOSPC if there's too much dirty data to write and it's not possible to make
126 the reservations for the new data (ie. how the COW design works).
127 +
128 -s <start>[kKmMgGtTpPeE]::::
129 defragmentation will start from the given offset, default is beginning of a file
130 -l <len>[kKmMgGtTpPeE]::::
131 defragment only up to 'len' bytes, default is the file size
132 -t <size>[kKmMgGtTpPeE]::::
133 target extent size, do not touch extents bigger than 'size', default: 32M
134 +
135 The value is only advisory and the final size of the extents may differ,
136 depending on the state of the free space and fragmentation or other internal
137 logic. Reasonable values are from tens to hundreds of megabytes.
138
139 *du* [options] <path> [<path>..]::
140 Calculate disk usage of the target files using FIEMAP. For individual
141 files, it will report a count of total bytes, and exclusive (not
142 shared) bytes. We also calculate a 'set shared' value which is
143 described below.
144 +
145 Each argument to 'btrfs filesystem du' will have a 'set shared' value
146 calculated for it. We define each 'set' as those files found by a
147 recursive search of an argument. The 'set shared' value
148 then is a sum of all shared space referenced by the set.
149 +
150 'set shared' takes into account overlapping shared extents, hence it
151 isn't as simple as adding up shared extents.
152 +
153 `Options`
154 +
155 -s|--summarize::::
156 display only a total for each argument
157 --raw::::
158 raw numbers in bytes, without the 'B' suffix.
159 --human-readable::::
160 print human friendly numbers, base 1024, this is the default
161 --iec::::
162 select the 1024 base for the following options, according to the IEC standard.
163 --si::::
164 select the 1000 base for the following options, according to the SI standard.
165 --kbytes::::
166 show sizes in KiB, or kB with --si.
167 --mbytes::::
168 show sizes in MiB, or MB with --si.
169 --gbytes::::
170 show sizes in GiB, or GB with --si.
171 --tbytes::::
172 show sizes in TiB, or TB with --si.
173
174 *label* [<device>|<mountpoint>] [<newlabel>]::
175 Show or update the label of a filesystem. This works on a mounted filesystem or
176 a filesystem image.
177 +
178 The 'newlabel' argument is optional. Current label is printed if the argument
179 is omitted.
180 +
181 NOTE: the maximum allowable length shall be less than 256 chars and must not contain
182 a newline. The trailing newline is stripped automatically.
183
184 // Some wording are extracted by the resize2fs man page
185 *resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>::
186 Resize a mounted filesystem identified by 'path'. A particular device
187 can be resized by specifying a 'devid'.
188 +
189 WARNING: If 'path' is a file containing a BTRFS image then resize does not work
190 as expected and does not resize the image. This would resize the underlying
191 filesystem instead.
192 +
193 The 'devid' can be found in the output of *btrfs filesystem show* and
194 defaults to 1 if not specified.
195 The 'size' parameter specifies the new size of the filesystem.
196 If the prefix '+' or '-' is present the size is increased or decreased
197 by the quantity 'size'.
198 If no units are specified, bytes are assumed for 'size'.
199 Optionally, the size parameter may be suffixed by one of the following
200 unit designators: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
201 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
202 +
203 If 'max' is passed, the filesystem will occupy all available space on the
204 device respecting 'devid' (remember, devid 1 by default).
205 +
206 The resize command does not manipulate the size of underlying
207 partition.  If you wish to enlarge/reduce a filesystem, you must make sure you
208 can expand the partition before enlarging the filesystem and shrink the
209 partition after reducing the size of the filesystem.  This can done using
210 `fdisk`(8) or `parted`(8) to delete the existing partition and recreate
211 it with the new desired size.  When recreating the partition make sure to use
212 the same starting partition offset as before.
213 +
214 Growing is usually instant as it only updates the size. However, shrinking could
215 take a long time if there are data in the device area that's beyond the new
216 end. Relocation of the data takes time.
217 +
218 See also section 'EXAMPLES'.
219
220 *show* [options] [<path>|<uuid>|<device>|<label>]::
221 Show the btrfs filesystem with some additional info about devices and space
222 allocation.
223 +
224 If no option none of 'path'/'uuid'/'device'/'label' is passed, information
225 about all the BTRFS filesystems is shown, both mounted and unmounted.
226 +
227 `Options`
228 +
229 -m|--mounted::::
230 probe kernel for mounted BTRFS filesystems
231 -d|--all-devices::::
232 scan all devices under /dev, otherwise the devices list is extracted from the
233 /proc/partitions file. This is a fallback option if there's no device node
234 manager (like udev) available in the system.
235 --raw::::
236 raw numbers in bytes, without the 'B' suffix
237 --human-readable::::
238 print human friendly numbers, base 1024, this is the default
239 --iec::::
240 select the 1024 base for the following options, according to the IEC standard
241 --si::::
242 select the 1000 base for the following options, according to the SI standard
243 --kbytes::::
244 show sizes in KiB, or kB with --si
245 --mbytes::::
246 show sizes in MiB, or MB with --si
247 --gbytes::::
248 show sizes in GiB, or GB with --si
249 --tbytes::::
250 show sizes in TiB, or TB with --si
251
252 *sync* <path>::
253 Force a sync of the filesystem at 'path'. This is done via a special ioctl and
254 will also trigger cleaning of deleted subvolumes. Besides that it's equivalent
255 to the `sync`(1) command.
256
257 *usage* [options] <path> [<path>...]::
258 Show detailed information about internal filesystem usage. This is supposed to
259 replace the *btrfs filesystem df* command in the long run.
260 +
261 The level of detail can differ if the command is run under a regular or the
262 root user (due to use of restricted ioctl). For both there's a summary section
263 with information about space usage:
264 +
265 -------------------------
266 $ btrfs filesystem usage /path
267 WARNING: cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root
268 Overall:
269     Device size:                   1.82TiB
270     Device allocated:              1.17TiB
271     Device unallocated:          669.99GiB
272     Device missing:                  0.00B
273     Used:                          1.14TiB
274     Free (estimated):            692.57GiB      (min: 692.57GiB)
275     Data ratio:                       1.00
276     Metadata ratio:                   1.00
277     Global reserve:              512.00MiB      (used: 0.00B)
278 -------------------------
279 +
280 The root user will also see stats broken down by block group types:
281 +
282 -------------------------
283 Data,single: Size:1.15TiB, Used:1.13TiB
284    /dev/sdb        1.15TiB
285
286 Metadata,single: Size:12.00GiB, Used:6.45GiB
287    /dev/sdb       12.00GiB
288
289 System,single: Size:32.00MiB, Used:144.00KiB
290    /dev/sdb       32.00MiB
291
292 Unallocated:
293    /dev/sdb      669.99GiB
294 -------------------------
295 +
296 `Options`
297 +
298 -b|--raw::::
299 raw numbers in bytes, without the 'B' suffix
300 -h|--human-readable::::
301 print human friendly numbers, base 1024, this is the default
302 -H::::
303 print human friendly numbers, base 1000
304 --iec::::
305 select the 1024 base for the following options, according to the IEC standard
306 --si::::
307 select the 1000 base for the following options, according to the SI standard
308 -k|--kbytes::::
309 show sizes in KiB, or kB with --si
310 -m|--mbytes::::
311 show sizes in MiB, or MB with --si
312 -g|--gbytes::::
313 show sizes in GiB, or GB with --si
314 -t|--tbytes::::
315 show sizes in TiB, or TB with --si
316 -T::::
317 show data in tabular format
318 +
319 If conflicting options are passed, the last one takes precedence.
320
321 EXAMPLES
322 --------
323
324 *$ btrfs filesystem defrag -v -r dir/*
325
326 Recursively defragment files under 'dir/', print files as they are processed.
327 The file names will be printed in batches, similarly the amount of data triggered
328 by defragmentation will be proportional to last N printed files. The system dirty
329 memory throttling will slow down the defragmentation but there can still be a lot
330 of IO load and the system may stall for a moment.
331
332 *$ btrfs filesystem defrag -v -r -f dir/*
333
334 Recursively defragment files under 'dir/', be verbose and wait until all blocks
335 are flushed before processing next file. You can note slower progress of the
336 output and lower IO load (proportional to currently defragmented file).
337
338 *$ btrfs filesystem defrag -v -r -f -clzo dir/*
339
340 Recursively defragment files under 'dir/', be verbose, wait until all blocks are
341 flushed and force file compression.
342
343 *$ btrfs filesystem defrag -v -r -t 64M dir/*
344
345 Recursively defragment files under 'dir/', be verbose and try to merge extents
346 to be about 64MiB. As stated above, the success rate depends on actual free
347 space fragmentation and the final result is not guaranteed to meet the target
348 even if run repeatedly.
349
350 *$ btrfs filesystem resize -1G /path*
351
352 *$ btrfs filesystem resize 1:-1G /path*
353
354 Shrink size of the filesystem's device id 1 by 1GiB. The first syntax expects a
355 device with id 1 to exist, otherwise fails. The second is equivalent and more
356 explicit. For a single-device filesystem it's typically not necessary to
357 specify the devid though.
358
359 *$ btrfs filesystem resize max /path*
360
361 *$ btrfs filesystem resize 1:max /path*
362
363 Let's assume that devid 1 exists and the filesystem does not occupy the whole
364 block device, eg. it has been enlarged and we wan the grow the filesystem. By
365 simply using 'max' as size we will achieve that.
366
367 NOTE: There are two ways to minimize the filesystem on a given device. The
368 *btrfs inspect-internal min-dev-size* command, or iteratively shrink in steps.
369
370 EXIT STATUS
371 -----------
372 *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
373 returned in case of failure.
374
375 AVAILABILITY
376 ------------
377 *btrfs* is part of btrfs-progs.
378 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
379 further details.
380
381 SEE ALSO
382 --------
383 `mkfs.btrfs`(8),