1MKFS.BTRFS(8) Btrfs Manual MKFS.BTRFS(8)
2
3
4
6 mkfs.btrfs - create a btrfs filesystem
7
9 mkfs.btrfs [options] <device> [<device>...]
10
12 mkfs.btrfs is used to create the btrfs filesystem on a single or
13 multiple devices. <device> is typically a block device but can be a
14 file-backed image as well. Multiple devices are grouped by UUID of the
15 filesystem.
16
17 Before mounting such filesystem, the kernel module must know all the
18 devices either via preceding execution of btrfs device scan or using
19 the device mount option. See section MULTIPLE DEVICES for more details.
20
21 The default block group profiles for data and metadata depend on number
22 of devices and possibly other factors. It’s recommended to use specific
23 profiles but the defaults should be OK and allowing future conversions
24 to other profiles. Please see options -d and -m for further detals and
25 btrfs-balance(8) for the profile conversion post mkfs.
26
28 -b|--byte-count <size>
29 Specify the size of the filesystem. If this option is not used,
30 then mkfs.btrfs uses the entire device space for the filesystem.
31
32 --csum <type>, --checksum <type>
33 Specify the checksum algorithm. Default is crc32c. Valid values are
34 crc32c, xxhash, sha256 or blake2. To mount such filesystem kernel
35 must support the checksums as well. See CHECKSUM ALGORITHMS in
36 btrfs(5).
37
38 -d|--data <profile>
39 Specify the profile for the data block groups. Valid values are
40 raid0, raid1, raid1c3, raid1c4, raid5, raid6, raid10 or single or
41 dup (case does not matter).
42
43 See DUP PROFILES ON A SINGLE DEVICE for more details.
44
45 On multiple devices, the default was raid0 until version 5.7, while
46 it is single since version 5.8. You can still select raid0
47 manually, but it was not suitable as default.
48
49 -m|--metadata <profile>
50 Specify the profile for the metadata block groups. Valid values are
51 raid0, raid1, raid1c3, raid1c4, raid5, raid6, raid10, single or dup
52 (case does not matter).
53
54 Default on a single device filesystem is DUP, unless an SSD is
55 detected, in which case it will default to single. The detection is
56 based on the value of /sys/block/DEV/queue/rotational, where DEV is
57 the short name of the device.
58
59 Note that the rotational status can be arbitrarily set by the
60 underlying block device driver and may not reflect the true status
61 (network block device, memory-backed SCSI devices etc). It’s
62 recommended to options --data/--metadata to avoid confusion.
63
64 See DUP PROFILES ON A SINGLE DEVICE for more details.
65
66 On multiple devices the default is raid1.
67
68 -M|--mixed
69 Normally the data and metadata block groups are isolated. The mixed
70 mode will remove the isolation and store both types in the same
71 block group type. This helps to utilize the free space regardless
72 of the purpose and is suitable for small devices. The separate
73 allocation of block groups leads to a situation where the space is
74 reserved for the other block group type, is not available for
75 allocation and can lead to ENOSPC state.
76
77 The recommended size for the mixed mode is for filesystems less
78 than 1GiB. The soft recommendation is to use it for filesystems
79 smaller than 5GiB. The mixed mode may lead to degraded performance
80 on larger filesystems, but is otherwise usable, even on multiple
81 devices.
82
83 The nodesize and sectorsize must be equal, and the block group
84 types must match.
85
86 Note
87 versions up to 4.2.x forced the mixed mode for devices smaller
88 than 1GiB. This has been removed in 4.3+ as it caused some
89 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
96 metadata. The default value is 16KiB (16384) or the page size,
97 whichever is bigger. Must be a multiple of the sectorsize and a
98 power of 2, but not larger than 64KiB (65536). Leafsize always
99 equals nodesize and the options are aliases.
100
101 Smaller node size increases fragmentation but leads to taller
102 b-trees which in turn leads to lower locking contention. Higher
103 node sizes give better packing and less fragmentation at the cost
104 of more expensive memory operations while updating the metadata
105 blocks.
106
107 Note
108 versions up to 3.11 set the nodesize to 4k.
109
110 -s|--sectorsize <size>
111 Specify the sectorsize, the minimum data block allocation unit.
112
113 The default value is the page size and is autodetected. If the
114 sectorsize differs from the page size, the created filesystem may
115 not be mountable by the running kernel. Therefore it is not
116 recommended to use this option unless you are going to mount it on
117 a system with the appropriate page size.
118
119 -L|--label <string>
120 Specify a label for the filesystem. The string should be less than
121 256 bytes and must not contain newline characters.
122
123 -K|--nodiscard
124 Do not perform whole device TRIM operation on devices that are
125 capable of that. This does not affect discard/trim operation when
126 the filesystem is mounted. Please see the mount option discard for
127 that in btrfs(5).
128
129 -r|--rootdir <rootdir>
130 Populate the toplevel subvolume with files from rootdir. This does
131 not require root permissions to write the new files or to mount the
132 filesystem.
133
134 Note
135 This option may enlarge the image or file to ensure it’s big
136 enough to contain the files from rootdir. Since version 4.14.1
137 the filesystem size is not minimized. Please see option
138 --shrink if you need that functionality.
139
140 --shrink
141 Shrink the filesystem to its minimal size, only works with
142 --rootdir option.
143
144 If the destination block device is a regular file, this option will
145 also truncate the file to the minimal size. Otherwise it will
146 reduce the filesystem available space. Extra space will not be
147 usable unless the filesystem is mounted and resized using btrfs
148 filesystem resize.
149
150 Note
151 prior to version 4.14.1, the shrinking was done automatically.
152
153 -O|--features <feature1>[,<feature2>...]
154 A list of filesystem features turned on at mkfs time. Not all
155 features are supported by old kernels. To disable a feature, prefix
156 it with ^.
157
158 See section FILESYSTEM FEATURES for more details. To see all
159 available features that mkfs.btrfs supports run:
160
161 mkfs.btrfs -O list-all
162
163 -R|--runtime-features <feature1>[,<feature2>...]
164 A list of features that be can enabled at mkfs time, otherwise
165 would have to be turned on a mounted filesystem. Although no
166 runtime feature is enabled by default, to disable a feature, prefix
167 it with ^.
168
169 See section RUNTIME FEATURES for more details. To see all available
170 runtime features that mkfs.btrfs supports run:
171
172 mkfs.btrfs -R list-all
173
174 -f|--force
175 Forcibly overwrite the block devices when an existing filesystem is
176 detected. By default, mkfs.btrfs will utilize libblkid to check for
177 any known filesystem on the devices. Alternatively you can use the
178 wipefs utility to clear the devices.
179
180 -q|--quiet
181 Print only error or warning messages. Options --features or --help
182 are unaffected.
183
184 -U|--uuid <UUID>
185 Create the filesystem with the given UUID. The UUID must not exist
186 on any filesystem currently present.
187
188 -V|--version
189 Print the mkfs.btrfs version and exit.
190
191 --help
192 Print help.
193
195 The default unit is byte. All size parameters accept suffixes in the
196 1024 base. The recognized suffixes are: k, m, g, t, p, e, both
197 uppercase and lowercase.
198
200 Before mounting a multiple device filesystem, the kernel module must
201 know the association of the block devices that are attached to the
202 filesystem UUID.
203
204 There is typically no action needed from the user. On a system that
205 utilizes a udev-like daemon, any new block device is automatically
206 registered. The rules call btrfs device scan.
207
208 The same command can be used to trigger the device scanning if the
209 btrfs kernel module is reloaded (naturally all previous information
210 about the device registration is lost).
211
212 Another possibility is to use the mount options device to specify the
213 list of devices to scan at the time of mount.
214
215 # mount -o device=/dev/sdb,device=/dev/sdc /dev/sda /mnt
216
217
218 Note
219 that this means only scanning, if the devices do not exist in the
220 system, mount will fail anyway. This can happen on systems without
221 initramfs/initrd and root partition created with RAID1/10/5/6
222 profiles. The mount action can happen before all block devices are
223 discovered. The waiting is usually done on the initramfs/initrd
224 systems.
225
226 RAID5/6 has known problems and should not be used in production.
227
229 Features that can be enabled during creation time. See also btrfs(5)
230 section FILESYSTEM FEATURES.
231
232 mixed-bg
233 (kernel support since 2.6.37)
234
235 mixed data and metadata block groups, also set by option --mixed
236
237 extref
238 (default since btrfs-progs 3.12, kernel support since 3.7)
239
240 increased hardlink limit per file in a directory to 65536, older
241 kernels supported a varying number of hardlinks depending on the
242 sum of all file name sizes that can be stored into one metadata
243 block
244
245 raid56
246 (kernel support since 3.9)
247
248 extended format for RAID5/6, also enabled if raid5 or raid6 block
249 groups are selected
250
251 skinny-metadata
252 (default since btrfs-progs 3.18, kernel support since 3.10)
253
254 reduced-size metadata for extent references, saves a few percent of
255 metadata
256
257 no-holes
258 (kernel support since 3.14)
259
260 improved representation of file extents where holes are not
261 explicitly stored as an extent, saves a few percent of metadata if
262 sparse files are used
263
265 Features that are typically enabled on a mounted filesystem, eg. by a
266 mount option or by an ioctl. Some of them can be enabled early, at mkfs
267 time. This applies to features that need to be enabled once and then
268 the status is permanent, this does not replace mount options.
269
270 quota
271 (kernel support since 3.4)
272
273 Enable quota support (qgroups). The qgroup accounting will be
274 consistent, can be used together with --rootdir. See also
275 btrfs-quota(8).
276
277 free-space-tree
278 (kernel support since 4.5)
279
280 Enable the free space tree (mount option space_cache=v2) for
281 persisting the free space cache.
282
284 The highlevel organizational units of a filesystem are block groups of
285 three types: data, metadata and system.
286
287 DATA
288 store data blocks and nothing else
289
290 METADATA
291 store internal metadata in b-trees, can store file data if they fit
292 into the inline limit
293
294 SYSTEM
295 store structures that describe the mapping between the physical
296 devices and the linear logical space representing the filesystem
297
298 Other terms commonly used:
299
300 block group, chunk
301 a logical range of space of a given profile, stores data, metadata
302 or both; sometimes the terms are used interchangeably
303
304 A typical size of metadata block group is 256MiB (filesystem
305 smaller than 50GiB) and 1GiB (larger than 50GiB), for data it’s
306 1GiB. The system block group size is a few megabytes.
307
308 RAID
309 a block group profile type that utilizes RAID-like features on
310 multiple devices: striping, mirroring, parity
311
312 profile
313 when used in connection with block groups refers to the allocation
314 strategy and constraints, see the section PROFILES for more details
315
317 There are the following block group types available:
318
319 ┌────────┬────────────────────────────┬─────────────┬─────────────┐
320 │ │ │ │ │
321 │Profile │ Redundancy │ Space │ Min/max │
322 │ ├────────┬────────┬──────────┤ utilization │ devices │
323 │ │ │ │ │ │ │
324 │ │ Copies │ Parity │ Striping │ │ │
325 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
326 │ │ │ │ │ │ │
327 │single │ 1 │ │ │ 100% │ 1/any │
328 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
329 │ │ │ │ │ │ │
330 │DUP │ 2 / 1 │ │ │ 50% │ 1/any ^(see │
331 │ │ device │ │ │ │ note 1) │
332 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
333 │ │ │ │ │ │ │
334 │RAID0 │ │ │ 1 to N │ 100% │ 2/any │
335 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
336 │ │ │ │ │ │ │
337 │RAID1 │ 2 │ │ │ 50% │ 2/any │
338 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
339 │ │ │ │ │ │ │
340 │RAID1C3 │ 3 │ │ │ 33% │ 3/any │
341 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
342 │ │ │ │ │ │ │
343 │RAID1C4 │ 4 │ │ │ 25% │ 4/any │
344 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
345 │ │ │ │ │ │ │
346 │RAID10 │ 2 │ │ 1 to N │ 50% │ 4/any │
347 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
348 │ │ │ │ │ │ │
349 │RAID5 │ 1 │ 1 │ 2 to N-1 │ (N-1)/N │ 2/any ^(see │
350 │ │ │ │ │ │ note 2) │
351 ├────────┼────────┼────────┼──────────┼─────────────┼─────────────┤
352 │ │ │ │ │ │ │
353 │RAID6 │ 1 │ 2 │ 3 to N-2 │ (N-2)/N │ 3/any ^(see │
354 │ │ │ │ │ │ note 3) │
355 └────────┴────────┴────────┴──────────┴─────────────┴─────────────┘
356
357 Warning
358 It’s not recommended to create filesystems with RAID0/1/10/5/6
359 profiles on partitions from the same device. Neither redundancy nor
360 performance will be improved.
361
362 Note 1: DUP may exist on more than 1 device if it starts on a single
363 device and another one is added. Since version 4.5.1, mkfs.btrfs will
364 let you create DUP on multiple devices without restrictions.
365
366 Note 2: It’s not recommended to use 2 devices with RAID5. In that case,
367 parity stripe will contain the same data as the data stripe, making
368 RAID5 degraded to RAID1 with more overhead.
369
370 Note 3: It’s also not recommended to use 3 devices with RAID6, unless
371 you want to get effectively 3 copies in a RAID1-like manner (but not
372 exactly that).
373
374 Note 4: Since kernel 5.5 it’s possible to use RAID1C3 as replacement
375 for RAID6, higher space cost but reliable.
376
377 PROFILE LAYOUT
378 For the following examples, assume devices numbered by 1, 2, 3 and 4,
379 data or metadata blocks A, B, C, D, with possible stripes eg. A1, A2
380 that would be logically A, etc. For parity profiles PA and QA are
381 parity and syndrom, associated with the given stripe. The simple
382 layouts single or DUP are left out. Actual physical block placement on
383 devices depends on current state of the free/allocated space and may
384 appear random. All devices are assumed to be present at the time of the
385 blocks would have been written.
386
387 RAID1
388
389 ┌─────────┬──────────┬──────────┬──────────┐
390 │device 1 │ device 2 │ device 3 │ device 4 │
391 ├─────────┼──────────┼──────────┼──────────┤
392 │ │ │ │ │
393 │ A │ D │ │ │
394 ├─────────┼──────────┼──────────┼──────────┤
395 │ │ │ │ │
396 │ B │ │ │ C │
397 ├─────────┼──────────┼──────────┼──────────┤
398 │ │ │ │ │
399 │ C │ │ │ │
400 ├─────────┼──────────┼──────────┼──────────┤
401 │ │ │ │ │
402 │ D │ A │ B │ │
403 └─────────┴──────────┴──────────┴──────────┘
404
405 RAID1C3
406
407 ┌─────────┬──────────┬──────────┬──────────┐
408 │device 1 │ device 2 │ device 3 │ device 4 │
409 ├─────────┼──────────┼──────────┼──────────┤
410 │ │ │ │ │
411 │ A │ A │ D │ │
412 ├─────────┼──────────┼──────────┼──────────┤
413 │ │ │ │ │
414 │ B │ │ B │ │
415 ├─────────┼──────────┼──────────┼──────────┤
416 │ │ │ │ │
417 │ C │ │ A │ C │
418 ├─────────┼──────────┼──────────┼──────────┤
419 │ │ │ │ │
420 │ D │ D │ C │ B │
421 └─────────┴──────────┴──────────┴──────────┘
422
423 RAID0
424
425 ┌─────────┬──────────┬──────────┬──────────┐
426 │device 1 │ device 2 │ device 3 │ device 4 │
427 ├─────────┼──────────┼──────────┼──────────┤
428 │ │ │ │ │
429 │ A2 │ C3 │ A3 │ C2 │
430 ├─────────┼──────────┼──────────┼──────────┤
431 │ │ │ │ │
432 │ B1 │ A1 │ D2 │ B3 │
433 ├─────────┼──────────┼──────────┼──────────┤
434 │ │ │ │ │
435 │ C1 │ D3 │ B4 │ D1 │
436 ├─────────┼──────────┼──────────┼──────────┤
437 │ │ │ │ │
438 │ D4 │ B2 │ C4 │ A4 │
439 └─────────┴──────────┴──────────┴──────────┘
440
441 RAID5
442
443 ┌─────────┬──────────┬──────────┬──────────┐
444 │device 1 │ device 2 │ device 3 │ device 4 │
445 ├─────────┼──────────┼──────────┼──────────┤
446 │ │ │ │ │
447 │ A2 │ C3 │ A3 │ C2 │
448 ├─────────┼──────────┼──────────┼──────────┤
449 │ │ │ │ │
450 │ B1 │ A1 │ D2 │ B3 │
451 ├─────────┼──────────┼──────────┼──────────┤
452 │ │ │ │ │
453 │ C1 │ D3 │ PB │ D1 │
454 ├─────────┼──────────┼──────────┼──────────┤
455 │ │ │ │ │
456 │ PD │ B2 │ PC │ PA │
457 └─────────┴──────────┴──────────┴──────────┘
458
459 RAID6
460
461 ┌─────────┬──────────┬──────────┬──────────┐
462 │device 1 │ device 2 │ device 3 │ device 4 │
463 ├─────────┼──────────┼──────────┼──────────┤
464 │ │ │ │ │
465 │ A2 │ QC │ QA │ C2 │
466 ├─────────┼──────────┼──────────┼──────────┤
467 │ │ │ │ │
468 │ B1 │ A1 │ D2 │ QB │
469 ├─────────┼──────────┼──────────┼──────────┤
470 │ │ │ │ │
471 │ C1 │ QD │ PB │ D1 │
472 ├─────────┼──────────┼──────────┼──────────┤
473 │ │ │ │ │
474 │ PD │ B2 │ PC │ PA │
475 └─────────┴──────────┴──────────┴──────────┘
476
478 The mkfs utility will let the user create a filesystem with profiles
479 that write the logical blocks to 2 physical locations. Whether there
480 are really 2 physical copies highly depends on the underlying device
481 type.
482
483 For example, a SSD drive can remap the blocks internally to a single
484 copy—thus deduplicating them. This negates the purpose of increased
485 redundancy and just wastes filesystem space without providing the
486 expected level of redundancy.
487
488 The duplicated data/metadata may still be useful to statistically
489 improve the chances on a device that might perform some internal
490 optimizations. The actual details are not usually disclosed by vendors.
491 For example we could expect that not all blocks get deduplicated. This
492 will provide a non-zero probability of recovery compared to a zero
493 chance if the single profile is used. The user should make the tradeoff
494 decision. The deduplication in SSDs is thought to be widely available
495 so the reason behind the mkfs default is to not give a false sense of
496 redundancy.
497
498 As another example, the widely used USB flash or SD cards use a
499 translation layer between the logical and physical view of the device.
500 The data lifetime may be affected by frequent plugging. The memory
501 cells could get damaged, hopefully not destroying both copies of
502 particular data in case of DUP.
503
504 The wear levelling techniques can also lead to reduced redundancy, even
505 if the device does not do any deduplication. The controllers may put
506 data written in a short timespan into the same physical storage unit
507 (cell, block etc). In case this unit dies, both copies are lost. BTRFS
508 does not add any artificial delay between metadata writes.
509
510 The traditional rotational hard drives usually fail at the sector
511 level.
512
513 In any case, a device that starts to misbehave and repairs from the DUP
514 copy should be replaced! DUP is not backup.
515
517 SMALL FILESYSTEMS AND LARGE NODESIZE
518
519 The combination of small filesystem size and large nodesize is not
520 recommended in general and can lead to various ENOSPC-related issues
521 during mount time or runtime.
522
523 Since mixed block group creation is optional, we allow small filesystem
524 instances with differing values for sectorsize and nodesize to be
525 created and could end up in the following situation:
526
527 # mkfs.btrfs -f -n 65536 /dev/loop0
528 btrfs-progs v3.19-rc2-405-g976307c
529 See http://btrfs.wiki.kernel.org for more information.
530
531 Performing full device TRIM (512.00MiB) ...
532 Label: (null)
533 UUID: 49fab72e-0c8b-466b-a3ca-d1bfe56475f0
534 Node size: 65536
535 Sector size: 4096
536 Filesystem size: 512.00MiB
537 Block group profiles:
538 Data: single 8.00MiB
539 Metadata: DUP 40.00MiB
540 System: DUP 12.00MiB
541 SSD detected: no
542 Incompat features: extref, skinny-metadata
543 Number of devices: 1
544 Devices:
545 ID SIZE PATH
546 1 512.00MiB /dev/loop0
547
548 # mount /dev/loop0 /mnt/
549 mount: mount /dev/loop0 on /mnt failed: No space left on device
550
551 The ENOSPC occurs during the creation of the UUID tree. This is caused
552 by large metadata blocks and space reservation strategy that allocates
553 more than can fit into the filesystem.
554
556 mkfs.btrfs is part of btrfs-progs. Please refer to the btrfs wiki
557 http://btrfs.wiki.kernel.org for further details.
558
560 btrfs(5), btrfs(8), btrfs-balance(8), wipefs(8)
561
562
563
564Btrfs v5.12.1 05/13/2021 MKFS.BTRFS(8)