btrfs-progs: docs: update btrfs manual page
[platform/upstream/btrfs-progs.git] / Documentation / btrfs-device.asciidoc
1 btrfs-device(8)
2 ===============
3
4 NAME
5 ----
6 btrfs-device - manage devices of btrfs filesystems
7
8 SYNOPSIS
9 --------
10 *btrfs device* <subcommand> <args>
11
12 DESCRIPTION
13 -----------
14 The *btrfs device* command group is used to manage devices of the btrfs filesystems.
15
16 DEVICE MANAGEMENT
17 -----------------
18 Btrfs filesystem can be created on top of single or multiple block devices.
19 Data and metadata are organized in allocation profiles with various redundancy
20 policies. There's some similarity with traditional RAID levels, but this could
21 be confusing to users familiar with the traditional meaning. Due to the
22 similarity, the RAID terminology is widely used in the documentation.  See
23 `mkfs.btrfs`(9) for more details and the exact profile capabilities and
24 constraints.
25
26 The device management works on a mounted filesystem. Devices can be added,
27 removed or replaced, by commands profided by *btrfs device* and *btrfs replace*.
28
29 The profiles can be also changed, provided there's enough workspace to do the
30 conversion, using the *btrfs balance* comand and namely the filter 'convert'.
31
32 Profile::
33 A profile describes an allocation policy based on the redundancy/replication
34 constrants in connection with the number of devices. The profile applies to
35 data and metadata block groups separately.
36
37 RAID level::
38 Where applicable, the level refers to a profile that matches constraints of the
39 standard RAID levels. At the moment the supported ones are: RAID0, RAID1,
40 RAID10, RAID5 and RAID6.
41
42 See the section *TYPICAL USECASES* for some examples.
43
44 SUBCOMMAND
45 ----------
46 *add* [-Kf] <dev> [<dev>...] <path>::
47 Add device(s) to the filesystem identified by <path>.
48 +
49 If applicable, a whole device discard (TRIM) operation is performed prior to
50 adding the device. A device with existing filesystem detected by `blkid`(8)
51 will prevent device addition and has to be forced. Alternatively the filesystem
52 can be wiped from the device using eg. the `wipefs`(8) tool.
53 +
54 The operation is instant and does not affect existing data. The operation merely
55 adds the device to the filesystem structures and creates some block groups
56 headers.
57 +
58 `Options`
59 +
60 -K|--nodiscard::::
61 do not perform discard (TRIM) by default
62 -f|--force::::
63 force overwrite of existing filesystem on the given disk(s)
64
65 *remove* <dev>|<devid> [<dev>|<devid>...] <path>::
66 Remove device(s) from a filesystem identified by <path>
67 +
68 Device removal must satisfy the profile constraints, otherwise the command
69 fails. The filesystem must be converted to profile(s) that would allow the
70 removal. This can typically happen when going down from 2 devices to 1 and
71 using the RAID1 profile. See the example section below.
72 +
73 The operation can take long as it needs to move all data from the device.
74 +
75 NOTE: It is not possible to delete the device that was used to mount the
76 filesystem. This is a limitation given by the VFS.
77
78 *delete* <dev>|<devid> [<dev>|<devid>...] <path>::
79 Alias of remove kept for backward compatibility
80
81 *ready* <device>::
82 Wait until all devices of a multiple-device filesystem are scanned and registered
83 within the kernel module.
84
85 *scan* [(--all-devices|-d)|<device> [<device>...]]::
86 Scan devices for a btrfs filesystem and register them with the kernel module.
87 This allows mounting multiple-device filesystem by specifying just one from the
88 whole group.
89 +
90 If no devices are passed, all block devices that blkid reports to contain btrfs
91 are scanned.
92 +
93 The options '--all-devices' or '-d' are deprecated and kept for backward compatibility.
94 If used, behavior is the same as if no devices are passed.
95 +
96 The command can be run repeatedly. Devices that have been already registered
97 remain as such. Reloading the kernel module will drop this information. There's
98 an alternative way of mounting multiple-device filesystem without the need for
99 prior scanning. See the mount option 'device'.
100
101 *stats* [-z] <path>|<device>::
102 Read and print the device IO error statistics for all devices of the given
103 filesystem identified by <path> or for a single <device>. See section *DEVICE
104 STATS* for more information.
105 +
106 `Options`
107 +
108 -z::::
109 Print the stats and reset the values to zero afterwards.
110
111 *usage* [options] <path> [<path>...]::
112 Show detailed information about internal allocations in devices.
113 +
114 `Options`
115 +
116 -b|--raw::::
117 raw numbers in bytes, without the 'B' suffix
118 -h|--human-readable::::
119 print human friendly numbers, base 1024, this is the default
120 -H::::
121 print human friendly numbers, base 1000
122 --iec::::
123 select the 1024 base for the following options, according to the IEC standard
124 --si::::
125 select the 1000 base for the following options, according to the SI standard
126 -k|--kbytes::::
127 show sizes in KiB, or kB with --si
128 -m|--mbytes::::
129 show sizes in MiB, or MB with --si
130 -g|--gbytes::::
131 show sizes in GiB, or GB with --si
132 -t|--tbytes::::
133 show sizes in TiB, or TB with --si
134
135 If conflicting options are passed, the last one takes precedence.
136
137 TYPICAL USECASES
138 ----------------
139
140 STARTING WITH A SINGLE-DEVICE FILESYSTEM
141 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142
143 Assume we've created a filesystem on a block device '/dev/sda' with profile
144 'single/single' (data/metadata), the device size is 50GiB and we've used the
145 whole device for the filesystem. The mount point is '/mnt'.
146
147 The amount of data stored is 16GiB, metadata have allocated 2GiB.
148
149 ==== ADD NEW DEVICE ====
150
151 We want to increase the total size of the filesystem and keep the profiles. The
152 size of the new device '/dev/sdb' is 100GiB.
153
154  $ btrfs device add /dev/sdb /mnt
155
156 The amount of free data space increases by less than 100GiB, some space is
157 allocated for metadata.
158
159 ==== CONVERT TO RAID1 ====
160
161 Now we want to increase the redundancy level of both data and metadata, but
162 we'll do that in steps. Note, that the device sizes are not equal and we'll use
163 that to show the capabilities of split data/metadata and independent profiles.
164
165 The constraint for RAID1 gives us at most 50GiB of usable space and exactly 2
166 copies will be stored on the devices.
167
168 First we'll convert the metadata. As the metadata occupy less than 50GiB and
169 there's enough workspace for the conversion process, we can do:
170
171  $ btrfs balance start -mconvert=raid1 /mnt
172
173 This operation can take a while as the metadata have to be moved and all block
174 pointers updated. Depending on the physical locations of the old and new
175 blocks, the disk seeking is the key factor affecting performance.
176
177 You'll note that the system block group has been also converted to RAID1, this
178 normally happens as the system block group also holds metadata (the physical to
179 logial mappings).
180
181 What changed:
182
183 * available data space decreased by 3GiB, usable rougly (50 - 3) + (100 - 3) = 144 GiB
184 * metadata redundancy increased
185
186 IOW, the unequal device sizes allow for combined space for data yet improved
187 redundancy for metadata. If we decide to increase redundancy of data as well,
188 we're going to lose 50GiB of the second device for obvious reasons.
189
190  $ btrfs balance start -dconvert=raid1 /mnt
191
192 The balance process needs some workspace (ie. a free device space without any
193 data or metadata block groups) so the command could fail if there's too much
194 data or the block groups occupy the whole first device.
195
196 The device size of '/dev/sdb' as seen by the filesystem remains unchanged, but
197 the logical space from 50-100GiB will be unused.
198
199 DEVICE STATS
200 ------------
201
202 The device stats keep persistent record of several error classes related to
203 doing IO. The current values are printed at mount time and updated during
204 filesystem lifetime or from a scrub run.
205
206  $ btrfs device stats /dev/sda3
207  [/dev/sda3].write_io_errs   0
208  [/dev/sda3].read_io_errs    0
209  [/dev/sda3].flush_io_errs   0
210  [/dev/sda3].corruption_errs 0
211  [/dev/sda3].generation_errs 0
212
213 write_io_errs::
214 Failed writes to the block devices, means that the layers beneath the
215 filesystem were not able to satisfy the write request.
216 read_io_errors::
217 Read request analogy to write_io_errs.
218 flush_io_errs::
219 Number of failed writes with the 'FLUSH' flag set. The flushing is a method of
220 forcing a particular order between write requests and is crucial for
221 implementing crash consistency. In case of btrfs, all the metadata blocks must
222 be permanently stored on the block device before the superblock is written.
223 corruption_errs::
224 A block checksum mismatched or a corrupted metadata header was found.
225 generation_errs::
226 The block generation does not match the expected value (eg. stored in the
227 parent node).
228
229 EXIT STATUS
230 -----------
231 *btrfs device* returns a zero exit status if it succeeds. Non zero is
232 returned in case of failure.
233
234 AVAILABILITY
235 ------------
236 *btrfs* is part of btrfs-progs.
237 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
238 further details.
239
240 SEE ALSO
241 --------
242 `mkfs.btrfs`(8),
243 `btrfs-replace`(8),
244 `btrfs-balance`(8)