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

SUBCOMMAND

17       add [-Kf] <device> [<device>...] <path>
18              Add device(s) to the filesystem identified by path.
19
20              If applicable, a whole device discard (TRIM) operation  is  per‐
21              formed  prior  to  adding  the  device.  A  device with existing
22              filesystem detected by blkid(8) will prevent device addition and
23              has to be forced. Alternatively the filesystem can be wiped from
24              the device using e.g. the wipefs(8) tool.
25
26              The operation is instant and does not affect existing data.  The
27              operation  merely  adds  the device to the filesystem structures
28              and creates some block groups headers.
29
30              Options
31
32              -K|--nodiscard
33                     do not perform discard (TRIM) by default
34
35              -f|--force
36                     force overwrite  of  existing  filesystem  on  the  given
37                     disk(s)
38
39              --enqueue
40                     wait if there's another exclusive operation running, oth‐
41                     erwise continue
42
43       remove [options] <device>|<devid> [<device>|<devid>...] <path>
44              Remove device(s) from a filesystem identified by <path>
45
46              Device removal must satisfy the profile  constraints,  otherwise
47              the  command  fails.  The  filesystem  must be converted to pro‐
48              file(s) that would allow the removal. This can typically  happen
49              when going down from 2 devices to 1 and using the RAID1 profile.
50              See the section TYPICAL USECASES.
51
52              The operation can take long as it needs to move  all  data  from
53              the device.
54
55              It  is  possible to delete the device that was used to mount the
56              filesystem. The device entry in the mount table will be replaced
57              by another device name with the lowest device id.
58
59              If  the  filesystem  is  mounted in degraded mode (-o degraded),
60              special term missing can be used for device. In that  case,  the
61              first  device  that is described by the filesystem metadata, but
62              not present at the mount time will be removed.
63
64              NOTE:
65                 In most cases, there is only one missing device  in  degraded
66                 mode, otherwise mount fails. If there are two or more devices
67                 missing (e.g. possible in RAID6), you need specify missing as
68                 many  times as the number of missing devices to remove all of
69                 them.
70
71              Options
72
73              --enqueue
74                     wait if there's another exclusive operation running, oth‐
75                     erwise continue
76
77       delete <device>|<devid> [<device>|<devid>...] <path>
78              Alias of remove kept for backward compatibility
79
80       replace <command> [options] <path>
81              Alias  of whole command group btrfs replace for convenience. See
82              btrfs-replace(8).
83
84       ready <device>
85              Wait until all  devices  of  a  multiple-device  filesystem  are
86              scanned and registered within the kernel module. This is to pro‐
87              vide a way for automatic filesystem mounting tools to  wait  be‐
88              fore  the  mount  can  start. The device scan is only one of the
89              preconditions and the mount can fail for other reasons.   Normal
90              users usually do not need this command and may safely ignore it.
91
92       scan [options] [<device> [<device>...]]
93              Scan  devices  for a btrfs filesystem and register them with the
94              kernel module.  This allows mounting multiple-device  filesystem
95              by specifying just one from the whole group.
96
97              If  no  devices are passed, all block devices that blkid reports
98              to contain btrfs are scanned.
99
100              The options --all-devices or -d can be used  as  a  fallback  in
101              case  blkid  is not available.  If used, behavior is the same as
102              if no devices are passed.
103
104              The command can be run repeatedly. Devices that  have  been  al‐
105              ready  registered  remain  as  such. Reloading the kernel module
106              will drop this information. There's an alternative way of mount‐
107              ing  multiple-device filesystem without the need for prior scan‐
108              ning. See the mount option device.
109
110              Options
111
112              -d|--all-devices
113                     Enumerate and register all devices, use as a fallback  in
114                     case blkid is not available.
115
116              -u|--forget
117                     Unregister a given device or all stale devices if no path
118                     is given, the device must be unmounted otherwise it's  an
119                     error.
120
121       stats [options] <path>|<device>
122              Read and print the device IO error statistics for all devices of
123              the given filesystem identified by path or for a single device>.
124              The  filesystem  must be mounted.  See section *DEVICE STATS for
125              more information about the reported statistics and the meaning.
126
127              Options
128
129              -z|--reset
130                     Print the stats and reset the values to zero afterwards.
131
132              -c|--check
133                     Check if the stats are all zeros and return 0  if  it  is
134                     so. Set bit 6 of the return code if any of the statistics
135                     is no-zero. The error values is 65 if reading stats  from
136                     at least one device failed, otherwise it's 64.
137
138              -T     Print  stats in a tabular form, devices as rows and stats
139                     as columns
140
141       usage [options] <path> [<path>...]::
142              Show detailed information about internal allocations on devices.
143
144              The level of detail can differ if the command  is  run  under  a
145              regular  or the root user (due to use of restricted ioctls). The
146              first example below is for normal user  (warning  included)  and
147              the next one with root on the same filesystem:
148
149                 WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
150                 /dev/sdc1, ID: 1
151                    Device size:           931.51GiB
152                    Device slack:              0.00B
153                    Unallocated:           931.51GiB
154
155                 /dev/sdc1, ID: 1
156                    Device size:           931.51GiB
157                    Device slack:              0.00B
158                    Data,single:           641.00GiB
159                    Data,RAID0/3:            1.00GiB
160                    Metadata,single:        19.00GiB
161                    System,single:          32.00MiB
162                    Unallocated:           271.48GiB
163
164Device  size  --  size of the device as seen by the filesystem
165                (may be different than actual device size)
166
167Device slack -- portion of device not used by  the  filesystem
168                but  still available in the physical space provided by the de‐
169                vice, e.g.  after a device shrink
170
171Data,single, Metadata,single,  System,single  --  in  general,
172                list  of block group type (Data, Metadata, System) and profile
173                (single, RAID1, ...) allocated on the device
174
175Data,RAID0/3    --    in    particular,    striped    profiles
176                RAID0/RAID10/RAID5/RAID6  with  the number of devices on which
177                the stripes are allocated, multiple occurrences  of  the  same
178                profile can appear in case a new device has been added and all
179                new available stripes have been used for writes
180
181Unallocated -- remaining space that the filesystem  can  still
182                use for new block groups
183
184              Options
185
186              -b|--raw
187                     raw numbers in bytes, without the B suffix
188
189              -h|--human-readable
190                     print  human friendly numbers, base 1024, this is the de‐
191                     fault
192
193              -H     print human friendly numbers, base 1000
194
195              --iec  select the 1024 base for the following options, according
196                     to the IEC standard
197
198              --si   select the 1000 base for the following options, according
199                     to the SI standard
200
201              -k|--kbytes
202                     show sizes in KiB, or kB with --si
203
204              -m|--mbytes
205                     show sizes in MiB, or MB with --si
206
207              -g|--gbytes
208                     show sizes in GiB, or GB with --si
209
210              -t|--tbytes
211                     show sizes in TiB, or TB with --si
212
213              If conflicting options are passed, the  last  one  takes  prece‐
214              dence.
215

