1BTRFS-DEVICE(8)                      BTRFS                     BTRFS-DEVICE(8)
2
3
4

NAME

6       btrfs-device - manage devices of btrfs filesystems
7

SYNOPSIS

9       btrfs device <subcommand> <args>
10

DESCRIPTION

12       The  btrfs  device command group is used to manage devices of the btrfs
13       filesystems.
14

DEVICE MANAGEMENT

16       BTRFS filesystem can be created on top of single or multiple block  de‐
17       vices.  Devices can be then added, removed or replaced on demand.  Data
18       and metadata are organized in allocation profiles with  various  redun‐
19       dancy  policies.  There's some similarity with traditional RAID levels,
20       but this could be confusing to  users  familiar  with  the  traditional
21       meaning.  Due to the similarity, the RAID terminology is widely used in
22       the documentation.  See mkfs.btrfs(8) for more details  and  the  exact
23       profile capabilities and constraints.
24
25       The  device  management  works  on a mounted filesystem. Devices can be
26       added, removed or replaced, by commands provided by  btrfs  device  and
27       btrfs replace.
28
29       The  profiles can be also changed, provided there's enough workspace to
30       do the conversion, using the btrfs balance command and namely the  fil‐
31       ter convert.
32
33       Type   The  block group profile type is the main distinction of the in‐
34              formation stored on the block device. User data are called Data,
35              the  internal data structures managed by filesystem are Metadata
36              and System.
37
38       Profile
39              A profile describes an allocation policy  based  on  the  redun‐
40              dancy/replication  constraints  in connection with the number of
41              devices. The profile applies to data and metadata  block  groups
42              separately. E.g. single, RAID1.
43
44       RAID level
45              Where  applicable,  the  level  refers to a profile that matches
46              constraints of the standard RAID levels. At the moment the  sup‐
47              ported ones are: RAID0, RAID1, RAID10, RAID5 and RAID6.
48

TYPICAL USE CASES

50   Starting with a single-device filesystem
51       Assume  we've created a filesystem on a block device /dev/sda with pro‐
52       file single/single (data/metadata), the device size is 50GiB and  we've
53       used the whole device for the filesystem. The mount point is /mnt.
54
55       The amount of data stored is 16GiB, metadata have allocated 2GiB.
56
57   Add new device
58       We  want to increase the total size of the filesystem and keep the pro‐
59       files. The size of the new device /dev/sdb is 100GiB.
60
61          $ btrfs device add /dev/sdb /mnt
62
63       The amount of free data space increases by less than 100GiB, some space
64       is allocated for metadata.
65
66   Convert to RAID1
67       Now we want to increase the redundancy level of both data and metadata,
68       but we'll do that in steps. Note, that the device sizes are  not  equal
69       and  we'll use that to show the capabilities of split data/metadata and
70       independent profiles.
71
72       The constraint for RAID1 gives us at most 50GiB of usable space and ex‐
73       actly 2 copies will be stored on the devices.
74
75       First  we'll  convert  the  metadata.  As the metadata occupy less than
76       50GiB and there's enough workspace for the conversion process,  we  can
77       do:
78
79          $ btrfs balance start -mconvert=raid1 /mnt
80
81       This  operation can take a while, because all metadata have to be moved
82       and all block pointers updated. Depending on the physical locations  of
83       the  old  and  new blocks, the disk seeking is the key factor affecting
84       performance.
85
86       You'll note that the system block group  has  been  also  converted  to
87       RAID1, this normally happens as the system block group also holds meta‐
88       data (the physical to logical mappings).
89
90       What changed:
91
92       • available data space decreased by 3GiB, usable roughly  (50  -  3)  +
93         (100 - 3) = 144 GiB
94
95       • metadata redundancy increased
96
97       IOW, the unequal device sizes allow for combined space for data yet im‐
98       proved redundancy for metadata. If we decide to increase redundancy  of
99       data  as well, we're going to lose 50GiB of the second device for obvi‐
100       ous reasons.
101
102          $ btrfs balance start -dconvert=raid1 /mnt
103
104       The balance process needs some workspace  (i.e.  a  free  device  space
105       without any data or metadata block groups) so the command could fail if
106       there's too much data or the block groups occupy the  whole  first  de‐
107       vice.
108
109       The  device  size  of  /dev/sdb  as  seen by the filesystem remains un‐
110       changed, but the logical space from 50-100GiB will be unused.
111
112   Remove device
113       Device removal must satisfy the profile constraints, otherwise the com‐
114       mand fails. For example:
115
116          $ btrfs device remove /dev/sda /mnt
117          ERROR: error removing device '/dev/sda': unable to go below two devices on raid1
118
119       In  order  to  remove a device, you need to convert the profile in this
120       case:
121
122          $ btrfs balance start -mconvert=dup -dconvert=single /mnt
123          $ btrfs device remove /dev/sda /mnt
124

