1MKFS.BTRFS(8)                    Btrfs Manual                    MKFS.BTRFS(8)
2
3
4

NAME

6       mkfs.btrfs - create a btrfs filesystem
7

SYNOPSIS

9       mkfs.btrfs [options] <device> [<device>...]
10

DESCRIPTION

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

OPTIONS

22       -A|--alloc-start <offset>
23           (An option to help debugging chunk allocator.) Specify the
24           (physical) offset from the start of the device at which allocations
25           start. The default value is zero.
26
27       -b|--byte-count <size>
28           Specify the size of the filesystem. If this option is not used,
29           mkfs.btrfs uses the entire device space for the filesystem.
30
31       -d|--data <profile>
32           Specify the profile for the data block groups. Valid values are
33           raid0, raid1, raid5, raid6, raid10 or single or dup (case does not
34           matter).
35
36           See DUP PROFILES ON A SINGLE DEVICE for more.
37
38       -m|--metadata <profile>
39           Specify the profile for the metadata block groups. Valid values are
40           raid0, raid1, raid5, raid6, raid10, single or dup, (case does not
41           matter).
42
43           A single device filesystem will default to DUP, unless a SSD is
44           detected. Then it will default to single. The detection is based on
45           the value of /sys/block/DEV/queue/rotational, where DEV is the
46           short name of the device.
47
48           Note that the rotational status can be arbitrarily set by the
49           underlying block device driver and may not reflect the true status
50           (network block device, memory-backed SCSI devices etc). Use the
51           options --data/--metadata to avoid confusion.
52
53           See DUP PROFILES ON A SINGLE DEVICE for more details.
54
55       -M|--mixed
56           Normally the data and metadata block groups are isolated. The mixed
57           mode will remove the isolation and store both types in the same
58           block group type. This helps to utilize the free space regardless
59           of the purpose and is suitable for small devices. The separate
60           allocation of block groups leads to a situation where the space is
61           reserved for the other block group type, is not available for
62           allocation and can lead to ENOSPC state.
63
64           The recommended size for the mixed mode is for filesystems less
65           than 1GiB. The soft recommendation is to use it for filesystems
66           smaller than 5GiB. The mixed mode may lead to degraded performance
67           on larger filesystems, but is otherwise usable, even on multiple
68           devices.
69
70           The nodesize and sectorsize must be equal, and the block group
71           types must match.
72
73               Note
74               versions up to 4.2.x forced the mixed mode for devices smaller
75               than 1GiB. This has been removed in 4.3+ as it caused some
76               usability issues.
77
78       -l|--leafsize <size>
79           Alias for --nodesize. Deprecated.
80
81       -n|--nodesize <size>
82           Specify the nodesize, the tree block size in which btrfs stores
83           metadata. The default value is 16KiB (16384) or the page size,
84           whichever is bigger. Must be a multiple of the sectorsize, but not
85           larger than 64KiB (65536). Leafsize always equals nodesize and the
86           options are aliases.
87
88           Smaller node size increases fragmentation but lead to higher
89           b-trees which in turn leads to lower locking contention. Higher
90           node sizes give better packing and less fragmentation at the cost
91           of more expensive memory operations while updating the metadata
92           blocks.
93
94               Note
95               versions up to 3.11 set the nodesize to 4k.
96
97       -s|--sectorsize <size>
98           Specify the sectorsize, the minimum data block allocation unit.
99
100           The default value is the page size and is autodetected. If the
101           sectorsize differs from the page size, the created filesystem may
102           not be mountable by the kernel. Therefore it is not recommended to
103           use this option unless you are going to mount it on a system with
104           the appropriate page size.
105
106       -L|--label <string>
107           Specify a label for the filesystem. The string should be less than
108           256 bytes and must not contain newline characters.
109
110       -K|--nodiscard
111           Do not perform whole device TRIM operation on devices that are
112           capable of that. This does not affect discard/trim operation when
113           the filesystem is mounted. Please see the mount option discard for
114           that in btrfs(5).
115
116       -r|--rootdir <rootdir>
117           Populate the toplevel subvolume with files from rootdir. This does
118           not require root permissions and does not mount the filesystem.
119
120       -O|--features <feature1>[,<feature2>...]
121           A list of filesystem features turned on at mkfs time. Not all
122           features are supported by old kernels. To disable a feature, prefix
123           it with ^.
124
125           See section FILESYSTEM FEATURES for more details. To see all
126           available features that mkfs.btrfs supports run:
127
128           mkfs.btrfs -O list-all
129
130       -f|--force
131           Forcibly overwrite the block devices when an existing filesystem is
132           detected. By default, mkfs.btrfs will utilize libblkid to check for
133           any known filesystem on the devices. Alternatively you can use the
134           wipefs utility to clear the devices.
135
136       -q|--quiet
137           Print only error or warning messages. Options --features or --help
138           are unaffected.
139
140       -U|--uuid <UUID>
141           Create the filesystem with the given UUID. The UUID must not exist
142           on any filesystem currently present.
143
144       -V|--version
145           Print the mkfs.btrfs version and exit.
146
147       --help
148           Print help.
149

