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