SUBCOMMAND

126       add [-Kf] <device> [<device>...] <path>
127              Add device(s) to the filesystem identified by path.
128
129              If applicable, a whole device discard (TRIM) operation  is  per‐
130              formed  prior  to  adding  the  device.  A  device with existing
131              filesystem detected by blkid(8) will prevent device addition and
132              has to be forced. Alternatively the filesystem can be wiped from
133              the device using e.g. the wipefs(8) tool.
134
135              The operation is instant and does not affect existing data.  The
136              operation  merely  adds  the device to the filesystem structures
137              and creates some block groups headers.
138
139              Options
140
141              -K|--nodiscard
142                     do not perform discard (TRIM) by default
143
144              -f|--force
145                     force overwrite  of  existing  filesystem  on  the  given
146                     disk(s)
147
148              --enqueue
149                     wait if there's another exclusive operation running, oth‐
150                     erwise continue
151
152       remove [options] <device>|<devid> [<device>|<devid>...] <path>
153              Remove device(s) from a filesystem identified by <path>
154
155              Device removal must satisfy the profile  constraints,  otherwise
156              the  command  fails.  The  filesystem  must be converted to pro‐
157              file(s) that would allow the removal. This can typically  happen
158              when going down from 2 devices to 1 and using the RAID1 profile.
159              See the section Typical use cases.
160
161              The operation can take long as it needs to move  all  data  from
162              the device.
163
164              It  is  possible to delete the device that was used to mount the
165              filesystem. The device entry in the mount table will be replaced
166              by another device name with the lowest device id.
167
168              If  the  filesystem  is  mounted in degraded mode (-o degraded),
169              special term missing can be used for device. In that  case,  the
170              first  device  that is described by the filesystem metadata, but
171              not present at the mount time will be removed.
172
173              NOTE:
174                 In most cases, there is only one missing device  in  degraded
175                 mode, otherwise mount fails. If there are two or more devices
176                 missing (e.g. possible in RAID6), you need specify missing as
177                 many  times as the number of missing devices to remove all of
178                 them.
179
180              Options
181
182              --enqueue
183                     wait if there's another exclusive operation running, oth‐
184                     erwise continue
185
186       delete <device>|<devid> [<device>|<devid>...] <path>
187              Alias of remove kept for backward compatibility
188
189       replace <command> [options] <path>
190              Alias  of whole command group btrfs replace for convenience. See
191              btrfs-replace(8).
192
193       ready <device>
194              Wait until all  devices  of  a  multiple-device  filesystem  are
195              scanned and registered within the kernel module. This is to pro‐
196              vide a way for automatic filesystem mounting tools to  wait  be‐
197              fore  the  mount  can  start. The device scan is only one of the
198              preconditions and the mount can fail for other reasons.   Normal
199              users usually do not need this command and may safely ignore it.
200
201       scan [options] [<device> [<device>...]]
202              Scan  devices  for a btrfs filesystem and register them with the
203              kernel module.  This allows mounting multiple-device  filesystem
204              by specifying just one from the whole group.
205
206              If  no  devices are passed, all block devices that blkid reports
207              to contain btrfs are scanned.
208
209              The options --all-devices or -d can be used  as  a  fallback  in
210              case  blkid  is not available.  If used, behavior is the same as
211              if no devices are passed.
212
213              The command can be run repeatedly. Devices that  have  been  al‐
214              ready  registered  remain  as  such. Reloading the kernel module
215              will drop this information. There's an alternative way of mount‐
216              ing  multiple-device filesystem without the need for prior scan‐
217              ning. See the mount option device.
218
219              Options
220
221              -d|--all-devices
222                     Enumerate and register all devices, use as a fallback  in
223                     case blkid is not available.
224
225              -u|--forget
226                     Unregister a given device or all stale devices if no path
227                     is given, the device must be unmounted otherwise it's  an
228                     error.
229
230       stats [options] <path>|<device>
231              Read and print the device IO error statistics for all devices of
232              the given filesystem identified by path or for a single  device.
233              The  filesystem  must  be mounted.  See section DEVICE STATS for
234              more information about the reported statistics and the meaning.
235
236              Options
237
238              -z|--reset
239                     Print the stats and reset the values to zero afterwards.
240
241              -c|--check
242                     Check if the stats are all zeros and return 0  if  it  is
243                     so. Set bit 6 of the return code if any of the statistics
244                     is no-zero. The error values is 65 if reading stats  from
245                     at least one device failed, otherwise it's 64.
246
247              -T     Print  stats in a tabular form, devices as rows and stats
248                     as columns
249
250       usage [options] <path> [<path>...]::
251              Show detailed information about internal allocations on devices.
252
253              The level of detail can differ if the command  is  run  under  a
254              regular  or the root user (due to use of restricted ioctls). The
255              first example below is for normal user  (warning  included)  and
256              the next one with root on the same filesystem:
257
258                 WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
259                 /dev/sdc1, ID: 1
260                    Device size:           931.51GiB
261                    Device slack:              0.00B
262                    Unallocated:           931.51GiB
263
264                 /dev/sdc1, ID: 1
265                    Device size:           931.51GiB
266                    Device slack:              0.00B
267                    Data,single:           641.00GiB
268                    Data,RAID0/3:            1.00GiB
269                    Metadata,single:        19.00GiB
270                    System,single:          32.00MiB
271                    Unallocated:           271.48GiB
272
273Device  size  --  size of the device as seen by the filesystem
274                (may be different than actual device size)
275
276Device slack -- portion of device not used by  the  filesystem
277                but  still available in the physical space provided by the de‐
278                vice, e.g.  after a device shrink
279
280Data,single, Metadata,single,  System,single  --  in  general,
281                list  of block group type (Data, Metadata, System) and profile
282                (single, RAID1, ...) allocated on the device
283
284Data,RAID0/3    --    in    particular,    striped    profiles
285                RAID0/RAID10/RAID5/RAID6  with  the number of devices on which
286                the stripes are allocated, multiple occurrences  of  the  same
287                profile can appear in case a new device has been added and all
288                new available stripes have been used for writes
289
290Unallocated -- remaining space that the filesystem  can  still
291                use for new block groups
292
293              Options
294
295              -b|--raw
296                     raw numbers in bytes, without the B suffix
297
298              -h|--human-readable
299                     print  human friendly numbers, base 1024, this is the de‐
300                     fault
301
302              -H     print human friendly numbers, base 1000
303
304              --iec  select the 1024 base for the following options, according
305                     to the IEC standard
306
307              --si   select the 1000 base for the following options, according
308                     to the SI standard
309
310              -k|--kbytes
311                     show sizes in KiB, or kB with --si
312
313              -m|--mbytes
314                     show sizes in MiB, or MB with --si
315
316              -g|--gbytes
317                     show sizes in GiB, or GB with --si
318
319              -t|--tbytes
320                     show sizes in TiB, or TB with --si
321
322              If conflicting options are passed, the  last  one  takes  prece‐
323              dence.
324

