8

I can not delete the "apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26" btrfs snapshot. Here are the details:

root@cioco:~# btrfs subvolume list -s /
ID 261 gen 246 cgen 245 top level 5 otime 2013-10-19 00:52:26 path @apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
root@cioco:~# btrfs subvolume list  /
ID 256 gen 334584 top level 5 path @
ID 258 gen 334134 top level 5 path @home
ID 261 gen 246 top level 5 path @apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
ID 267 gen 334580 top level 256 path var/lib/lxc/mythtv/rootfs
ID 268 gen 334584 top level 256 path var/lib/lxc/jira/rootfs
ID 278 gen 279278 top level 256 path var/lib/lxc/michele/rootfs
root@cioco:~# grep btrfs /proc/self/mountinfo
20 1 0:16 /@ / rw,relatime - btrfs /dev/sda2 rw,compress=zlib,space_cache
39 20 0:16 /@home /home rw,relatime - btrfs /dev/sda2 rw,compress=zlib,space_cache

root@cioco:~# btrfs subvolume delete /@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
ERROR: error accessing '/@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26' 

However I can delete a snapshot created by me:

root@cioco:~# btrfs subvolume snapshot / root-snap
Create a snapshot of '/' in './root-snap'
root@cioco:~# btrfs subvolume list -s /
ID 261 gen 246 cgen 245 top level 5 otime 2013-10-19 00:52:26 path @apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
ID 309 gen 334592 cgen 334592 top level 256 otime 2014-03-31 02:19:08 path root/root-snap
root@cioco:~# btrfs subvolume delete /root/root-snap
Delete subvolume '/root/root-snap'

EDIT1: There is nothing logged in the kernel log:

root@cioco:~# dmesg -c >/dev/null
root@cioco:~# btrfs subvolume delete /@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
ERROR: error accessing '/@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26'
root@cioco:~# dmesg
root@cioco:~#

But strace gives a hint:

root@cioco:~# strace btrfs subvolume delete /@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
...
stat("/@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26", 0x7fffe88ebb60) = -1 ENOENT (No such file or directory)
write(2, "ERROR: error accessing '/@apt-sn"..., 82ERROR: error accessing '/@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26'
) = 82

Edit2: I've mounted the volume...

root@cioco:~# mkdir /snapshot
root@cioco:~# mount /dev/sda2 /snapshot -o subvol=/@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
root@cioco:~# grep btrfs /proc/self/mountinfo
20 1 0:16 /@ / rw,relatime - btrfs /dev/sda2 rw,compress=zlib,space_cache
39 20 0:16 /@home /home rw,relatime - btrfs /dev/sda2 rw,compress=zlib,space_cache
61 20 0:16 /@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26 /snapshot rw,relatime - btrfs /dev/sda2 rw,compress=zlib,space_cache
root@cioco:~# btrfs subvolume delete /snapshot/
Delete subvolume '//snapshot'
ERROR: cannot delete '//snapshot' - Invalid argument

root@cioco:~# strace btrfs subvolume delete /snapshot/
...
stat("/snapshot", {st_mode=S_IFDIR|0755, st_size=230, ...}) = 0
brk(0)                                  = 0x2206000
brk(0x2228000)                          = 0x2228000
lstat("/snapshot", {st_mode=S_IFDIR|0755, st_size=230, ...}) = 0
stat("/", {st_mode=S_IFDIR|0755, st_size=242, ...}) = 0
openat(AT_FDCWD, "/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
fstat(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 23), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd8ad2ae000
write(1, "Delete subvolume '//snapshot'\n", 30Delete subvolume '//snapshot'
) = 30
ioctl(3, BTRFS_IOC_SNAP_DESTROY, 0x7fff5f1e5878) = -1 EINVAL (Invalid argument)
close(3)                                = 0
write(2, "ERROR: cannot delete '//snapshot"..., 53ERROR: cannot delete '//snapshot' - Invalid argument
) = 53
...

root@cioco:~# dmesg
[3172764.459166] device label cioco-root devid 1 transid 336213 /dev/sda2

Edit3: Solution

root@cioco:~# mount /dev/sda2 /btrfs-root/
root@cioco:~# ls -l /btrfs-root/
total 0
drwxr-xr-x 1 root root 262 Apr  1 08:31 @
drwxr-xr-x 1 root root 230 Oct 16 22:53 @apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26
drwxr-xr-x 1 root root   6 Oct 16 22:13 @home
root@cioco:~# btrfs subvolume delete /btrfs-root/@apt-snapshot-release-upgrade-saucy-2013-10-19_00\:52\:26/
Delete subvolume '/btrfs-root/@apt-snapshot-release-upgrade-saucy-2013-10-19_00:52:26'
root@cioco:~# dmesg
[41113.537617] device label cioco-root devid 1 transid 337615 /dev/sda2

Any help would be appreciated.

8
  • Can you delete it from a Live session? Maybe it's still in use. grepping /proc/self/mountinfo is not enough, for example it may be used as a bind mount or if it was unmounted with umount -l (lazy unmount) and I don't know whether there may be other cases.
    – ignis
    Mar 31, 2014 at 7:19
  • It is not mounted at all. The system is my home server. And I think that the snapshot was taken after Ubuntu upgrade. I am running now Ubuntu 13.10 64bit Mar 31, 2014 at 7:34
  • What do you mean by "Live session"? Mar 31, 2014 at 7:35
  • I mean Live DVD or Live USB.
    – ignis
    Mar 31, 2014 at 7:38
  • Please post the output of dmesg | tail after that btrfs subvolume delete fails.
    – ignis
    Mar 31, 2014 at 7:41

1 Answer 1

16

The snapshot exists in the real root of the filesystem, which is not what you have mounted in /. You have the /@ subvolume mounted in /, so there is no such file with that name. You have to mount the real root volume somewhere and use that path to reference the snapshot.

Or you can use apt-btrfs-snapshot delete instead.

7
  • 2
    I've had so many problems mounting and deleting in the past but have never had any trouble running apt-btrfs-snapshot delete
    – mchid
    Aug 29, 2015 at 2:26
  • Unlike normal btrfs snapshot management, apt-btrfs-snapshot is to be run from a running system and not a mounted partition.
    – mchid
    Jul 19, 2016 at 16:46
  • 3
    @mchid, what? Normal btrfs snapshot management is run from a running system... apt-btrfs-snapshot is just an apt script that automatically runs the normal btrfs snapshot any time you have apt install/upgrade/remove packages.
    – psusi
    Jul 20, 2016 at 1:39
  • My problem is that I am in a disk full situation because of the snapshots, hence I can't install apt-btrfs-snapshot.
    – fccoelho
    Oct 15, 2018 at 16:22
  • You have to boot from a USB to delete stuff when you run out of space. Also, I guess you can delete from a running system if you mount the volume to /mnt.
    – mchid
    Oct 25, 2019 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .