223ade5c52dbda6a3f47baba199661ca41354028
[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`(8) 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 provided 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* command and namely the filter 'convert'.
31
32 Profile::
33 A profile describes an allocation policy based on the redundancy/replication
34 constraints 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] <device> [<device>...] <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* <device>|<devid> [<device>|<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 *TYPICAL USECASES* section below.
72 +
73 The operation can take long as it needs to move all data from the device.
74 +
75 It is possible to delete the device that was used to mount the filesystem. The
76 device entry in the mount table will be replaced by another device name with
77 the lowest device id.
78 +
79 If the filesystem is mounted in degraded mode (-o degraded), special term
80 'missing' can be used for 'device'. In that case, the first device that is
81 described by the filesystem metadata, but not present at the mount time will be
82 removed.
83 +
84 NOTE: In most cases, there is only one missing device in degraded mode,
85 otherwise mount fails. If there are two or more devices missing (e.g. possible
86 in RAID6), you need specify 'missing' as many times as the number of missing
87 devices to remove all of them.
88
89 *delete* <device>|<devid> [<device>|<devid>...] <path>::
90 Alias of remove kept for backward compatibility
91
92 *ready* <device>::
93 Wait until all devices of a multiple-device filesystem are scanned and
94 registered within the kernel module. This is to provide a way for automatic
95 filesystem mounting tools to wait before the mount can start. The device scan
96 is only one of the preconditions and the mount can fail for other reasons.
97 Normal users usually do not need this command and may safely ignore it.
98
99 *scan* [(--all-devices|-d)|<device> [<device>...]]::
100 Scan devices for a btrfs filesystem and register them with the kernel module.
101 This allows mounting multiple-device filesystem by specifying just one from the
102 whole group.
103 +
104 If no devices are passed, all block devices that blkid reports to contain btrfs
105 are scanned.
106 +
107 The options '--all-devices' or '-d' are deprecated and kept for backward compatibility.
108 If used, behavior is the same as if no devices are passed.
109 +
110 The command can be run repeatedly. Devices that have been already registered
111 remain as such. Reloading the kernel module will drop this information. There's
112 an alternative way of mounting multiple-device filesystem without the need for
113 prior scanning. See the mount option 'device'.
114
115 *stats* [options] <path>|<device>::
116 Read and print the device IO error statistics for all devices of the given
117 filesystem identified by <path> or for a single <device>. The filesystem must
118 be mounted.  See section *DEVICE STATS* for more information about the reported
119 statistics and the meaning.
120 +
121 `Options`
122 +
123 -z|--reset::::
124 Print the stats and reset the values to zero afterwards.
125
126 -c|--check::::
127 Check if the stats are all zeros and return 0 it this is so. Set bit 6 of the
128 return code if any of the statistics is no-zero. The error values is 65 if
129 reading stats from at least one device failed, otherwise it's 64.
130
131 *usage* [options] <path> [<path>...]::
132 Show detailed information about internal allocations in devices.
133 +
134 `Options`
135 +
136 -b|--raw::::
137 raw numbers in bytes, without the 'B' suffix
138 -h|--human-readable::::
139 print human friendly numbers, base 1024, this is the default
140 -H::::
141 print human friendly numbers, base 1000
142 --iec::::
143 select the 1024 base for the following options, according to the IEC standard
144 --si::::
145 select the 1000 base for the following options, according to the SI standard
146 -k|--kbytes::::
147 show sizes in KiB, or kB with --si
148 -m|--mbytes::::
149 show sizes in MiB, or MB with --si
150 -g|--gbytes::::
151 show sizes in GiB, or GB with --si
152 -t|--tbytes::::
153 show sizes in TiB, or TB with --si
154
155 If conflicting options are passed, the last one takes precedence.
156
157 TYPICAL USECASES
158 ----------------
159
160 STARTING WITH A SINGLE-DEVICE FILESYSTEM
161 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162
163 Assume we've created a filesystem on a block device '/dev/sda' with profile
164 'single/single' (data/metadata), the device size is 50GiB and we've used the
165 whole device for the filesystem. The mount point is '/mnt'.
166
167 The amount of data stored is 16GiB, metadata have allocated 2GiB.
168
169 ==== ADD NEW DEVICE ====
170
171 We want to increase the total size of the filesystem and keep the profiles. The
172 size of the new device '/dev/sdb' is 100GiB.
173
174  $ btrfs device add /dev/sdb /mnt
175
176 The amount of free data space increases by less than 100GiB, some space is
177 allocated for metadata.
178
179 ==== CONVERT TO RAID1 ====
180
181 Now we want to increase the redundancy level of both data and metadata, but
182 we'll do that in steps. Note, that the device sizes are not equal and we'll use
183 that to show the capabilities of split data/metadata and independent profiles.
184
185 The constraint for RAID1 gives us at most 50GiB of usable space and exactly 2
186 copies will be stored on the devices.
187
188 First we'll convert the metadata. As the metadata occupy less than 50GiB and
189 there's enough workspace for the conversion process, we can do:
190
191  $ btrfs balance start -mconvert=raid1 /mnt
192
193 This operation can take a while, because al  metadata have to be moved and all
194 block pointers updated. Depending on the physical locations of the old and new
195 blocks, the disk seeking is the key factor affecting performance.
196
197 You'll note that the system block group has been also converted to RAID1, this
198 normally happens as the system block group also holds metadata (the physical to
199 logical mappings).
200
201 What changed:
202
203 * available data space decreased by 3GiB, usable roughly (50 - 3) + (100 - 3) = 144 GiB
204 * metadata redundancy increased
205
206 IOW, the unequal device sizes allow for combined space for data yet improved
207 redundancy for metadata. If we decide to increase redundancy of data as well,
208 we're going to lose 50GiB of the second device for obvious reasons.
209
210  $ btrfs balance start -dconvert=raid1 /mnt
211
212 The balance process needs some workspace (ie. a free device space without any
213 data or metadata block groups) so the command could fail if there's too much
214 data or the block groups occupy the whole first device.
215
216 The device size of '/dev/sdb' as seen by the filesystem remains unchanged, but
217 the logical space from 50-100GiB will be unused.
218
219 ==== REMOVE DEVICE ====
220
221 Device removal must satisfy the profile constraints, otherwise the command
222 fails. For example:
223
224  $ btrfs device remove /dev/sda /mnt
225  ERROR: error removing device '/dev/sda': unable to go below two devices on raid1
226
227 In order to remove a device, you need to convert the profile in this case:
228
229  $ btrfs balance start -mconvert=dup -dconvert=single /mnt
230  $ btrfs device remove /dev/sda /mnt
231
232 DEVICE STATS
233 ------------
234
235 The device stats keep persistent record of several error classes related to
236 doing IO. The current values are printed at mount time and updated during
237 filesystem lifetime or from a scrub run.
238
239  $ btrfs device stats /dev/sda3
240  [/dev/sda3].write_io_errs   0
241  [/dev/sda3].read_io_errs    0
242  [/dev/sda3].flush_io_errs   0
243  [/dev/sda3].corruption_errs 0
244  [/dev/sda3].generation_errs 0
245
246 write_io_errs::
247 Failed writes to the block devices, means that the layers beneath the
248 filesystem were not able to satisfy the write request.
249 read_io_errors::
250 Read request analogy to write_io_errs.
251 flush_io_errs::
252 Number of failed writes with the 'FLUSH' flag set. The flushing is a method of
253 forcing a particular order between write requests and is crucial for
254 implementing crash consistency. In case of btrfs, all the metadata blocks must
255 be permanently stored on the block device before the superblock is written.
256 corruption_errs::
257 A block checksum mismatched or a corrupted metadata header was found.
258 generation_errs::
259 The block generation does not match the expected value (eg. stored in the
260 parent node).
261
262 EXIT STATUS
263 -----------
264 *btrfs device* returns a zero exit status if it succeeds. Non zero is
265 returned in case of failure.
266
267 If the '-s' option is used, *btrfs device stats* will add 64 to the
268 exit status if any of the error counters is non-zero.
269
270 AVAILABILITY
271 ------------
272 *btrfs* is part of btrfs-progs.
273 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
274 further details.
275
276 SEE ALSO
277 --------
278 `mkfs.btrfs`(8),
279 `btrfs-replace`(8),
280 `btrfs-balance`(8)