info > BTRFS-DEVICE

๐Ÿ“ NAME

btrfs-device โ€” manage devices of btrfs filesystems

๐Ÿš€ Quick Reference

Use CaseCommandDescription
โž• Add a new devicebtrfs device add /dev/sdb /mntAdds a block device to a mounted btrfs filesystem
โŒ Remove a devicebtrfs device remove /dev/sda /mntRemoves a device after moving all data (may require profile conversion)
โŸณ Replace a devicebtrfs replace start /dev/sda /dev/sdb /mntReplaces a device (uses btrfs replace subcommand)
๐Ÿ“Š Show device statsbtrfs device stats /dev/sda3Displays I/O error counters per device
๐Ÿ” Scan for btrfs devicesbtrfs device scanRegisters all btrfs devices with kernel module for multi-device mounts
๐Ÿ“ˆ Show device usagebtrfs device usage /mntShows per-device allocation details (run as root for full info)

๐Ÿ“‹ SYNOPSIS

btrfs device <subcommand> <args>

๐Ÿ“– DESCRIPTION

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

๐Ÿ› ๏ธ DEVICE MANAGEMENT

Btrfs filesystem can be created on top of single or multiple block devices. Data and metadata are organized in allocation profiles with various redundancy policies. There's 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 mkfs.btrfs(8) for more details and the exact profile capabilities and constraints.

The device management works on a mounted filesystem. Devices can be added, removed or replaced, by commands provided by btrfs device and btrfs replace.

The profiles can be also changed, provided there's enough workspace to do the conversion, using the btrfs balance command and namely the filter convert.

See the section TYPICAL USECASES for some examples.

๐Ÿ“‚ SUBCOMMAND

โž• add [-Kf] <device> [<device>...] <path>

Add device(s) to the filesystem identified by <path>.

If applicable, a whole device discard (TRIM) operation is performed prior to adding the device. A device with existing filesystem detected by blkid(8) will prevent device addition and has to be forced. Alternatively the filesystem can be wiped from the device using e.g. wipefs(8).

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.

โŒ 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. The filesystem must be converted to profile(s) that would allow the removal. This can typically happen when going down from 2 devices to 1 and using the RAID1 profile. See the TYPICAL USECASES section below.

โฑ๏ธ The operation can take long as it needs to move all data from the device.

It is possible to delete the device that was used to mount the filesystem. The device entry in the mount table will be replaced by another device name with the lowest device id.

If the filesystem is mounted in degraded mode (-o degraded), 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 in RAID6), you need specify missing as many times as the number of missing devices to remove all of them.

๐Ÿ—‘๏ธ delete <device>|<devid> [<device>|<devid>...] <path>

Alias of remove kept for backward compatibility.

โณ 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 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 been already registered remain as such. Reloading the kernel module will drop this information. There's an alternative way of mounting multiple-device filesystem without the need for prior scanning. See the mount option device.

๐Ÿ“Š stats [options] <path>|<device>

Read and print the device IO error statistics for all devices of the given filesystem identified by <path> or for a single <device>. The filesystem must be mounted. See section DEVICE STATS for more information about the reported statistics and the meaning.

๐Ÿ“ˆ 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 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

If conflicting options are passed, the last one takes precedence.

๐Ÿ“˜ TYPICAL USECASES

๐Ÿš€ 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.

๐Ÿ”„ 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.

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.

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:

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're going to lose 50GiB of the second device for obvious reasons.

$ 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.

โŒ 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

๐Ÿ“Š DEVICE STATS

The device stats keep persistent record of several error classes related to doing I/O. The current values are printed at mount time and updated during filesystem lifetime or from a scrub run.

$ 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

Since kernel 5.14 the device stats are also available in textual form in /sys/fs/btrfs/FSID/devinfo/DEVID/error_stats.

๐Ÿšช EXIT STATUS

btrfs device returns a zero exit status if it succeeds. Non-zero is returned in case of failure.

If the -s option is used with btrfs device stats, it will add 64 to the exit status if any of the error counters is non-zero.

๐ŸŒ AVAILABILITY

btrfs is part of btrfs-progs. Please refer to the btrfs wiki for further details.

๐Ÿ“š SEE ALSO

BTRFS-DEVICE
๐Ÿ“ NAME ๐Ÿš€ Quick Reference ๐Ÿ“‹ SYNOPSIS ๐Ÿ“– DESCRIPTION ๐Ÿ› ๏ธ DEVICE MANAGEMENT ๐Ÿ“‚ SUBCOMMAND
โž• add [-Kf] <device> [<device>...] <path> โŒ remove [options] <device>|<devid> [<device>|<devid>...] <path> ๐Ÿ—‘๏ธ delete <device>|<devid> [<device>|<devid>...] <path> โณ ready <device> ๐Ÿ” scan [options] [<device> [<device>...]] ๐Ÿ“Š stats [options] <path>|<device> ๐Ÿ“ˆ usage [options] <path> [<path>...]
๐Ÿ“˜ TYPICAL USECASES
๐Ÿš€ Starting with a Single-Device Filesystem
๐Ÿ“Š DEVICE STATS ๐Ÿšช EXIT STATUS ๐ŸŒ AVAILABILITY ๐Ÿ“š SEE ALSO

Generated by phpman v4.9.26-1-g511901d Author: Che Dong Under GNU General Public License
2026-08-09 09:59 @2600:1f28:365:80b0:50b3:453e:ff52:20f7
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format