btrfs-progs: docs: enhance manual page for mkfs
[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', (case does not matter).
54
55 *-m|--metadata <profile>*::
56 Specify the profile for the metadata block groups.
57 Valid values are 'raid0', 'raid1', 'raid5', 'raid6', 'raid10', 'single' or
58 'dup', (case does not matter).
59 +
60 A single device filesystem will default to 'DUP', unless a SSD is detected. Then
61 it will default to 'single'. The detection is based on the value of
62 `/sys/block/DEV/queue/rotational`, where 'DEV' is the short name of the device.
63 This is because SSDs can remap the blocks internally to a single copy thus
64 deduplicating them which negates the purpose of increased metadata redunancy
65 and just wastes space. 
66 +
67 Note that the rotational status can be arbitrarily set by the underlying block
68 device driver and may not reflect the true status (network block device, memory-backed
69 SCSI devices etc). Use the options '--data/--metadata' to avoid confusion.
70
71 *-M|--mixed*::
72 Normally the data and metadata block groups are isolated. The 'mixed' mode
73 will remove the isolation and store both types in the same block group type.
74 This helps to utilize the free space regardless of the purpose and is suitable
75 for small devices. The separate allocation of block groups leads to a situation
76 where the space is reserved for the other block group type, is not available for
77 allocation and can lead to ENOSPC state.
78 +
79 The recommended size for the mixed mode is for filesystems less than 1GiB. The
80 soft recommendation is to use it for filesystems smaller than 5GiB. Thie mixed
81 mode may lead to degraded performance on larger filesystems, but is otherwise
82 usable, even on multiple devices.
83 +
84 The 'nodesize' and 'sectorsize' must be equal, and the block group types must
85 match.
86 +
87 NOTE: versions up to 4.2.x forced the mixed mode for devices smaller than 1GiB.
88 This has been removed in 4.3+ as it caused some usability issues.
89
90 *-l|--leafsize <size>*::
91 Alias for --nodesize. Deprecated.
92
93 *-n|--nodesize <size>*::
94 Specify the nodesize, the tree block size in which btrfs stores metadata. The
95 default value is 16KiB (16384) or the page size, whichever is bigger. Must be a
96 multiple of the sectorsize, but not larger than 64KiB (65536).  Leafsize always
97 equals nodesize and the options are aliases.
98 +
99 Smaller node size increases fragmentation but lead to higher b-trees which in
100 turn leads to lower locking contention. Higher node sizes give better packing
101 and less fragmentation at the cost of more expensive memory operations while
102 updating the metadata blocks.
103 +
104 NOTE: versions up to 3.11 set the nodesize to 4k.
105
106 *-s|--sectorsize <size>*::
107 Specify the sectorsize, the minimum data block allocation unit.
108 +
109 The default value is the page size and is autodetected. If the sectorsize
110 differs from the page size, the created filesystem may not be mountable by the
111 kernel. Therefore it is not recommended to use this option unless you are going
112 to mount it on a system with the appropriate page size.
113
114 *-L|--label <string>*::
115 Specify a label for the filesystem. The 'string' should be less than 256
116 bytes and must not contain newline characters.
117
118 *-K|--nodiscard*::
119 Do not perform whole device TRIM operation on devices that are capable of that.
120
121 *-r|--rootdir <rootdir>*::
122 Populate the toplevel subvolume with files from 'rootdir'.  This does not
123 require root permissions and does not mount the filesystem.
124
125 *-O|--features <feature1>[,<feature2>...]*::
126 A list of filesystem features turned on at mkfs time. Not all features are
127 supported by old kernels. To disable a feature, prefix it with '^'.
128 +
129 See section *FILESYSTEM FEATURES* for more details.  To see all available
130 features that mkfs.btrfs supports run:
131 +
132 +mkfs.btrfs -O list-all+
133
134 *-f|--force*::
135 Forcibly overwrite the block devices when an existing filesystem is detected.
136 By default, mkfs.btrfs will utilize 'libblkid' to check for any known
137 filesystem on the devices. Alternatively you can use the `wipefs` utility
138 to clear the devices.
139
140 *-q|--quiet*::
141 Print only error or warning messages. Options --features or --help are unaffected.
142
143 *-U|--uuid <UUID>*::
144 Create the filesystem with the given 'UUID'. The UUID must not exist on any
145 filesystem currently present.
146
147 *-V|--version*::
148 Print the *mkfs.btrfs* version and exit.
149
150 *--help*::
151 Print help.
152
153 SIZE UNITS
154 ----------
155 The default unit is 'byte'. All size parameters accept suffixes in the 1024
156 base. The recognized suffixes are: 'k', 'm', 'g', 't', 'e', both uppercase and
157 lowercase.
158
159 MULTIPLE DEVICES
160 ----------------
161
162 Before mounting a multiple device filesystem, the kernel module must know the
163 association of the block devices that are attached to the filesystem UUID.
164
165 There is typically no action needed from the user.  On a system that utilizes a
166 udev-like daemon, any new block device is automatically registered. The rules
167 call *btrfs device scan*.
168
169 The same command can be used to trigger the device scanning if the btrfs kernel
170 module is reloaded (naturally all previous information about the device
171 registration is lost).
172
173 Another possibility is to use the mount options *device* to specify the list of
174 devices to scan at the time of mount.
175
176  # mount -o device=/dev/sdb,device=/dev/sdc /dev/sda /mnt
177
178 NOTE: that this means only scanning, if the devices do not exist in the system,
179 mount will fail anyway. This can happen on systems without initramfs/initrd and
180 root partition created with RAID1/10/5/6 profiles. The mount action can happen
181 before all block devices are discovered. The waiting is usually done on the
182 initramfs/initrd systems.
183
184 FILESYSTEM FEATURES
185 -------------------
186
187 *mixed-bg*::
188 mixed data and metadata block groups, also set by option '--mixed'
189
190 *extref*::
191 (default since btrfs-progs 3.12, kernel support since 3.7)
192 +
193 increased hardlink limit per file in a directory to 65536, older kernels
194 supported a varying number of hardlinks depending on the sum of all file name
195 sizes that can be stored into one metadata block
196
197 *raid56*::
198 extended format for RAID5/6, also enabled if raid5 or raid6 block groups
199 are selected
200
201 *skinny-metadata*::
202 (default since btrfs-progs 3.18, kernel support since 3.10)
203 +
204 reduced-size metadata for extent references, saves a few percent of metadata
205
206 *no-holes*::
207 improved representation of file extents where holes are not explicitly
208 stored as an extent, saves a few percent of metadata if sparse files are used
209
210 BLOCK GROUPS, CHUNKS, RAID
211 --------------------------
212
213 The highlevel organizational units of a filesystem are block groups of three types:
214 data, metadata and system.
215
216 *DATA*::
217 store data blocks and nothing else
218
219 *METADATA*::
220 store internal metadata in b-trees, can store file data if they fit into the
221 inline limit
222
223 *SYSTEM*::
224 store structures that describe the mapping between the physical devices and the
225 linear logical space representing the filesystem
226
227 Other terms commonly used:
228
229 *block group*::
230 *chunk*::
231 a logical range of space of a given profile, stores data, metadata or both;
232 sometimes the terms are used interchangably
233 +
234 A typical size of metadata block group is 256MiB (filesystem smaller than
235 50GiB) and 1GiB (larger than 50GiB), for data it's 1GiB. The system block group
236 size is a few megabytes.
237
238 *RAID*::
239 a block group profile type that utilizes RAID-like features on multiple
240 devices: striping, mirroring, parity
241
242 *profile*::
243 when used in connection with block groups refers to the allocation strategy
244 and constraints, see the section 'PROFILES' for more details
245
246 PROFILES
247 --------
248
249 There are the following block group types available:
250
251 [ width="60%",options="header" ]
252 |=============================================================
253 | Profile | Redundancy          | Striping   | Min/max devices
254 | single  | 1 copy              | n/a        | 1/any
255 | DUP     | 2 copies / 1 device | n/a        | 1/1
256 | RAID0   | n/a                 | 1 to N     | 2/any
257 | RAID10  | 2 copies            | 1 to N     | 4/any
258 | RAID5   | 2 copies            | 3 to N - 1 | 2/any
259 | RAID6   | 3 copies            | 3 to N - 2 | 3/any
260 |=============================================================
261
262 KNOWN ISSUES
263 ------------
264
265 **SMALL FILESYSTEMS AND LARGE NODESIZE**
266
267 The combination of small filesystem size and large nodesize is not recommended
268 in general and can lead to various ENOSPC-related issues during mount time or runtime.
269
270 Since mixed block group creation is optional, we allow small
271 filesystem instances with differing values for 'sectorsize' and 'nodesize'
272 to be created and could end up in the following situation:
273
274   # mkfs.btrfs -f -n 65536 /dev/loop0
275   btrfs-progs v3.19-rc2-405-g976307c
276   See http://btrfs.wiki.kernel.org for more information.
277
278   Performing full device TRIM (512.00MiB) ...
279   Label:              (null)
280   UUID:               49fab72e-0c8b-466b-a3ca-d1bfe56475f0
281   Node size:          65536
282   Sector size:        4096
283   Filesystem size:    512.00MiB
284   Block group profiles:
285     Data:             single            8.00MiB
286     Metadata:         DUP              40.00MiB
287     System:           DUP              12.00MiB
288   SSD detected:       no
289   Incompat features:  extref, skinny-metadata
290   Number of devices:  1
291   Devices:
292     ID        SIZE  PATH
293      1   512.00MiB  /dev/loop0
294
295   # mount /dev/loop0 /mnt/
296   mount: mount /dev/loop0 on /mnt failed: No space left on device
297
298 The ENOSPC occurs during the creation of the UUID tree. This is caused
299 by large metadata blocks and space reservation strategy that allocates more
300 than can fit into the filesystem.
301
302
303 AVAILABILITY
304 ------------
305 *mkfs.btrfs* is part of btrfs-progs.
306 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
307 further details.
308
309 SEE ALSO
310 --------
311 `btrfs`(8), `wipefs`(8)