BTRFS and filling up / filesystem with snapshots (@apt-snapshot)

0

In addition to my ZFS adventures I recently also installed Ubuntu 14.04 with btrfs as root.

While the installation was straight forward and went fine I spotted that after some while my root FS was increasing and increasing without any real reason.

Up to then I didnt realise that whenever I run an apt-get upgrade btrfs creates a snapshot.

You can see those snapshots by using

# btrfs subvolume list /
ID 257 gen 8065 top level 5 path @
ID 258 gen 8062 top level 5 path @home
ID 326 gen 6506 top level 5 path @apt-snapshot-2014-05-15_21:01:13
ID 327 gen 6507 top level 5 path @apt-snapshot-2014-05-15_21:01:13/@
ID 330 gen 6518 top level 5 path @apt-snapshot-2014-05-15_21:05:49
ID 331 gen 6519 top level 5 path @apt-snapshot-2014-05-15_21:05:49/@
ID 334 gen 7304 top level 5 path @apt-snapshot-2014-05-22_16:01:03
ID 335 gen 7317 top level 5 path @apt-snapshot-2014-05-22_16:08:00
ID 336 gen 7318 top level 5 path @apt-snapshot-2014-05-22_16:08:01
ID 337 gen 7319 top level 5 path @apt-snapshot-2014-05-22_16:08:02

While that gives you the chance to roll back some broken updates it fills up the root fs.

Simple solution is to clean up maybe after 7 days or so. To do some maintence there is a separate tool named apt-btrfs-snapshot which of course does not come as default.

apt-get install apt-btrfs-snapshot

You can use that in the following ways:

list snapshots

# apt-btrfs-snapshot list
Available snapshots:
@apt-snapshot-2014-05-15_21:01:13
@apt-snapshot-2014-05-15_21:05:49
@apt-snapshot-2014-05-22_16:01:03
@apt-snapshot-2014-05-22_16:08:00
@apt-snapshot-2014-05-22_16:08:01
@apt-snapshot-2014-05-22_16:08:02

delete older snapshots (where 1d stands for older than 1day)

apt-btrfs-snapshot delete-older-than 1d

# apt-btrfs-snapshot delete-older-than 1d
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-y05mz9q6/@apt-snapshot-2014-05-15_21:01:13'
ERROR: cannot delete '/tmp/apt-btrfs-snapshot-mp-y05mz9q6/@apt-snapshot-2014-05-15_21:01:13' - Directory not empty
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-t8y4zdsz/@apt-snapshot-2014-05-15_21:05:49'
ERROR: cannot delete '/tmp/apt-btrfs-snapshot-mp-t8y4zdsz/@apt-snapshot-2014-05-15_21:05:49' - Directory not empty
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-x82l81rk/@apt-snapshot-2014-05-22_16:01:03'
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-qjqhvz5a/@apt-snapshot-2014-05-22_16:08:00'
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-_mi1wtsh/@apt-snapshot-2014-05-22_16:08:01'
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-kgz6muje/@apt-snapshot-2014-05-22_16:08:02'

As you can see is that not too straightforward. Its unable to delete the main snap because of the @subset

Solution:

Find out where your btrfs is located:

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb4 25G 11G 14G 43% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 3.9G 4.0K 3.9G 1% /dev
tmpfs 783M 1.3M 781M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 3.9G 19M 3.9G 1% /run/shm
none 100M 52K 100M 1% /run/user
/dev/sdb4 25G 11G 14G 43% /home

In my case its under /dev/sdb4 including the /home subset

I do mount it under /mnt and you can see the snapshots in there

# mount /dev/sdb4 /mnt
# cd /mnt
# ls
@ @apt-snapshot-2014-05-15_21:01:13 @apt-snapshot-2014-05-15_21:05:49 @home
# btrfs subvolume list /mnt
ID 257 gen 8090 top level 5 path @
ID 258 gen 8073 top level 5 path @home
ID 326 gen 6506 top level 5 path @apt-snapshot-2014-05-15_21:01:13
ID 327 gen 6507 top level 5 path @apt-snapshot-2014-05-15_21:01:13/@
ID 330 gen 6518 top level 5 path @apt-snapshot-2014-05-15_21:05:49
ID 331 gen 6519 top level 5 path @apt-snapshot-2014-05-15_21:05:49/@

lets whack the one with the @ at the end which are causing the issues.

# btrfs subvolume delete /mnt/@apt-snapshot-2014-05-15_21:01:13/@
Delete subvolume '/mnt/@apt-snapshot-2014-05-15_21:01:13/@'
# btrfs subvolume delete /mnt/@apt-snapshot-2014-05-15_21:05:49/@
Delete subvolume '/mnt/@apt-snapshot-2014-05-15_21:05:49/@'

That should do the job now.

# apt-btrfs-snapshot list
Available snapshots:
@apt-snapshot-2014-05-15_21:01:13
@apt-snapshot-2014-05-15_21:05:49

# apt-btrfs-snapshot delete-older-than 1d
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-3m52fcjv/@apt-snapshot-2014-05-15_21:01:13'
Delete subvolume '/tmp/apt-btrfs-snapshot-mp-w6smuzp8/@apt-snapshot-2014-05-15_21:05:49'

# apt-btrfs-snapshot list
Available snapshots:

# btrfs subvolume list /
ID 257 gen 8094 top level 5 path @
ID 258 gen 8073 top level 5 path @home

# cd ..
# umount /mnt

# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sdb4 25G 9.1G 15G 39% /

All gone. Certainly not the most elegant way but that sorts out the locked space. Of course please keep in mind that deleting the snapshots will remove the ability to roll back. So use wisely.

Leave a Reply