I have disk with btrfs file system which is mounted on root directory.

$ sudo btrfs subvol show  /media/qkiz/Corsair/
/media/qkiz/Corsair is btrfs root

On this this root is a snapshot.

$ sudo btrfs subvol show  /media/qkiz/Corsair/snapshot/
    Name:           snapshot
    uuid:           94d5d0fa-aaf4-d84c-b716-d5121accf7a0
    Parent uuid:        -
    Creation time:      2015-12-02 13:31:18
    Object ID:      258
    Generation (Gen):   23
    Gen at creation:    23
    Parent:         5
    Top Level:      5
    Flags:          -

I make changes on root file system and now I want to back to snapshot. If I change default subvolume:

$ sudo btrfs subvol set-default 258 /media/qkiz/Corsair/

I can see state from snapshot but disk space is still used by root directory. How to delete root directory and use snapshot as root??


To make your life easier, I would recommend that the root btrfs subvolume (id=5) is only used to manage other subvolumes and snapshots. Don't store a lot of data on the root subvolume and don't reference it in scripts etc. This will make it a lot easier for you to make snapshots, do roll-backs etc.

For example, in fstab:

# Root of btrfs volume. Used for volume management.
# Do not reference /mnt/root-XYZ/ in scripts or software.
LABEL=XYZ /mnt/root-XYZ btrfs noauto,subvolid=5

# Software using data on this subvolume should reference this path:
#     /media/qkiz/Corsair/...
# and NOT /mnt/root-XYZ/corsair/...
LABEL=XYZ /media/qkiz/Corsair btrfs noauto,subvol=corsair

(you would change XYZ to your actual btrfs label)

Do put this into effect, you could create a snapshot of your root subvolume, and call it corsair. Probably also make a read-only snapshot of corsair, for backup purposes. Then delete files from the root subvolume. For example:

umount /mnt/qkiz/Corsair
mount /mnt/root-XYZ
cd /mnt/root-XYZ
btrfs subvol snap . corsair
btrfs subvol snap -r corsair corsair-YYMMDD

Check that corsair-YYMMDD/ contains your important data, then delete the data from your root subvolume:

rm -rf ./datafiles....

Finally, mount your new subvolume:

mount /mnt/qkiz/Corsair

You could make your 'corsair' subvolume the default subvolume if you wanted, but that is not strictly necessary. It could be useful if this is a portable drive and you move it to another machine with a different fstab. In that way, the corsair subvolume would be mounted by default, and not the root subvolume.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.