btrfs-progs: mkfs: Separate shrink from rootdir
[platform/upstream/btrfs-progs.git] / Documentation / mkfs.btrfs.asciidoc
1 mkfs.btrfs(8)
2 =============
3
4 NAME
5 ----
6 mkfs.btrfs - create a btrfs filesystem
7
8 SYNOPSIS
9 --------
10 *mkfs.btrfs* [options] <device> [<device>...]
11
12 DESCRIPTION
13 -----------
14 *mkfs.btrfs* is used to create the btrfs filesystem on a single or multiple
15 devices.  <device> is typically a block device but can be a file-backed image
16 as well. Multiple devices are grouped by UUID of the filesystem.
17
18 Before mounting such filesystem, the kernel module must know all the devices
19 either via preceding execution of *btrfs device scan* or using the *device*
20 mount option. See section *MULTIPLE DEVICES* for more details.
21
22 OPTIONS
23 -------
24 *-b|--byte-count <size>*::
25 Specify the size of the filesystem. If this option is not used, then
26 mkfs.btrfs uses the entire device space for the filesystem.
27
28 *-d|--data <profile>*::
29 Specify the profile for the data block groups.  Valid values are 'raid0',
30 'raid1', 'raid5', 'raid6', 'raid10' or 'single' or dup (case does not matter).
31 +
32 See 'DUP PROFILES ON A SINGLE DEVICE' for more.
33
34 *-m|--metadata <profile>*::
35 Specify the profile for the metadata block groups.
36 Valid values are 'raid0', 'raid1', 'raid5', 'raid6', 'raid10', 'single' or
37 'dup', (case does not matter).
38 +
39 A single device filesystem will default to 'DUP', unless a SSD is detected. Then
40 it will default to 'single'. The detection is based on the value of
41 `/sys/block/DEV/queue/rotational`, where 'DEV' is the short name of the device.
42 +
43 Note that the rotational status can be arbitrarily set by the underlying block
44 device driver and may not reflect the true status (network block device, memory-backed
45 SCSI devices etc). Use the options '--data/--metadata' to avoid confusion.
46 +
47 See 'DUP PROFILES ON A SINGLE DEVICE' for more details.
48
49 *-M|--mixed*::
50 Normally the data and metadata block groups are isolated. The 'mixed' mode
51 will remove the isolation and store both types in the same block group type.
52 This helps to utilize the free space regardless of the purpose and is suitable
53 for small devices. The separate allocation of block groups leads to a situation
54 where the space is reserved for the other block group type, is not available for
55 allocation and can lead to ENOSPC state.
56 +
57 The recommended size for the mixed mode is for filesystems less than 1GiB. The
58 soft recommendation is to use it for filesystems smaller than 5GiB. The mixed
59 mode may lead to degraded performance on larger filesystems, but is otherwise
60 usable, even on multiple devices.
61 +
62 The 'nodesize' and 'sectorsize' must be equal, and the block group types must
63 match.
64 +
65 NOTE: versions up to 4.2.x forced the mixed mode for devices smaller than 1GiB.
66 This has been removed in 4.3+ as it caused some usability issues.
67
68 *-l|--leafsize <size>*::
69 Alias for --nodesize. Deprecated.
70
71 *-n|--nodesize <size>*::
72 Specify the nodesize, the tree block size in which btrfs stores metadata. The
73 default value is 16KiB (16384) or the page size, whichever is bigger. Must be a
74 multiple of the sectorsize and a power of 2, but not larger than 64KiB (65536).
75 Leafsize always equals nodesize and the options are aliases.
76 +
77 Smaller node size increases fragmentation but leads to taller b-trees which in
78 turn leads to lower locking contention. Higher node sizes give better packing
79 and less fragmentation at the cost of more expensive memory operations while
80 updating the metadata blocks.
81 +
82 NOTE: versions up to 3.11 set the nodesize to 4k.
83
84 *-s|--sectorsize <size>*::
85 Specify the sectorsize, the minimum data block allocation unit.
86 +
87 The default value is the page size and is autodetected. If the sectorsize
88 differs from the page size, the created filesystem may not be mountable by the
89 kernel. Therefore it is not recommended to use this option unless you are going
90 to mount it on a system with the appropriate page size.
91
92 *-L|--label <string>*::
93 Specify a label for the filesystem. The 'string' should be less than 256
94 bytes and must not contain newline characters.
95
96 *-K|--nodiscard*::
97 Do not perform whole device TRIM operation on devices that are capable of that.
98 This does not affect discard/trim operation when the filesystem is mounted.
99 Please see the mount option 'discard' for that in `btrfs`(5).
100
101 *-r|--rootdir <rootdir>*::
102 Populate the toplevel subvolume with files from 'rootdir'.  This does not
103 require root permissions and does not mount the filesystem.
104 +
105 NOTE: This option may enlarge the image or file to ensure it's large enough to
106 contain the files from 'rootdir'.
107
108 *--shrink*:
109 Shrink the filesystem to its minimal size, only works with *-r|--rootdir*
110 option.
111 +
112 NOTE: If the destination is regular file, this option will also reduce the
113 file size. Or it will only reduce the filesystem available space.
114 Extra space will not be usable unless resized using 'btrfs filesystem resize'.
115
116 *-O|--features <feature1>[,<feature2>...]*::
117 A list of filesystem features turned on at mkfs time. Not all features are
118 supported by old kernels. To disable a feature, prefix it with '^'.
119 +
120 See section *FILESYSTEM FEATURES* for more details.  To see all available
121 features that mkfs.btrfs supports run:
122 +
123 +mkfs.btrfs -O list-all+
124
125 *-f|--force*::
126 Forcibly overwrite the block devices when an existing filesystem is detected.
127 By default, mkfs.btrfs will utilize 'libblkid' to check for any known
128 filesystem on the devices. Alternatively you can use the `wipefs` utility
129 to clear the devices.
130
131 *-q|--quiet*::
132 Print only error or warning messages. Options --features or --help are unaffected.
133
134 *-U|--uuid <UUID>*::
135 Create the filesystem with the given 'UUID'. The UUID must not exist on any
136 filesystem currently present.
137
138 *-V|--version*::
139 Print the *mkfs.btrfs* version and exit.
140
141 *--help*::
142 Print help.
143
144 *-A|--alloc-start <offset>*::
145 *deprecated, will be removed*
146 (An option to help debugging chunk allocator.)
147 Specify the (physical) offset from the start of the device at which allocations
148 start.  The default value is zero.
149
150 SIZE UNITS
151 ----------
152 The default unit is 'byte'. All size parameters accept suffixes in the 1024
153 base. The recognized suffixes are: 'k', 'm', 'g', 't', 'p', 'e', both uppercase
154 and lowercase.
155
156 MULTIPLE DEVICES
157 ----------------
158
159 Before mounting a multiple device filesystem, the kernel module must know the
160 association of the block devices that are attached to the filesystem UUID.
161
162 There is typically no action needed from the user.  On a system that utilizes a
163 udev-like daemon, any new block device is automatically registered. The rules
164 call *btrfs device scan*.
165
166 The same command can be used to trigger the device scanning if the btrfs kernel
167 module is reloaded (naturally all previous information about the device
168 registration is lost).
169
170 Another possibility is to use the mount options *device* to specify the list of
171 devices to scan at the time of mount.
172
173  # mount -o device=/dev/sdb,device=/dev/sdc /dev/sda /mnt
174
175 NOTE: that this means only scanning, if the devices do not exist in the system,
176 mount will fail anyway. This can happen on systems without initramfs/initrd and
177 root partition created with RAID1/10/5/6 profiles. The mount action can happen
178 before all block devices are discovered. The waiting is usually done on the
179 initramfs/initrd systems.
180
181 As of kernel 4.14, RAID5/6 is still considered experimental and shouldn't be
182 employed for production use.
183
184 FILESYSTEM FEATURES
185 -------------------
186
187 Features that can be enabled during creation time. See also `btrfs`(5) section
188 'FILESYSTEM FEATURES'.
189
190 *mixed-bg*::
191 (kernel support since 2.6.37)
192 +
193 mixed data and metadata block groups, also set by option '--mixed'
194
195 *extref*::
196 (default since btrfs-progs 3.12, kernel support since 3.7)
197 +
198 increased hardlink limit per file in a directory to 65536, older kernels
199 supported a varying number of hardlinks depending on the sum of all file name
200 sizes that can be stored into one metadata block
201
202 *raid56*::
203 (kernel support since 3.9)
204 +
205 extended format for RAID5/6, also enabled if raid5 or raid6 block groups
206 are selected
207
208 *skinny-metadata*::
209 (default since btrfs-progs 3.18, kernel support since 3.10)
210 +
211 reduced-size metadata for extent references, saves a few percent of metadata
212
213 *no-holes*::
214 (kernel support since 3.14)
215 +
216 improved representation of file extents where holes are not explicitly
217 stored as an extent, saves a few percent of metadata if sparse files are used
218
219 BLOCK GROUPS, CHUNKS, RAID
220 --------------------------
221
222 The highlevel organizational units of a filesystem are block groups of three types:
223 data, metadata and system.
224
225 *DATA*::
226 store data blocks and nothing else
227
228 *METADATA*::
229 store internal metadata in b-trees, can store file data if they fit into the
230 inline limit
231
232 *SYSTEM*::
233 store structures that describe the mapping between the physical devices and the
234 linear logical space representing the filesystem
235
236 Other terms commonly used:
237
238 *block group*::
239 *chunk*::
240 a logical range of space of a given profile, stores data, metadata or both;
241 sometimes the terms are used interchangeably
242 +
243 A typical size of metadata block group is 256MiB (filesystem smaller than
244 50GiB) and 1GiB (larger than 50GiB), for data it's 1GiB. The system block group
245 size is a few megabytes.
246
247 *RAID*::
248 a block group profile type that utilizes RAID-like features on multiple
249 devices: striping, mirroring, parity
250
251 *profile*::
252 when used in connection with block groups refers to the allocation strategy
253 and constraints, see the section 'PROFILES' for more details
254
255 PROFILES
256 --------
257
258 There are the following block group types available:
259
260 [ cols="^,^,^,^,^",width="60%" ]
261 |=============================================================
262 .2+^.<h| Profile   3+^.^h| Redundancy           .2+^.<h| Min/max devices
263       ^.^h| Copies   ^.^h| Parity     ^.<h| Striping
264 | single  | 1            |                |            | 1/any
265 | DUP     | 2 / 1 device |                |            | 1/any ^(see note 1)^
266 | RAID0   |              |                | 1 to N     | 2/any
267 | RAID1   | 2            |                |            | 2/any
268 | RAID10  | 2            |                | 1 to N     | 4/any
269 | RAID5   | 1            | 1              | 2 to N - 1 | 2/any ^(see note 2)^
270 | RAID6   | 1            | 2              | 3 to N - 2 | 3/any ^(see note 3)^
271 |=============================================================
272
273 WARNING: It's not recommended to build btrfs with RAID0/1/10/5/6 profiles on
274 partitions from the same device.  Neither redundancy nor performance will be
275 improved.
276
277 'Note 1:' DUP may exist on more than 1 device if it starts on a single device and
278 another one is added. Since version 4.5.1, *mkfs.btrfs* will let you create DUP
279 on multiple devices.
280
281 'Note 2:' It's not recommended to use 2 devices with RAID5. In that case,
282 parity stripe will contain the same data as the data stripe, making RAID5
283 degraded to RAID1 with more overhead.
284
285 'Note 3:' It's also not recommended to use 3 devices with RAID6, unless you
286 want to get effectively 3 copies in a RAID1-like manner (but not exactly that).
287 N-copies RAID1 is not implemented.
288
289 DUP PROFILES ON A SINGLE DEVICE
290 -------------------------------
291
292 The mkfs utility will let the user create a filesystem with profiles that write
293 the logical blocks to 2 physical locations. Whether there are really 2
294 physical copies highly depends on the underlying device type.
295
296 For example, a SSD drive can remap the blocks internally to a single copy--thus
297 deduplicating them. This negates the purpose of increased redundancy and just
298 wastes filesystem space without providing the expected level of redundancy.
299
300 The duplicated data/metadata may still be useful to statistically improve the
301 chances on a device that might perform some internal optimizations. The actual
302 details are not usually disclosed by vendors. For example we could expect that
303 not all blocks get deduplicated. This will provide a non-zero probability of
304 recovery compared to a zero chance if the single profile is used. The user
305 should make the tradeoff decision. The deduplication in SSDs is thought to be
306 widely available so the reason behind the mkfs default is to not give a false
307 sense of redundancy.
308
309 As another example, the widely used USB flash or SD cards use a translation
310 layer between the logical and physical view of the device. The data lifetime
311 may be affected by frequent plugging. The memory cells could get damaged,
312 hopefully not destroying both copies of particular data in case of DUP.
313
314 The wear levelling techniques can also lead to reduced redundancy, even if the
315 device does not do any deduplication. The controllers may put data written in
316 a short timespan into the same physical storage unit (cell, block etc). In case
317 this unit dies, both copies are lost. BTRFS does not add any artificial delay
318 between metadata writes.
319
320 The traditional rotational hard drives usually fail at the sector level.
321
322 In any case, a device that starts to misbehave and repairs from the DUP copy
323 should be replaced! *DUP is not backup*.
324
325 KNOWN ISSUES
326 ------------
327
328 **SMALL FILESYSTEMS AND LARGE NODESIZE**
329
330 The combination of small filesystem size and large nodesize is not recommended
331 in general and can lead to various ENOSPC-related issues during mount time or runtime.
332
333 Since mixed block group creation is optional, we allow small
334 filesystem instances with differing values for 'sectorsize' and 'nodesize'
335 to be created and could end up in the following situation:
336
337   # mkfs.btrfs -f -n 65536 /dev/loop0
338   btrfs-progs v3.19-rc2-405-g976307c
339   See http://btrfs.wiki.kernel.org for more information.
340
341   Performing full device TRIM (512.00MiB) ...
342   Label:              (null)
343   UUID:               49fab72e-0c8b-466b-a3ca-d1bfe56475f0
344   Node size:          65536
345   Sector size:        4096
346   Filesystem size:    512.00MiB
347   Block group profiles:
348     Data:             single            8.00MiB
349     Metadata:         DUP              40.00MiB
350     System:           DUP              12.00MiB
351   SSD detected:       no
352   Incompat features:  extref, skinny-metadata
353   Number of devices:  1
354   Devices:
355     ID        SIZE  PATH
356      1   512.00MiB  /dev/loop0
357
358   # mount /dev/loop0 /mnt/
359   mount: mount /dev/loop0 on /mnt failed: No space left on device
360
361 The ENOSPC occurs during the creation of the UUID tree. This is caused
362 by large metadata blocks and space reservation strategy that allocates more
363 than can fit into the filesystem.
364
365
366 AVAILABILITY
367 ------------
368 *mkfs.btrfs* is part of btrfs-progs.
369 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
370 further details.
371
372 SEE ALSO
373 --------
374 `btrfs`(5),
375 `btrfs`(8),
376 `wipefs`(8)