Btrfs supports volume management without external configuration files. Let’s explore how Btrfs assembles devices and verifies them during mount
Below is an overview of how Btrfs assembles devices and verifies them during mount:
- Device Registration and Volume Formation:
- On-disk super-blocks and root trees are created during
mkfs.btrfs. - Devices are read into the kernel using
BTRFS_IOC_SCAN_DEVioctl to/dev/btrfs-control. - The list of Btrfs filesystems is maintained in the kernel, with each pointing to an fsid
struct btrfs_fs_devices. - Information about the devices is maintained in the list at
btrfs_fs_devices::devlist.
- On-disk super-blocks and root trees are created during
- Device Paths:
- Device paths may be updated during boot.
- Matched device paths are scanned again during subvolume mount.
- Device Identification:
- Each device has a unique UUID and devid.
- During mount, any registered device can be used to mount the entire volume.
- Manual device specification is possible using
btrfs device scan \--forgetfollowed by specifying devices in the mount option.
- Generation Number:
- Devices have a generation number.
- If multiple devices have the same UUID and devid, the one with the larger generation number is chosen.
- This prevents older or reappeared devices from joining the volume.
- System Chunk Array:
- Metadata chunks information is stored in
sys_chunk_arrayin each superblock on each device. - Additional devices needed for assembly are listed here.
- UUID and devid are verified against the devices in
btrfs_fs_devices::devlist.
- Metadata chunks information is stored in
- Chunk Tree and Verification:
- The chunk-tree root is loaded from
btrfs_super_block::chunk_root. - Devices are checked against devid, uuid, and fsid/metadata_uuid.
- Verification includes physical sizes and dev extent to chunk mapping.
- The chunk-tree root is loaded from
- Missing Devices:
- Missing devices are identified during metadata-required device identification and chunk tree read.
- If a missing device reappears, it won’t immediately join the allocation.
- A mount recycle is needed to copy missing blocks.
- Block Groups and Data Redundancy:
- Block-group profiles manage redundancy.
- It can be visualized for a mounted btrfs filesystem at
/sys/fs/btrfs/\<fsid>/allocation/\<bg-type>/\<bg> - Block groups are searched in the extent-tree or a separate block-group-tree (since kernel v6.1).
- Verifies the required set of devices for a degraded mount in case of a missing device.
In summary, Btrfs ensures robust device assembly verification and adaptability during mount.