SIZE UNITS

151       The default unit is byte. All size parameters accept suffixes in the
152       1024 base. The recognized suffixes are: k, m, g, t, p, e, both
153       uppercase and lowercase.
154

MULTIPLE DEVICES

156       Before mounting a multiple device filesystem, the kernel module must
157       know the association of the block devices that are attached to the
158       filesystem UUID.
159
160       There is typically no action needed from the user. On a system that
161       utilizes a udev-like daemon, any new block device is automatically
162       registered. The rules call btrfs device scan.
163
164       The same command can be used to trigger the device scanning if the
165       btrfs kernel module is reloaded (naturally all previous information
166       about the device registration is lost).
167
168       Another possibility is to use the mount options device to specify the
169       list of devices to scan at the time of mount.
170
171           # mount -o device=/dev/sdb,device=/dev/sdc /dev/sda /mnt
172
173
174           Note
175           that this means only scanning, if the devices do not exist in the
176           system, mount will fail anyway. This can happen on systems without
177           initramfs/initrd and root partition created with RAID1/10/5/6
178           profiles. The mount action can happen before all block devices are
179           discovered. The waiting is usually done on the initramfs/initrd
180           systems.
181
182       As of kernel 4.9, RAID5/6 is still considered experimental and
183       shouldn’t be employed for production use.
184

FILESYSTEM FEATURES

186       Features that can be enabled during creation time. See also btrfs(5)
187       section FILESYSTEM FEATURES.
188
189       mixed-bg
190           (kernel support since 2.6.37)
191
192           mixed data and metadata block groups, also set by option --mixed
193
194       extref
195           (default since btrfs-progs 3.12, kernel support since 3.7)
196
197           increased hardlink limit per file in a directory to 65536, older
198           kernels supported a varying number of hardlinks depending on the
199           sum of all file name sizes that can be stored into one metadata
200           block
201
202       raid56
203           (kernel support since 3.9)
204
205           extended format for RAID5/6, also enabled if raid5 or raid6 block
206           groups are selected
207
208       skinny-metadata
209           (default since btrfs-progs 3.18, kernel support since 3.10)
210
211           reduced-size metadata for extent references, saves a few percent of
212           metadata
213
214       no-holes
215           (kernel support since 3.14)
216
217           improved representation of file extents where holes are not
218           explicitly stored as an extent, saves a few percent of metadata if
219           sparse files are used
220

BLOCK GROUPS, CHUNKS, RAID

222       The highlevel organizational units of a filesystem are block groups of
223       three types: data, metadata and system.
224
225       DATA
226           store data blocks and nothing else
227
228       METADATA
229           store internal metadata in b-trees, can store file data if they fit
230           into the inline limit
231
232       SYSTEM
233           store structures that describe the mapping between the physical
234           devices and the linear logical space representing the filesystem
235
236       Other terms commonly used:
237
238       block group, chunk
239           a logical range of space of a given profile, stores data, metadata
240           or both; sometimes the terms are used interchangeably
241
242           A typical size of metadata block group is 256MiB (filesystem
243           smaller than 50GiB) and 1GiB (larger than 50GiB), for data it’s
244           1GiB. The system block group size is a few megabytes.
245
246       RAID
247           a block group profile type that utilizes RAID-like features on
248           multiple devices: striping, mirroring, parity
249
250       profile
251           when used in connection with block groups refers to the allocation
252           strategy and constraints, see the section PROFILES for more details
253

PROFILES

255       There are the following block group types available:
256
257       ┌────────┬────────────────────────────────────┬────────────┐
258       │        │                                    │            │
259Profile Redundancy                         Min/max   
260       │        ├──────────────┬────────┬────────────┤  devices   
261       │        │              │        │            │            │
262       │        │    Copies    Parity Striping  │            │
263       ├────────┼──────────────┼────────┼────────────┼────────────┤
264       │        │              │        │            │            │
265       │single  │      1       │        │            │   1/any    │
266       ├────────┼──────────────┼────────┼────────────┼────────────┤
267       │        │              │        │            │            │
268       │  DUP   │ 2 / 1 device │        │            │ 1/any (see │
269       │        │              │        │            │ note 1)    │
270       ├────────┼──────────────┼────────┼────────────┼────────────┤
271       │        │              │        │            │            │
272       │ RAID0  │              │        │   1 to N   │   2/any    │
273       ├────────┼──────────────┼────────┼────────────┼────────────┤
274       │        │              │        │            │            │
275       │ RAID1  │      2       │        │            │   2/any    │
276       ├────────┼──────────────┼────────┼────────────┼────────────┤
277       │        │              │        │            │            │
278       │RAID10  │      2       │        │   1 to N   │   4/any    │
279       ├────────┼──────────────┼────────┼────────────┼────────────┤
280       │        │              │        │            │            │
281       │ RAID5  │      1       │   1    │ 2 to N - 1 │ 2/any (see │
282       │        │              │        │            │ note 2)    │
283       ├────────┼──────────────┼────────┼────────────┼────────────┤
284       │        │              │        │            │            │
285       │ RAID6  │      1       │   2    │ 3 to N - 2 │ 3/any (see │
286       │        │              │        │            │ note 3)    │
287       └────────┴──────────────┴────────┴────────────┴────────────┘
288
289           Warning
290           It’s not recommended to build btrfs with RAID0/1/10/5/6 profiles on
291           partitions from the same device. Neither redundancy nor performance
292           will be improved.
293
294       Note 1: DUP may exist on more than 1 device if it starts on a single
295       device and another one is added. Since version 4.5.1, mkfs.btrfs will
296       let you create DUP on multiple devices.
297
298       Note 2: It’s not recommended to use 2 devices with RAID5. In that case,
299       parity stripe will contain the same data as the data stripe, making
300       RAID5 degraded to RAID1 with more overhead.
301
302       Note 3: It’s also not recommended to use 3 devices with RAID6, unless
303       you want to get effectively 3 copies in a RAID1-like manner (but not
304       exactly that). N-copies RAID1 is not implemented.
305

DUP PROFILES ON A SINGLE DEVICE

307       The mkfs utility will let the user create a filesystem with profiles
308       that write the logical blocks to 2 physical locations. Whether there
309       are really 2 physical copies highly depends on the underlying device
310       type.
311
312       For example, a SSD drive can remap the blocks internally to a single
313       copy thus deduplicating them. This negates the purpose of increased
314       redundancy and just wastes filesystem space without the expected level
315       of redundancy.
316
317       The duplicated data/metadata may still be useful to statistically
318       improve the chances on a device that might perform some internal
319       optimizations. The actual details are not usually disclosed by vendors.
320       For example we could expect that not all blocks get deduplicated. This
321       will provide a non-zero probability of recovery compared to a zero
322       chance if the single profile is used. The user should make the tradeoff
323       decision. The deduplication in SSDs is thought to be widely available
324       so the reason behind the mkfs default is to not give a false sense of
325       redundancy.
326
327       As another example, the widely used USB flash or SD cards use a
328       translation layer between the logical and physical view of the device.
329       The data lifetime may be affected by frequent plugging. The memory
330       cells could get damaged, hopefully not destroying both copies of
331       particular data in case of DUP.
332
333       The wear levelling techniques can also lead to reduced redundancy, even
334       if the device does not do any deduplication. The controllers may put
335       data written in a short timespan into the same physical storage unit
336       (cell, block etc). In case this unit dies, both copies are lost. BTRFS
337       does not add any artificial delay between metadata writes.
338
339       The traditional rotational hard drives usually fail at the sector
340       level.
341
342       In any case, a device that starts to misbehave and repairs from the DUP
343       copy should be replaced! DUP is not backup.
344

KNOWN ISSUES

346       SMALL FILESYSTEMS AND LARGE NODESIZE
347
348       The combination of small filesystem size and large nodesize is not
349       recommended in general and can lead to various ENOSPC-related issues
350       during mount time or runtime.
351
352       Since mixed block group creation is optional, we allow small filesystem
353       instances with differing values for sectorsize and nodesize to be
354       created and could end up in the following situation:
355
356           # mkfs.btrfs -f -n 65536 /dev/loop0
357           btrfs-progs v3.19-rc2-405-g976307c
358           See http://btrfs.wiki.kernel.org for more information.
359
360           Performing full device TRIM (512.00MiB) ...
361           Label:              (null)
362           UUID:               49fab72e-0c8b-466b-a3ca-d1bfe56475f0
363           Node size:          65536
364           Sector size:        4096
365           Filesystem size:    512.00MiB
366           Block group profiles:
367             Data:             single            8.00MiB
368             Metadata:         DUP              40.00MiB
369             System:           DUP              12.00MiB
370           SSD detected:       no
371           Incompat features:  extref, skinny-metadata
372           Number of devices:  1
373           Devices:
374             ID        SIZE  PATH
375              1   512.00MiB  /dev/loop0
376
377           # mount /dev/loop0 /mnt/
378           mount: mount /dev/loop0 on /mnt failed: No space left on device
379
380       The ENOSPC occurs during the creation of the UUID tree. This is caused
381       by large metadata blocks and space reservation strategy that allocates
382       more than can fit into the filesystem.
383

AVAILABILITY

385       mkfs.btrfs is part of btrfs-progs. Please refer to the btrfs wiki
386       http://btrfs.wiki.kernel.org for further details.
387

SEE ALSO

389       btrfs(5), btrfs(8), wipefs(8)
390
391
392
393Btrfs v4.9.1                      08/06/2017                     MKFS.BTRFS(8)
Impressum