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