I have a regular directory than contains directly underneath it several btrfs snapshots. Is it safe to do an rm -rf
on the parent directory, or do I need to first do a btrfs subvolume delete SUBVOL
on each of the snapshots before removing the parent directory?
-
Possible duplicate of unix.stackexchange.com/questions/236745/…– StrongBadCommented Jan 29, 2016 at 15:29
2 Answers
rm -rf
is not unsafe per se, so go ahead and run it. However, it won't completely work. For some reason, an empty Btrfs subvolume cannot be removed with the rmdir(2)
system call.
rm -rf
will remove all of the contents of all of the subvolumes (regular files, etc...) but the empty subvolumes themselves as well as the parent directories of all those subvolumes will remain. You will have to delete those with btrfs subvolume delete
and then run rm -rf
again to take care of all the now-empty non-subvolume directories that couldn't be deleted earlier.
You probably know that deleting a subvolume with btrfs subvolume delete
is much faster than deleting all its contents. So if you know ahead of time that the directory tree you are about to rm -rf
has subvolumes in it, you can save yourself some work and time by btrfs subvolume delete
'ing them first, then running rm -rf
(which will work completely) after that.
You can use btrfs-rm.
I use it on a docker installation running on btrfs, to cleanup the whole docker dir on a regular basis. Use at your own risk, but works for me (TM).
sudo ./btrfs-rm /var/lib/docker/* # create clean empty dir for docker