BTRFS-DEVICE(8)
๐ btrfs-device โ manage devices of btrfs filesystems ๐
okay bestie, welcome to btrfs-device(8), the manual page that's literally all about wrangling the actual physical block devices that your btrfs filesystem lives on. no cap. let's get into it. โจ
โจ SYNOPSIS โจ
btrfs device <subcommand> <args>
๐ธ DESCRIPTION ๐ธ
The btrfs device command group is the whole vibe for managing devices of the btrfs filesystems. that's it, that's the intro. iconic. ๐
๐ DEVICE MANAGEMENT ๐
so here's the tea: a BTRFS filesystem can be created on top of single or multiple block devices. and then, whenever you feel like it, Devices can be added, removed or replaced on demand. main character energy fr.
Data and metadata are organized in allocation profiles with various redundancy policies. there's some similarity with traditional RAID levels, but ngl this could be confusing to users who are familiar with the traditional meaning. because of the similarity, the RAID terminology is widely used in the documentation. See mkfs.btrfs(8) for more details and the exact profile capabilities and constraints. ty bestie.
The device management works on a mounted filesystem. Devices can be added, removed or replaced, by commands provided by btrfs device and btrfs replace. yes queen, mounted, don't forget.
The profiles can also be changed, provided there's enough workspace to do the conversion, using the btrfs balance command and namely the filter convert.
- Type โ The block group profile type is the main distinction of the information stored on the block device. User data are called
Data, the internal data structures managed by filesystem areMetadataandSystem. - 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.
single,RAID1. - 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,RAID5andRAID6.
๐ฆ TYPICAL USE CASES ๐ฆ
๐ Starting with a single-device filesystem
Assume we've created a filesystem on a block device /dev/sda with profile single/single (data/metadata), the device size is 50GiB and we've used the whole device for the filesystem. The mount point is /mnt.
The amount of data stored is 16GiB, metadata have allocated 2GiB.
๐ Add new device
We want to increase the total size of the filesystem and keep the profiles. The size of the new device /dev/sdb is 100GiB.
$ btrfs device add /dev/sdb /mnt
The amount of free data space increases by less than 100GiB, some space is allocated for metadata. sneaky but necessary, yk?
๐ Convert to RAID1
Now we want to increase the redundancy level of both data and metadata, but we'll do that in steps. Note, that the device sizes are not equal and we'll use that to show the capabilities of split data/metadata and independent profiles. slay, multi-tasking.
The constraint for RAID1 gives us at most 50GiB of usable space and exactly 2 copies will be stored on the devices.
First we'll convert the metadata. As the metadata occupy less than 50GiB and there's enough workspace for the conversion process, we can do:
$ btrfs balance start -mconvert=raid1 /mnt
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. patience, babe. ๐ง
You'll 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).
What changed:
- available data space decreased by
3GiB, usable roughly(50 - 3) + (100 - 3) = 144 GiB - metadata redundancy increased
In other words, 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're going to lose 50GiB of the second device for obvious reasons. math is mathing. ๐ญ
$ btrfs balance start -dconvert=raid1 /mnt
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's too much data or the block groups occupy the whole first device.
The device size of /dev/sdb as seen by the filesystem remains unchanged, but the logical space from 50-100GiB will be unused. lowkey wasteful but that's the deal.
๐ Remove device
Device removal must satisfy the profile constraints, otherwise the command fails. For example:
$ btrfs device remove /dev/sda /mnt
ERROR: error removing device '/dev/sda': unable to go below two devices on raid1
In order to remove a device, you need to convert the profile in this case:
$ btrfs balance start -mconvert=dup -dconvert=single /mnt
$ btrfs device remove /dev/sda /mnt
Warning: Do not run balance to convert from a profile with more redundancy to one with less redundancy in order to remove a failing device from a filesystem. Balance is done by reading out the good metadata/data and write them into a new chunk. Thus it's possible the new chunk is written into the failing device. Use btrfs device replace instead.
like please, do not do that, i am begging. use btrfs device replace. periodt. ๐
๐ SUBCOMMAND ๐
okay bestie, this is the main character section โ every actual btrfs device verb lives here. no cap, all the flags are staying. โจ
โจ add [-Kf] <device> [<device>...] <path> โจ
Add device(s) to the filesystem identified by path. ๐
If applicable, a whole-device discard (TRIM) operation is performed before adding the device. A device with an existing filesystem detected by blkid(8) (link: https://man7.org/linux/man-pages/man8/blkid.8.html) will prevent device addition and has to be forced. Alternatively, the filesystem can be wiped from the device using e.g. the wipefs(8) tool (link: https://man7.org/linux/man-pages/man8/wipefs.8.html). ๐งน
The operation is instant and does not affect existing data. The operation merely adds the device to the filesystem structures and creates some block group headers. ๐ธ
โจ Options โจ
-K|--nodiscardโ do not perform discard (TRIM) by default-f|--forceโ force overwrite of existing filesystem on the given disk(s)--enqueueโ wait if there's another exclusive operation running, otherwise continue
๐ remove [options] <device>|<devid> [<device>|<devid>...] <path> ๐
Remove device(s) from a filesystem identified by <path>. ๐ซถ
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 Typical use cases โ internal ref: btrfs-device//#man-device-typical-use-cases. ๐ญ
The operation can take long as it needs to move all data from the device. fr fr, this one is a marathon, not a sprint.
Note: It's 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 still be used for writes. In that case there's a warning and safety timeout as this can be confusing and unexpected. The timeout can be overridden by option --force. โณ
It is possible to delete the device that was used to mount the filesystem. The device entry in the mount table (/proc/self/mounts) will be replaced by another device name with the lowest device id. ๐
If the filesystem is mounted in degraded mode (-o degraded), the special term missing can be used for device. In that case, the first device that is described by the filesystem metadata, but not present at the mount time, will be removed. ๐ฆ
Note: 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 inRAID6), you need to specifymissingas many times as the number of missing devices to remove all of them. ๐
โจ Options โจ
--enqueueโ wait if there's another exclusive operation running, otherwise continue--forceโ skip the safety timeout when there are multiple devices for removal, this does not force removing devices that would break the profile constraints
๐ delete <device>|<devid> [<device>|<devid>...] <path> ๐
Alias of remove kept for backward compatibility. it's giving legacy energy, but we respect it. ๐
๐ฆ replace <command> [options] <path> ๐ฆ
Alias of the whole command group btrfs replace for convenience. See btrfs-replace(8). โจ
๐ 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. ๐
โญ scan [options] [<device> [<device>...]] โญ
Scan devices for a btrfs filesystem and register them with the kernel module. This allows mounting a multiple-device filesystem by specifying just one from the whole group. ๐
If no devices are passed, all block devices that blkid reports to contain btrfs are scanned.
The options --all-devices or -d can be used as a fallback in case blkid is not available. If used, behavior is the same as if no devices are passed.
The command can be run repeatedly. Devices that have already been registered remain as such. Reloading the kernel module will drop this information. There's an alternative way of mounting a multiple-device filesystem without the need for prior scanning. See the mount option device (in btrfs-man5) โ internal ref: btrfs-man5//#mount-option-device. ๐ธ
โจ Options โจ
-d|--all-devicesโ Enumerate and register all devices, use as a fallback in caseblkidis not available.-u|--forgetโ Unregister a given device or all stale devices if no path is given, the device must be unmounted otherwise it's an error.
๐
stats [options] <path>|<device>|<file> ๐
Read and print the device IO error statistics for all devices of the given filesystem identified by path, or for a single device or file (the offline mode, unmounted filesystem). ๐
When the filesystem is mounted, the path is expected to be a directory and the stats are read using an ioctl and can be reset or checked. Same for a block device of a mounted filesystem.
For an offline mode, the path must be a file image or a block device, and the option --offline is mandatory. As it's read-only access, the option --reset does not work. ๐
See section DEVICE STATS for more information about the reported statistics and the meaning.
โจ Options โจ
-z|--resetโ Print the stats and reset the values to zero afterwards. Does not work in offline mode.-c|--checkโ Check if the stats are all zeros and return0if it is so. Set bit 6 of the return code if any of the statistics is no-zero. The error values is65if reading stats from at least one device failed, otherwise it's64. ๐--offlineโ Read the stats from the file image or directly from block device.-Tโ Print stats in a tabular form, devices as rows and stats as columns
๐ธ usage [options] <path> [<path>...]:: ๐ธ
Show detailed information about internal allocations on devices. ๐
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 a normal user (warning included) and the next one with root on the same filesystem:
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
- Device size โ size of the device as seen by the filesystem (may be different than actual device size)
- Device slack โ 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
- Data,single, Metadata,single, System,single โ in general, list of block group type (
Data,Metadata,System) and profile (single,RAID1, ...) allocated on the device - Data,RAID0/3 โ in particular, striped profiles
RAID0/RAID10/RAID5/RAID6with 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 - Unallocated โ remaining space that the filesystem can still use for new block groups
โจ Options โจ
-b|--rawโ raw numbers in bytes, without theBsuffix-h|--human-readableโ print human friendly numbers, base 1024, this is the default-Hโ print human friendly numbers, base 1000--iecโ select the 1024 base for the following options, according to the IEC standard--siโ select the 1000 base for the following options, according to the SI standard-k|--kbytesโ show sizes in KiB, or kB with--si-m|--mbytesโ show sizes in MiB, or MB with--si-g|--gbytesโ show sizes in GiB, or GB with--si-t|--tbytesโ show sizes in TiB, or TB with--si
If conflicting options are passed, the last one takes precedence. ๐
๐พ DEVICE STATS ๐พ
okay so the device stats are lowkey the receipts of your filesystem's bad days bestie. they keep a persistent record of several error classes related to doing IO. the current values get printed at mount time and then updated during the filesystem lifetime or from a scrub run. she never forgets โจ
$ 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
here's the girlies, one by one ๐
write_io_errsโ failed writes to the block devices. translation: the layers beneath the filesystem were not able to satisfy the write request. they simply could not do it for you ๐read_io_errsโ the read request analogy towrite_io_errs. same energy, reads instead of writes.flush_io_errsโ the number of failed writes with theFLUSHflag set. flushing is a method of forcing a particular order between write requests and it is crucial for implementing crash consistency. in the case of btrfs, all the metadata blocks must be permanently stored on the block device before the superblock is written. no cutting the line, periodt.corruption_errsโ a block checksum mismatched or a corrupted metadata header was found. it's giving chaos ๐ญgeneration_errsโ the block generation does not match the expected value (e.g. stored in the parent node). mismatch behavior, we don't love her.
also!! since kernel 5.14 the device stats are also available in textual form, right here:
/sys/fs/btrfs/FSID/devinfo/DEVID/error_stats
convenient?? yes. iconic?? obviously ๐ธ
๐ช EXIT STATUS ๐ช
btrfs devicereturns a zero exit status if it succeeds. non zero is returned in case of failure. she's honest like that.- if the
-coption is used,btrfs device statswill add64to the exit status if any of the error counters is non-zero. so like... nonzero plus64. do the math bestie ๐งฎ
๐ฆ AVAILABILITY ๐ฆ
btrfs is part of btrfs-progs. please refer to the documentation at https://btrfs.readthedocs.io. go read it, i'm not kidding, it's so good ๐ซถ
๐ SEE ALSO ๐
and that's a wrap on the whole page babes ๐
this was btrfs-device(8), version 7.3, dated Oct 24, 2026 โ go forth and check your device stats, your future self will literally thank you. mwah ๐โจ๐
๐ฆ where this page comes from
- arch rolling: btrfs-progs 7.3-1 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms