/var/lib/snapd/snaps retains huge amounts of data

I’ve been struggling with a full hard drive for a few years; blaming my use of nodejs/git etc. I’ve set refresh.retain to 2 and manually copied and checked a script from https://www.linuxuprising.com/2019/04/how-to-remove-old-snap-versions-to-free.html so that I can run it when my filesystem is full.

Finally I’ve figured out today that /var/lib/snapd/snaps still holds many older versions of downloaded snaps. I run du -h -x --max-depth=6 -t 1100000000 regularly and write it’s output to a timestampted file, so I can see that this folder has grown linearly from 2.8G at the end of 2020 to 6.2G today.

E.g. snap thinks there’s only one firefox version installed, but there is almost 2GB of Firefox snaps in that folder:

$ snap list --all |grep firef
firefox               119.0.1-1                   3358   latest/stable    mozilla**       -
$ ls -al /var/lib/snapd/snaps/ |grep firef
-rw-------  1 root root 254681088 May 31 11:08 firefox_2710.snap
-rw-------  1 root root 256638976 Jun  9 17:10 firefox_2760.snap
-rw-------  1 root root 256905216 Jul  5 10:57 firefox_2850.snap
-rw-------  1 root root 248733696 Aug  3 19:10 firefox_2952.snap
-rw-------  1 root root 248729600 Aug 16 16:18 firefox_2987.snap
-rw-------  1 root root 248418304 Sep 22 12:53 firefox_3131.snap
-rw-------  1 root root 251994112 Nov  7 14:08 firefox_3290.snap
-rw-------  1 root root 251990016 Nov  8 16:41 firefox_3358.snap

So basically I must have the same problem as this poster: https://superuser.com/questions/1811233/snap-list-all-does-not-show-everyting-in-var-lib-snapd-snaps

I was just going to purchase a new hard drive and glad I haven’t.

Is this on anyone’s radar or am I posting to the wrong forum?

2 Likes

This smells like a snapd bug, it should only keep two versions by default… you can use the --revision= option to the remove command to remove the older versions

1 Like

I am also seeing multiple revisions (9) of firefox in /var/lib/snapd/snaps/. Other snaps have two revisions. I’m on u22.04

1 Like

Given it’s firefox, which I’m guessing it quite often running, this may be a bug with refresh awareness. A blind guess, but perhaps the downloads aren’t being cleaned up properly if an update was postponed long enough to be superseded by yet another revision bump.

1 Like

It appears to be happening only with Firefox. I checked it now, and guess: there are 4 versions of Firefox, and the rest have only 2 versions. (I’m on u22.04)

I had the same issue with telegram, code, and some other snaps. I manually removed older snap versions that don’t show up on snap list --all, then ran snap refresh.

A few days in, everything’s good.

Tested on Ubuntu 20.04 and 22.04, on Intel and AMD.