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