Replace /path/to/mountpoint with the Btrfs filesystem's mount point (e.g., /mnt/btrfs) and subvolume_name with the desired name (e.g., data).
Example:
bash
sudo btrfs subvolume create /mnt/btrfs/data
This creates a subvolume named data under the Btrfs mount point /mnt/btrfs.
Key Details
Permissions: Requires root privileges (sudo).
Path: The subvolume is created relative to the Btrfs mount point. For example, if /mnt/btrfs is the root of the Btrfs filesystem, the new subvolume will exist at /mnt/btrfs/data.
Automatic Mounting: Subvolumes are accessible immediately after creation if the parent Btrfs filesystem is mounted.
Common Options
-i <ID>: Assign a specific subvolume ID (advanced, rarely needed).
Example:
Creates team1 and team2 subvolumes under projects.
User
convert existing dir to subvolume.
Assistant
To convert an existing directory into a Btrfs subvolume, you cannot do it in-place. Instead, you must move the directory's contents into a new subvolume and replace the original directory with the subvolume. Here's how to do it safely:
Step-by-Step Guide
1. Create a Temporary Subvolume
Create a temporary subvolume to hold the directory's contents:
Use btrfs subvolume create to make new subvolumes.
Subvolumes inherit properties of the parent Btrfs filesystem.
Mount subvolumes independently for isolation (e.g., separate OS installations, containers).
Snapshots allow efficient backups/clones.
Let me know if you need help with quotas, compression, or RAID configurations! 🚀
bash
sudo btrfs subvolume list /path/to/mountpoint
Example:
bash
sudo btrfs subvolume list /mnt/btrfs
You should see /data listed as a subvolume.
Check Contents:
bash
ls /mnt/btrfs/data # Should show your original files
Key Notes
Why This Works: Btrfs subvolumes are separate entities from regular directories. By moving data into a subvolume and replacing the directory, you effectively "convert" it.
Data Safety: This process preserves all file attributes (permissions, timestamps, etc.) because mv maintains them.
Mounting: If you want to mount the new subvolume separately (e.g., for backups), use:
bash
sudo mount -o subvol=data /dev/sdX /mnt/data
Example Scenario
Goal: Convert /mnt/btrfs/projects (a regular directory) into a subvolume.
Directory Must Be Empty: If the original directory contains files while in use (e.g., /home), unmount or stop services using it before proceeding.
UUID Check: Use sudo btrfs filesystem show to confirm the correct device UUID for mounting.
Reversibility: To revert, delete the subvolume and restore files from a backup.
By following these steps, you can safely convert any directory into a Btrfs subvolume and leverage features like snapshots, quotas, and independent mounting. 🚀