DEVICE STATS

326       The  device  stats  keep persistent record of several error classes re‐
327       lated to doing IO. The current values are printed at mount time and up‐
328       dated during filesystem lifetime or from a scrub run.
329
330          $ btrfs device stats /dev/sda3
331          [/dev/sda3].write_io_errs   0
332          [/dev/sda3].read_io_errs    0
333          [/dev/sda3].flush_io_errs   0
334          [/dev/sda3].corruption_errs 0
335          [/dev/sda3].generation_errs 0
336
337       write_io_errs
338              Failed  writes  to  the block devices, means that the layers be‐
339              neath the filesystem were not able to satisfy the write request.
340
341       read_io_errors
342              Read request analogy to write_io_errs.
343
344       flush_io_errs
345              Number of failed writes with the FLUSH flag set. The flushing is
346              a  method  of  forcing a particular order between write requests
347              and is crucial for implementing crash consistency.  In  case  of
348              btrfs, all the metadata blocks must be permanently stored on the
349              block device before the superblock is written.
350
351       corruption_errs
352              A block checksum mismatched or a corrupted metadata  header  was
353              found.
354
355       generation_errs
356              The  block  generation  does  not match the expected value (e.g.
357              stored in the parent node).
358
359       Since kernel 5.14 the device stats are also available in  textual  form
360       in /sys/fs/btrfs/FSID/devinfo/DEVID/error_stats.
361

EXIT STATUS

363       btrfs device returns a zero exit status if it succeeds. Non zero is re‐
364       turned in case of failure.
365
366       If the -c option is used, btrfs device stats will add 64  to  the  exit
367       status if any of the error counters is non-zero.
368

AVAILABILITY

370       btrfs  is  part  of  btrfs-progs.  Please refer to the documentation at
371       https://btrfs.readthedocs.io.
372

SEE ALSO

374       btrfs-balance(8) btrfs-device(8), btrfs-replace(8), mkfs.btrfs(8)
375
376
377
378
3796.6.2                            Nov 24, 2023                  BTRFS-DEVICE(8)
Impressum