btrfs-progs: docs: annual typo, clarity, & grammar review & fixups
[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 *-O|--features <feature1>[,<feature2>...]*::
106 A list of filesystem features turned on at mkfs time. Not all features are
107 supported by old kernels. To disable a feature, prefix it with '^'.
108 +
109 See section *FILESYSTEM FEATURES* for more details.  To see all available
110 features that mkfs.btrfs supports run:
111 +
112 +mkfs.btrfs -O list-all+
113
114 *-f|--force*::
115 Forcibly overwrite the block devices when an existing filesystem is detected.
116 By default, mkfs.btrfs will utilize 'libblkid' to check for any known
117 filesystem on the devices. Alternatively you can use the `wipefs` utility
118 to clear the devices.
119
120 *-q|--quiet*::
121 Print only error or warning messages. Options --features or --help are unaffected.
122
123 *-U|--uuid <UUID>*::
124 Create the filesystem with the given 'UUID'. The UUID must not exist on any
125 filesystem currently present.
126
127 *-V|--version*::
128 Print the *mkfs.btrfs* version and exit.
129
130 *--help*::
131 Print help.
132
133 *-A|--alloc-start <offset>*::
134 *deprecated, will be removed*
135 (An option to help debugging chunk allocator.)
136 Specify the (physical) offset from the start of the device at which allocations
137 start.  The default value is zero.
138
139 SIZE UNITS
140 ----------
141 The default unit is 'byte'. All size parameters accept suffixes in the 1024
142 base. The recognized suffixes are: 'k', 'm', 'g', 't', 'p', 'e', both uppercase
143 and lowercase.
144
145 MULTIPLE DEVICES
146 ----------------
147
148 Before mounting a multiple device filesystem, the kernel module must know the
149 association of the block devices that are attached to the filesystem UUID.
150
151 There is typically no action needed from the user.  On a system that utilizes a
152 udev-like daemon, any new block device is automatically registered. The rules
153 call *btrfs device scan*.
154
155 The same command can be used to trigger the device scanning if the btrfs kernel
156 module is reloaded (naturally all previous information about the device
157 registration is lost).
158
159 Another possibility is to use the mount options *device* to specify the list of
160 devices to scan at the time of mount.
161
162  # mount -o device=/dev/sdb,device=/dev/sdc /dev/sda /mnt
163
164 NOTE: that this means only scanning, if the devices do not exist in the system,
165 mount will fail anyway. This can happen on systems without initramfs/initrd and
166 root partition created with RAID1/10/5/6 profiles. The mount action can happen
167 before all block devices are discovered. The waiting is usually done on the
168 initramfs/initrd systems.
169
170 As of kernel 4.14, RAID5/6 is still considered experimental and shouldn't be
171 employed for production use.
172
173 FILESYSTEM FEATURES
174 -------------------
175
176 Features that can be enabled during creation time. See also `btrfs`(5) section
177 'FILESYSTEM FEATURES'.
178
179 *mixed-bg*::
180 (kernel support since 2.6.37)
181 +
182 mixed data and metadata block groups, also set by option '--mixed'
183
184 *extref*::
185 (default since btrfs-progs 3.12, kernel support since 3.7)
186 +
187 increased hardlink limit per file in a directory to 65536, older kernels
188 supported a varying number of hardlinks depending on the sum of all file name
189 sizes that can be stored into one metadata block
190
191 *raid56*::
192 (kernel support since 3.9)
193 +
194 extended format for RAID5/6, also enabled if raid5 or raid6 block groups
195 are selected
196
197 *skinny-metadata*::
198 (default since btrfs-progs 3.18, kernel support since 3.10)
199 +
200 reduced-size metadata for extent references, saves a few percent of metadata
201
202 *no-holes*::
203 (kernel support since 3.14)
204 +
205 improved representation of file extents where holes are not explicitly
206 stored as an extent, saves a few percent of metadata if sparse files are used
207
208 BLOCK GROUPS, CHUNKS, RAID
209 --------------------------
210
211 The highlevel organizational units of a filesystem are block groups of three types:
212 data, metadata and system.
213
214 *DATA*::
215 store data blocks and nothing else
216
217 *METADATA*::
218 store internal metadata in b-trees, can store file data if they fit into the
219 inline limit
220
221 *SYSTEM*::
222 store structures that describe the mapping between the physical devices and the
223 linear logical space representing the filesystem
224
225 Other terms commonly used:
226
227 *block group*::
228 *chunk*::
229 a logical range of space of a given profile, stores data, metadata or both;
230 sometimes the terms are used interchangeably
231 +
232 A typical size of metadata block group is 256MiB (filesystem smaller than
233 50GiB) and 1GiB (larger than 50GiB), for data it's 1GiB. The system block group
234 size is a few megabytes.
235
236 *RAID*::
237 a block group profile type that utilizes RAID-like features on multiple
238 devices: striping, mirroring, parity
239
240 *profile*::
241 when used in connection with block groups refers to the allocation strategy
242 and constraints, see the section 'PROFILES' for more details
243
244 PROFILES
245 --------
246
247 There are the following block group types available:
248
249 [ cols="^,^,^,^,^",width="60%" ]
250 |=============================================================
251 .2+^.<h| Profile   3+^.^h| Redundancy           .2+^.<h| Min/max devices
252       ^.^h| Copies   ^.^h| Parity     ^.<h| Striping
253 | single  | 1            |                |            | 1/any
254 | DUP     | 2 / 1 device |                |            | 1/any ^(see note 1)^
255 | RAID0   |              |                | 1 to N     | 2/any
256 | RAID1   | 2            |                |            | 2/any
257 | RAID10  | 2            |                | 1 to N     | 4/any
258 | RAID5   | 1            | 1              | 2 to N - 1 | 2/any ^(see note 2)^
259 | RAID6   | 1            | 2              | 3 to N - 2 | 3/any ^(see note 3)^
260 |=============================================================
261
262 WARNING: It's not recommended to build btrfs with RAID0/1/10/5/6 profiles on
263 partitions from the same device.  Neither redundancy nor performance will be
264 improved.
265
266 'Note 1:' DUP may exist on more than 1 device if it starts on a single device and
267 another one is added. Since version 4.5.1, *mkfs.btrfs* will let you create DUP
268 on multiple devices.
269
270 'Note 2:' It's not recommended to use 2 devices with RAID5. In that case,
271 parity stripe will contain the same data as the data stripe, making RAID5
272 degraded to RAID1 with more overhead.
273
274 'Note 3:' It's also not recommended to use 3 devices with RAID6, unless you
275 want to get effectively 3 copies in a RAID1-like manner (but not exactly that).
276 N-copies RAID1 is not implemented.
277
278 DUP PROFILES ON A SINGLE DEVICE
279 -------------------------------
280
281 The mkfs utility will let the user create a filesystem with profiles that write
282 the logical blocks to 2 physical locations. Whether there are really 2
283 physical copies highly depends on the underlying device type.
284
285 For example, a SSD drive can remap the blocks internally to a single copy--thus
286 deduplicating them. This negates the purpose of increased redundancy and just
287 wastes filesystem space without providing the expected level of redundancy.
288
289 The duplicated data/metadata may still be useful to statistically improve the
290 chances on a device that might perform some internal optimizations. The actual
291 details are not usually disclosed by vendors. For example we could expect that
292 not all blocks get deduplicated. This will provide a non-zero probability of
293 recovery compared to a zero chance if the single profile is used. The user
294 should make the tradeoff decision. The deduplication in SSDs is thought to be
295 widely available so the reason behind the mkfs default is to not give a false
296 sense of redundancy.
297
298 As another example, the widely used USB flash or SD cards use a translation
299 layer between the logical and physical view of the device. The data lifetime
300 may be affected by frequent plugging. The memory cells could get damaged,
301 hopefully not destroying both copies of particular data in case of DUP.
302
303 The wear levelling techniques can also lead to reduced redundancy, even if the
304 device does not do any deduplication. The controllers may put data written in
305 a short timespan into the same physical storage unit (cell, block etc). In case
306 this unit dies, both copies are lost. BTRFS does not add any artificial delay
307 between metadata writes.
308
309 The traditional rotational hard drives usually fail at the sector level.
310
311 In any case, a device that starts to misbehave and repairs from the DUP copy
312 should be replaced! *DUP is not backup*.
313
314 KNOWN ISSUES
315 ------------
316
317 **SMALL FILESYSTEMS AND LARGE NODESIZE**
318
319 The combination of small filesystem size and large nodesize is not recommended
320 in general and can lead to various ENOSPC-related issues during mount time or runtime.
321
322 Since mixed block group creation is optional, we allow small
323 filesystem instances with differing values for 'sectorsize' and 'nodesize'
324 to be created and could end up in the following situation:
325
326   # mkfs.btrfs -f -n 65536 /dev/loop0
327   btrfs-progs v3.19-rc2-405-g976307c
328   See http://btrfs.wiki.kernel.org for more information.
329
330   Performing full device TRIM (512.00MiB) ...
331   Label:              (null)
332   UUID:               49fab72e-0c8b-466b-a3ca-d1bfe56475f0
333   Node size:          65536
334   Sector size:        4096
335   Filesystem size:    512.00MiB
336   Block group profiles:
337     Data:             single            8.00MiB
338     Metadata:         DUP              40.00MiB
339     System:           DUP              12.00MiB
340   SSD detected:       no
341   Incompat features:  extref, skinny-metadata
342   Number of devices:  1
343   Devices:
344     ID        SIZE  PATH
345      1   512.00MiB  /dev/loop0
346
347   # mount /dev/loop0 /mnt/
348   mount: mount /dev/loop0 on /mnt failed: No space left on device
349
350 The ENOSPC occurs during the creation of the UUID tree. This is caused
351 by large metadata blocks and space reservation strategy that allocates more
352 than can fit into the filesystem.
353
354
355 AVAILABILITY
356 ------------
357 *mkfs.btrfs* is part of btrfs-progs.
358 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
359 further details.
360
361 SEE ALSO
362 --------
363 `btrfs`(5),
364 `btrfs`(8),
365 `wipefs`(8)