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