summaryrefslogtreecommitdiffstats
path: root/upstream/fedora-rawhide/man8/btrfs-device.8
blob: 795dc42b9234b5f2aa42cb14198f53cd956664ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
.\" Man page generated from reStructuredText.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "BTRFS-DEVICE" "8" "Mar 26, 2024" "6.8.1" "BTRFS"
.SH NAME
btrfs-device \- manage devices of btrfs filesystems
.SH SYNOPSIS
.sp
\fBbtrfs device\fP <subcommand> <args>
.SH DESCRIPTION
.sp
The \fBbtrfs device\fP command group is used to manage devices of the btrfs filesystems.
.SH DEVICE MANAGEMENT
.sp
BTRFS filesystem can be created on top of single or multiple block devices.
Devices can be then added, removed or replaced on demand.  Data and metadata are
organized in allocation profiles with various redundancy policies.  There\(aqs some
similarity with traditional RAID levels, but this could be confusing to users
familiar with the traditional meaning. Due to the similarity, the RAID
terminology is widely used in the documentation.  See \fI\%mkfs.btrfs(8)\fP for more
details and the exact profile capabilities and constraints.
.sp
The device management works on a mounted filesystem. Devices can be added,
removed or replaced, by commands provided by \fBbtrfs device\fP and \fBbtrfs replace\fP\&.
.sp
The profiles can be also changed, provided there\(aqs enough workspace to do the
conversion, using the \fBbtrfs balance\fP command and namely the filter \fIconvert\fP\&.
.INDENT 0.0
.TP
.B Type
The block group profile type is the main distinction of the information stored
on the block device. User data are called \fIData\fP, the internal data structures
managed by filesystem are \fIMetadata\fP and \fISystem\fP\&.
.TP
.B Profile
A profile describes an allocation policy based on the redundancy/replication
constraints in connection with the number of devices. The profile applies to
data and metadata block groups separately. E.g. \fIsingle\fP, \fIRAID1\fP\&.
.TP
.B RAID level
Where applicable, the level refers to a profile that matches constraints of the
standard RAID levels. At the moment the supported ones are: RAID0, RAID1,
RAID10, RAID5 and RAID6.
.UNINDENT
.SH TYPICAL USE CASES
.SS Starting with a single\-device filesystem
.sp
Assume we\(aqve created a filesystem on a block device \fB/dev/sda\fP with profile
\fIsingle/single\fP (data/metadata), the device size is 50GiB and we\(aqve used the
whole device for the filesystem. The mount point is \fB/mnt\fP\&.
.sp
The amount of data stored is 16GiB, metadata have allocated 2GiB.
.SS Add new device
.sp
We want to increase the total size of the filesystem and keep the profiles. The
size of the new device \fB/dev/sdb\fP is 100GiB.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ btrfs device add /dev/sdb /mnt
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The amount of free data space increases by less than 100GiB, some space is
allocated for metadata.
.SS Convert to RAID1
.sp
Now we want to increase the redundancy level of both data and metadata, but
we\(aqll do that in steps. Note, that the device sizes are not equal and we\(aqll use
that to show the capabilities of split data/metadata and independent profiles.
.sp
The constraint for RAID1 gives us at most 50GiB of usable space and exactly 2
copies will be stored on the devices.
.sp
First we\(aqll convert the metadata. As the metadata occupy less than 50GiB and
there\(aqs enough workspace for the conversion process, we can do:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ btrfs balance start \-mconvert=raid1 /mnt
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
This operation can take a while, because all metadata have to be moved and all
block pointers updated. Depending on the physical locations of the old and new
blocks, the disk seeking is the key factor affecting performance.
.sp
You\(aqll note that the system block group has been also converted to RAID1, this
normally happens as the system block group also holds metadata (the physical to
logical mappings).
.sp
What changed:
.INDENT 0.0
.IP \(bu 2
available data space decreased by 3GiB, usable roughly (50 \- 3) + (100 \- 3) = 144 GiB
.IP \(bu 2
metadata redundancy increased
.UNINDENT
.sp
IOW, the unequal device sizes allow for combined space for data yet improved
redundancy for metadata. If we decide to increase redundancy of data as well,
we\(aqre going to lose 50GiB of the second device for obvious reasons.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ btrfs balance start \-dconvert=raid1 /mnt
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The balance process needs some workspace (i.e. a free device space without any
data or metadata block groups) so the command could fail if there\(aqs too much
data or the block groups occupy the whole first device.
.sp
The device size of \fB/dev/sdb\fP as seen by the filesystem remains unchanged, but
the logical space from 50\-100GiB will be unused.
.SS Remove device
.sp
Device removal must satisfy the profile constraints, otherwise the command
fails. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ btrfs device remove /dev/sda /mnt
ERROR: error removing device \(aq/dev/sda\(aq: unable to go below two devices on raid1
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
In order to remove a device, you need to convert the profile in this case:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ btrfs balance start \-mconvert=dup \-dconvert=single /mnt
$ btrfs device remove /dev/sda /mnt
.ft P
.fi
.UNINDENT
.UNINDENT
.SH SUBCOMMAND
.INDENT 0.0
.TP
.B add [\-Kf] <device> [<device>...] <path>
Add device(s) to the filesystem identified by \fIpath\fP\&.
.sp
If applicable, a whole device discard (TRIM) operation is performed prior to
adding the device. A device with existing filesystem detected by \fI\%blkid(8)\fP
will prevent device addition and has to be forced. Alternatively the filesystem
can be wiped from the device using e.g. the \fI\%wipefs(8)\fP tool.
.sp
The operation is instant and does not affect existing data. The operation merely
adds the device to the filesystem structures and creates some block groups
headers.
.sp
\fBOptions\fP
.INDENT 7.0
.TP
.B \-K|\-\-nodiscard
do not perform discard (TRIM) by default
.TP
.B \-f|\-\-force
force overwrite of existing filesystem on the given disk(s)
.UNINDENT
.INDENT 7.0
.TP
.B  \-\-enqueue
wait if there\(aqs another exclusive operation running, otherwise continue
.UNINDENT
.TP
.B remove [options] <device>|<devid> [<device>|<devid>...] <path>
Remove device(s) from a filesystem identified by <path>
.sp
Device removal must satisfy the profile constraints, otherwise the command
fails and cannot be enforced. The filesystem must be converted to
profile(s) that would allow the removal. This can for example happen when
going down from 2 devices to 1 and using the RAID1 profile. See the
section \fI\%Typical use cases\fP\&.
.sp
The operation can take long as it needs to move all data from the device.
.sp
\fBNOTE:\fP
.INDENT 7.0
.INDENT 3.5
It\(aqs possible to specify more than one device on the command
line but the devices will be removed one by one, not at once.
This means that the remaining devices to be deleted can be
still used for writes. In that case there\(aqs a warning and safety
timeout as this can be confusing and unexpected. The timeout can
be overridden by option \fI\-\-force\fP\&.
.UNINDENT
.UNINDENT
.sp
It is possible to delete the device that was used to mount the filesystem. The
device entry in the mount table (\fB/proc/self/mounts\fP) will be
replaced by another device name with the lowest device id.
.sp
If the filesystem is mounted in degraded mode (\fI\-o degraded\fP), special term
\fImissing\fP can be used for \fIdevice\fP\&. In that case, the first device that is
described by the filesystem metadata, but not present at the mount time will be
removed.
.sp
\fBNOTE:\fP
.INDENT 7.0
.INDENT 3.5
In most cases, there is only one missing device in degraded mode,
otherwise mount fails. If there are two or more devices missing (e.g. possible
in RAID6), you need specify \fImissing\fP as many times as the number of missing
devices to remove all of them.
.UNINDENT
.UNINDENT
.sp
\fBOptions\fP
.INDENT 7.0
.TP
.B  \-\-enqueue
wait if there\(aqs another exclusive operation running, otherwise continue
.TP
.B  \-\-force
skip the safety timeout when there are multiple devices for removal, this
does not force removing devices that would break the profile constraints
.UNINDENT
.TP
.B delete <device>|<devid> [<device>|<devid>...] <path>
Alias of remove kept for backward compatibility
.TP
.B replace <command> [options] <path>
Alias of whole command group \fIbtrfs replace\fP for convenience. See
\fI\%btrfs\-replace(8)\fP\&.
.TP
.B ready <device>
Wait until all devices of a multiple\-device filesystem are scanned and
registered within the kernel module. This is to provide a way for automatic
filesystem mounting tools to wait before the mount can start. The device scan
is only one of the preconditions and the mount can fail for other reasons.
Normal users usually do not need this command and may safely ignore it.
.TP
.B scan [options] [<device> [<device>...]]
Scan devices for a btrfs filesystem and register them with the kernel module.
This allows mounting multiple\-device filesystem by specifying just one from the
whole group.
.sp
If no devices are passed, all block devices that blkid reports to contain btrfs
are scanned.
.sp
The options \fI\-\-all\-devices\fP or \fI\-d\fP can be used as a fallback in case blkid is
not available.  If used, behavior is the same as if no devices are passed.
.sp
The command can be run repeatedly. Devices that have been already registered
remain as such. Reloading the kernel module will drop this information. There\(aqs
an alternative way of mounting multiple\-device filesystem without the need for
prior scanning. See the mount option
\fI\%device (in btrfs\-man5)\fP\&.
.sp
\fBOptions\fP
.INDENT 7.0
.TP
.B \-d|\-\-all\-devices
Enumerate and register all devices, use as a fallback in case blkid is not
available.
.TP
.B \-u|\-\-forget
Unregister a given device or all stale devices if no path is given, the device
must be unmounted otherwise it\(aqs an error.
.UNINDENT
.TP
.B stats [options] <path>|<device>
Read and print the device IO error statistics for all devices of the given
filesystem identified by \fIpath\fP or for a single \fIdevice\fP\&. The filesystem must
be mounted.  See section \fI\%DEVICE STATS\fP
for more information about the reported statistics and the meaning.
.sp
\fBOptions\fP
.INDENT 7.0
.TP
.B \-z|\-\-reset
Print the stats and reset the values to zero afterwards.
.TP
.B \-c|\-\-check
Check if the stats are all zeros and return 0 if it is so. Set bit 6 of the
return code if any of the statistics is no\-zero. The error values is 65 if
reading stats from at least one device failed, otherwise it\(aqs 64.
.UNINDENT
.INDENT 7.0
.TP
.B  \-T
Print stats in a tabular form, devices as rows and stats as columns
.UNINDENT
.TP
.B usage [options] <path> [<path>...]::
Show detailed information about internal allocations on devices.
.sp
The level of detail can differ if the command is run under a regular or the
root user (due to use of restricted ioctls). The first example below is for
normal user (warning included) and the next one with root on the same
filesystem:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
WARNING: cannot read detailed chunk info, per\-device usage will not be shown, run as root
/dev/sdc1, ID: 1
   Device size:           931.51GiB
   Device slack:              0.00B
   Unallocated:           931.51GiB

/dev/sdc1, ID: 1
   Device size:           931.51GiB
   Device slack:              0.00B
   Data,single:           641.00GiB
   Data,RAID0/3:            1.00GiB
   Metadata,single:        19.00GiB
   System,single:          32.00MiB
   Unallocated:           271.48GiB
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 7.0
.IP \(bu 2
\fIDevice size\fP \-\- size of the device as seen by the filesystem (may be
different than actual device size)
.IP \(bu 2
\fIDevice slack\fP \-\- portion of device not used by the filesystem but
still available in the physical space provided by the device, e.g.
after a device shrink
.IP \(bu 2
\fIData,single\fP, \fIMetadata,single\fP, \fISystem,single\fP \-\- in general, list
of block group type (Data, Metadata, System) and profile (single,
RAID1, ...) allocated on the device
.IP \(bu 2
\fIData,RAID0/3\fP \-\- in particular, striped profiles
RAID0/RAID10/RAID5/RAID6 with the number of devices on which the
stripes are allocated, multiple occurrences of the same profile can
appear in case a new device has been added and all new available
stripes have been used for writes
.IP \(bu 2
\fIUnallocated\fP \-\- remaining space that the filesystem can still use
for new block groups
.UNINDENT
.sp
\fBOptions\fP
.INDENT 7.0
.TP
.B \-b|\-\-raw
raw numbers in bytes, without the \fIB\fP suffix
.TP
.B \-h|\-\-human\-readable
print human friendly numbers, base 1024, this is the default
.UNINDENT
.INDENT 7.0
.TP
.B  \-H
print human friendly numbers, base 1000
.TP
.B  \-\-iec
select the 1024 base for the following options, according to the IEC standard
.TP
.B  \-\-si
select the 1000 base for the following options, according to the SI standard
.UNINDENT
.INDENT 7.0
.TP
.B \-k|\-\-kbytes
show sizes in KiB, or kB with \-\-si
.TP
.B \-m|\-\-mbytes
show sizes in MiB, or MB with \-\-si
.TP
.B \-g|\-\-gbytes
show sizes in GiB, or GB with \-\-si
.TP
.B \-t|\-\-tbytes
show sizes in TiB, or TB with \-\-si
.UNINDENT
.sp
If conflicting options are passed, the last one takes precedence.
.UNINDENT
.SH DEVICE STATS
.sp
The device stats keep persistent record of several error classes related to
doing IO. The current values are printed at mount time and updated during
filesystem lifetime or from a scrub run.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ btrfs device stats /dev/sda3
[/dev/sda3].write_io_errs   0
[/dev/sda3].read_io_errs    0
[/dev/sda3].flush_io_errs   0
[/dev/sda3].corruption_errs 0
[/dev/sda3].generation_errs 0
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B write_io_errs
Failed writes to the block devices, means that the layers beneath the
filesystem were not able to satisfy the write request.
.TP
.B read_io_errors
Read request analogy to write_io_errs.
.TP
.B flush_io_errs
Number of failed writes with the \fIFLUSH\fP flag set. The flushing is a method of
forcing a particular order between write requests and is crucial for
implementing crash consistency. In case of btrfs, all the metadata blocks must
be permanently stored on the block device before the superblock is written.
.TP
.B corruption_errs
A block checksum mismatched or a corrupted metadata header was found.
.TP
.B generation_errs
The block generation does not match the expected value (e.g. stored in the
parent node).
.UNINDENT
.sp
Since kernel 5.14 the device stats are also available in textual form in
\fB/sys/fs/btrfs/FSID/devinfo/DEVID/error_stats\fP\&.
.SH EXIT STATUS
.sp
\fBbtrfs device\fP returns a zero exit status if it succeeds. Non zero is
returned in case of failure.
.sp
If the \fI\-c\fP option is used, \fIbtrfs device stats\fP will add 64 to the
exit status if any of the error counters is non\-zero.
.SH AVAILABILITY
.sp
\fBbtrfs\fP is part of btrfs\-progs.  Please refer to the documentation at
\fI\%https://btrfs.readthedocs.io\fP\&.
.SH SEE ALSO
.sp
\fI\%btrfs\-balance(8)\fP
\fI\%btrfs\-device(8)\fP,
\fI\%btrfs\-replace(8)\fP,
\fI\%mkfs.btrfs(8)\fP
.\" Generated by docutils manpage writer.
.