Btrfs Subvolumes
Btrfs Subvolumes are a powerful feature for organizing data and enabling snapshot-based backups. A subvolume acts as a virtual directory within a Btrfs filesystem, allowing independent mounting, snapshots, and permission management. This section covers how to create, manage, and leverage subvolumes for structured storage administration.
Creating Subvolumes¶
To create a new subvolume, use the btrfs subvol create command. Subvolumes are typically created under the root subvolume (which is automatically created when the filesystem is initialized).
Example:
data_home under /mnt/btrfs.
Note: Subvolumes must reside within a Btrfs filesystem. Ensure the mount point is correctly specified.
Managing Subvolumes¶
Use the btrfs subvol command to rename, delete, or inspect subvolumes.
Renaming a Subvolume:
Deleting a Subvolume:
Listing Subvolumes:
Mounting Subvolumes¶
Subvolumes can be mounted independently using the mount command with the subvol option.
Mounting a Subvolume:
data_home subvolume from /dev/sdb1 to /mnt/btrfs_mount.
For persistent mounts, add an entry to /etc/fstab:
Snapshots and Subvolumes¶
Subvolumes are essential for creating snapshots. Use btrfs subvol snapshot to generate read-only copies.
Creating a Snapshot:
-r flag ensures the snapshot is read-only.
Restoring from a Snapshot:
Unmount the original subvolume and replace it with the snapshot:
Permissions and Access Control¶
Subvolumes inherit standard Unix permissions but can be isolated for security. Use chown or chmod to adjust ownership and access rights. For granular control, combine subvolumes with Access Control Lists (ACLs):
Troubleshooting Tips¶
- Permission Errors: Ensure the user has execute permissions on the parent directory of the subvolume.
- Snapshot Failures: Verify the source subvolume exists and the target path is writable.
- Mount Issues: Check if the subvolume ID matches the one in
/etc/fstabor themountcommand.
Key takeaways¶
- Subvolumes enable logical organization and independent management of Btrfs data.
- Use
btrfs subvol createandbtrfs subvol snapshotfor structured storage workflows. - Mount subvolumes via
mount -o subvol=...or/etc/fstabfor persistent access. - Snapshots on subvolumes simplify backups and rollbacks.
- Permissions and ACLs can isolate subvolumes for security or access control.