My root file system is on a btrfs partition. My /chroot directory has a number of btrfs subvolumes in it which prevent me from deleting it with rm -rf /chroot. In an attempt to delete all the subvolumes, I tried listing just the subvolumes below /chroot by using the -o, which the man page says "print only subvolumes below specified path".

# btrfs subvolume list -o /chroot
ID 593 gen 6616 top level 5 path chroot/base-devel/root
ID 594 gen 6618 top level 5 path chroot/multilib-devel/root
ID 595 gen 6620 top level 5 path chroot/base/root
ID 597 gen 6624 top level 5 path chroot/twm/root
ID 599 gen 6628 top level 5 path chroot/lxde/root
ID 601 gen 6655 top level 5 path chroot/wheezy/root
ID 602 gen 6684 top level 5 path chroot/sid/root
ID 603 gen 6862 top level 5 path var/lib/machines

To my surprise, this returns the subvolume in /var/lib/macines (which I do not want to delete). This leads me to 3 questions:

  1. What does the -o option do?

  2. How do I list only subvolumes below /chroot

  3. How can I delete a directory with an unknown number of subvolumes?

I am running Arch Linux with the 4.2.5 kernel and btrfs-progs v4.3.1

  • What kernel are you running and what version of the btrfs tools do you have installed? This is probably a bug in the tools. – David King Dec 23 '15 at 16:31
  • @DavidKing see edit. I am running a fairly recent kernel and btrfs-progs. – StrongBad Dec 23 '15 at 19:15
  • I would file a bug report with btrfs. In the mean time could you pipe the list of directories through grep chroot? – David King Dec 24 '15 at 1:21

The following command removes all subvolumes in the /chrootdirectory:

ls /chroot | xargs btrfs subvolume delete

In case there are files or directories that are not btrfs subvolumes present, an error will be printed, but they are not removed.

(Tested on Debian with the 4.6.0 kernel and btrfs-progs v3.17)


To answer your third question, 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

Download: https://github.com/DirkTheDaring/btrfs-rm

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.