DEVICE STATS

217       The  device  stats  keep persistent record of several error classes re‐
218       lated to doing IO. The current values are printed at mount time and up‐
219       dated during filesystem lifetime or from a scrub run.
220
221          $ btrfs device stats /dev/sda3
222          [/dev/sda3].write_io_errs   0
223          [/dev/sda3].read_io_errs    0
224          [/dev/sda3].flush_io_errs   0
225          [/dev/sda3].corruption_errs 0
226          [/dev/sda3].generation_errs 0
227
228       write_io_errs
229              Failed  writes  to  the block devices, means that the layers be‐
230              neath the filesystem were not able to satisfy the write request.
231
232       read_io_errors
233              Read request analogy to write_io_errs.
234
235       flush_io_errs
236              Number of failed writes with the FLUSH flag set. The flushing is
237              a  method  of  forcing a particular order between write requests
238              and is crucial for implementing crash consistency.  In  case  of
239              btrfs, all the metadata blocks must be permanently stored on the
240              block device before the superblock is written.
241
242       corruption_errs
243              A block checksum mismatched or a corrupted metadata  header  was
244              found.
245
246       generation_errs
247              The  block  generation  does  not match the expected value (e.g.
248              stored in the parent node).
249
250       Since kernel 5.14 the device stats are also available in  textual  form
251       in /sys/fs/btrfs/FSID/devinfo/DEVID/error_stats.
252

EXIT STATUS

254       btrfs device returns a zero exit status if it succeeds. Non zero is re‐
255       turned in case of failure.
256
257       If the -c option is used, btrfs device stats will add 64  to  the  exit
258       status if any of the error counters is non-zero.
259

AVAILABILITY

261       btrfs  is  part  of  btrfs-progs.  Please refer to the documentation at
262       https://btrfs.readthedocs.io or wiki  http://btrfs.wiki.kernel.org  for
263       further information.
264

SEE ALSO

266       btrfs-balance(8) btrfs-device(8), btrfs-replace(8), mkfs.btrfs(8),
267
268
269
270
2716.1.3                            Jan 25, 2023                  BTRFS-DEVICE(8)
Impressum