11

I have a bunch of btrfs snapshots like so:

20:17:37 [root@galaxy /]$ btrfs subvolume list -a / |grep apt
ID 271 gen 348 top level 5 path <FS_TREE>/@apt-snapshot-2013-04-17_21:44:30
ID 272 gen 352 top level 5 path <FS_TREE>/@apt-snapshot-2013-04-17_21:46:25
ID 273 gen 361 top level 5 path <FS_TREE>/@apt-snapshot-2013-04-17_21:51:13
... # lots more

I would like to get rid of them. So I tried

20:21:31 [root@galaxy ~]$ btrfs subvolume delete '/<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '/<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
20:21:36 [root@galaxy ~]$ btrfs subvolume delete '<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
20:21:43 [root@galaxy ~]$ btrfs subvolume delete '/@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '/@apt-snapshot-2013-04-17_21:44:30'
20:21:47 [root@galaxy ~]$ btrfs subvolume delete '@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '@apt-snapshot-2013-04-17_21:44:30'

What's the correct syntax to delete these snapshots?

2 Answers 2

11

I was able to delete these snapshots by first mounting the whole btrfs volume (not the @ subvolume) and then working from there:

# mount /dev/mapper/whatever /mnt -o subvol=/
# ls /mnt
@
@apt-snapshot-2013-04-17_21:44:30
...

So at this point, all subvolumes (including the funky apt-snapshot ones) are visible in /mnt, so we can delete them:

# btrfs subvol delete /mnt/@apt-snapshot-2013-04-17_21:44:30
# umount /mnt
2
  • 2
    Did you have to use a live CD for this?
    – mlissner
    Mar 7, 2015 at 0:10
  • 2
    No, I was able to do this while running the system from @ of the same filesystem.
    – Cactus
    Mar 7, 2015 at 1:25
3

The easiest way to do this is to use the built in apt-btrfs-snapshot commands:

Unlike normal snapshot deletion, you do not need to mount the filesystem to delete snapshots.

First, list the available apt-btrfs-snapshot snapshots using the following command:

sudo apt-btrfs-snapshot list

Here is an example of the output from that command:

@apt-snapshot-old-root-2015-10-19_20:20:10
@apt-snapshot-2015-10-28_19:00:46
@apt-snapshot-2015-10-28_19:09:14
@apt-snapshot-2015-10-29_04:40:07
@apt-snapshot-2015-10-29_06:35:57
@apt-snapshot-2015-10-29_07:03:39
@apt-snapshot-2015-10-30_03:49:05
@apt-snapshot-2015-10-30_17:53:59

To delete the snapshot @apt-snapshot-2015-10-30_17:53:59, run:

sudo apt-btrfs-snapshot delete @apt-snapshot-2015-10-30_17:53:59

You can also delete a number of snapshots by date. Here is an example of a command that would delete all snapshots that are older than 0 days.

sudo apt-btrfs-snapshot delete-older-than 0d   

Here is an example of the output from that command:

Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-odfe0o4g/@apt-snapshot-old-root-2015-10-19_20:20:10'
ERROR: cannot delete '/tmp/apt-btrfs-snapshot-mp-odfe0o4g/@apt-snapshot-old-root-2015-10-19_20:20:10' - Directory not empty
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-b2zv18qr/@apt-snapshot-2015-10-28_19:00:46'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-zjglvefe/@apt-snapshot-2015-10-28_19:09:14'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-lj3v74qa/@apt-snapshot-2015-10-29_04:40:07'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-vztc82zr/@apt-snapshot-2015-10-29_06:35:57'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-q0ou8e24/@apt-snapshot-2015-10-29_07:03:39'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-dw8eq0vv/@apt-snapshot-2015-10-30_03:49:05'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-vgo2yuf2/@apt-snapshot-2015-10-30_17:53:59'

As you can see, the available snapshots were deleted. However, the oldest snapshot "old-root" was not deleted and can still be used to roll back even though it is much older than 0 days.

Run the following command for a full list of features:

apt-btrfs-snapshot --help
4
  • I've just tried this, and sudo apt-btrfs-snapshot delete-older-than 30d proceeded to delete ALL snapshots...
    – Cactus
    Nov 29, 2015 at 6:42
  • @Cactus if all your snapshots are older than 30 days then, that's what should happen. To verify this before you start, you can run: sudo apt-btrfs-snapshot list-older-than 30d to see what is older than 30 days.
    – mchid
    Nov 29, 2015 at 7:13
  • @Cactus although, oldroot should not delete and can still be used as a restore point.
    – mchid
    Nov 29, 2015 at 7:14
  • 1
    Note that apt-btrfs-snapshot is not "built in" in every distribution. In particular it seem not to be available in the Debian repositories.
    – user44400
    Oct 25, 2019 at 18:45

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.