23

I'm using Ubuntu 20.04 LTS.

My snapd service is unavailable :

$ systemctl status snapd.service
● snapd.service - Snap Daemon
     Loaded: loaded (/lib/systemd/system/snapd.service; enabled; vendor preset: enabled)
     Active: deactivating (stop-sigterm) (Result: timeout)
TriggeredBy: ● snapd.socket
   Main PID: 29952 (snapd)
      Tasks: 10 (limit: 8186)
     Memory: 12.8M
     CGroup: /system.slice/snapd.service
             └─29952 /usr/lib/snapd/snapd

Oct 27 00:47:07 seb-C70D-B-311 systemd[1]: Starting Snap Daemon...
Oct 27 00:47:07 seb-C70D-B-311 snapd[29952]: AppArmor status: apparmor is enabled and all features are available
Oct 27 00:47:07 seb-C70D-B-311 snapd[29952]: AppArmor status: apparmor is enabled and all features are available
Oct 27 00:48:37 seb-C70D-B-311 systemd[1]: snapd.service: start operation timed out. Terminating.
$ time snap version
snap    2.52.1
snapd   unavailable
series  -

real    0m25.075s
user    0m0.036s
sys 0m0.060s

My /var/lib/snapd filesystem is full :

$ df -PTh /var/lib/snapd
Filesystem                                                            Type  Size  Used Avail Use% Mounted on
/dev/mapper/VG_Samsung_SSD_860_EVO_1TB__S3Z9NB0K4019-LV_var_lib_snapd ext4  4.9G  4.9G     0 100% /var/lib/snapd
$ ls -lh /var/lib/snapd/snaps
total 4.0G
-rw------- 1 root root  68K Sep 10 23:08 acrordrdc_53.snap
-rw------- 1 root root  68K Sep 20 13:03 acrordrdc_62.snap
-rw------- 2 root root 4.0K Sep 26 12:44 bare_5.snap
-rw------- 1 root root 146M Oct 10 21:58 chromium_1781.snap
-rw------- 2 root root 145M Oct 23 12:29 chromium_1801.snap
-rw------- 1 root root  56M Jun 23 18:57 core18_2074.snap
-rw------- 1 root root  56M Aug 15 17:45 core18_2128.snap
-rw------- 1 root root  62M Jul 24 10:15 core20_1081.snap
-rw------- 1 root root  62M Oct  8 22:05 core20_1169.snap
-rw------- 1 root root 100M Oct 15 11:18 core_11798.snap
-rw------- 1 root root 100M Oct 21 12:26 core_11993.snap
-rw------- 2 root root 163M Dec 19  2020 gnome-3-28-1804_145.snap
-rw------- 1 root root 165M Jul  8 16:18 gnome-3-28-1804_161.snap
-rw------- 1 root root 219M Jan  9  2021 gnome-3-34-1804_66.snap
-rw------- 1 root root 219M Jun 14 14:23 gnome-3-34-1804_72.snap
-rw------- 1 root root  66M Apr 22  2021 gtk-common-themes_1515.snap
-rw------- 1 root root  66M Sep 26 12:44 gtk-common-themes_1519.snap
-rw------- 2 root root 140K Aug 23  2020 gtk2-common-themes_13.snap
drwxr-xr-x 2 root root 4.0K Jul 10  2020 partial/
-rw------- 1 root root  33M Oct 13 20:06 snapd_13270.snap
-rw------- 1 root root  33M Oct 20 21:14 snapd_13640.snap
-rw------- 1 root root 136M Aug 23 00:17 whatsapp-for-linux_26.snap
-rw------- 1 root root 112M Oct 18 15:58 whatsapp-for-linux_27.snap
-rw------- 2 root root 304M Feb  6  2021 wine-platform-5-stable_16.snap
-rw------- 1 root root 304M Sep 26 12:44 wine-platform-5-stable_18.snap
-rw------- 2 root root 323M Sep 20 13:03 wine-platform-6-stable_8.snap
-rw------- 1 root root 347M Oct  8 22:05 wine-platform-runtime_250.snap
-rw------- 1 root root 347M Oct 15 11:19 wine-platform-runtime_251.snap
-rw------- 1 root root 347M Oct 23 12:29 wine-platform-runtime_252.snap
-rw------- 1 root root 164M Oct 26 22:50 wine-platform-runtime_252.snap.partial

Howto can I free up space properly on my /var/lib/snapd filesystem when snapd is unavailable ?

EDIT0 : Cannot start the snapd service successfully, maybe because my /var/lib/snapd filesystem is full.

SebMa
  • 2,081
  • 3
  • 28
  • 38
  • Make snapd active, then remove the snap packages using `sudo snap remove packagename`. What do you mean with "My /var/lib/snapd filesystem is full :"? Is that residing on a separate partition that is full? – vanadium Oct 27 '21 at 07:06
  • @vanadium Hi, thank you for your answer. See my EDIT0. – SebMa Oct 27 '21 at 14:00
  • Never seen someone have a separate partition only for the snaps. The problem is caused by a lack of space. Solution: enlarge that partition. Recommendation: do not have that on a dedicated partition. – vanadium Oct 27 '21 at 15:54
  • @vanadium Can't. I don't have spare space anymore. – SebMa Oct 28 '21 at 17:02

2 Answers2

29

You can remove all unused version of snap packages. You can create a script file and make it executable, or just copy & paste it in the console.

Note you need sudo rights for it.

#!/bin/sh
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read pkg revision; do
  sudo snap remove "$pkg" --revision="$revision"
done

If the snap remove command does not work because the snapd server is not run, you should free some space manually. You can remove an old version of a snap package file.

E.g., user ha two Chromium snaps, chromium_1781.snap and chromium_1801.snap. Just manually remove the older version using:

sudo rm /var/lib/snapd/snaps/chromium_1781.snap

And try to run the snapd service.

Also, you can clean your file logs to get free space by this command:

journalctl --vacuum-size=100M
Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Alexey Muravyov
  • 581
  • 1
  • 4
  • 8
  • will `snap` command work if `snapd` service is deactivated? – Lorenz Keel Nov 26 '21 at 09:23
  • not sure. but if it can't, you should free some space manually e.g. you can remove one of snap package file with old version manually e.g. user have two chromium_1781.snap and chromium_1801.snap. just remove less version; and try to run snapd service; also you can clean you logs file to get free space by this command journalctl --vacuum-size=100M – Alexey Muravyov Nov 26 '21 at 11:15
  • in my opinion you should add your last comment in your answer. – Lorenz Keel Nov 26 '21 at 11:19
  • @AlexeyMuravyov You wrote `e.g. user have two chromium_1781.snap and chromium_1801.snap. just remove less version And try to run snapd service` . Can this removal be done with `rm` ? – SebMa Nov 26 '21 at 11:39
  • sure. use sudo rm for less version of snap package, but better remove application packages like chromium or watsapp or wine and not core and gnome. sure you don't need a lot of space to run daemo. Also you can remove some movies from you machine )) and resize snap partition if you use separate one for it – Alexey Muravyov Nov 26 '21 at 11:42
11

Run

sudo bash -c 'rm /var/lib/snapd/cache/*'

to clear the cache, that should give you some free space.

mook765
  • 14,911
  • 5
  • 35
  • 67
  • Just what I was looking for. Sad that I could not wait long enough until your answer came along. I unfortunately had to manually delete everything by doing `sudo apt purge snapd` – SebMa Nov 26 '21 at 11:53
  • 3
    I'm missing something basic here: that command silently doesn't remove any file, [I had to](https://askubuntu.com/a/1156686/349837) `sudo sh -c 'rm -rf /var/lib/snapd/cache/*'` – Pablo Bianchi Jun 30 '22 at 13:43
  • 1
    @PabloBianchi this is because these files are not visible for your user. The glob expansion is performed by the shell, so `sudo` has no effect on it. It first expands to the files visibles to you (= none), then delete them. Your solution works because the glob expansion is executed by a shell run with `sudo`. – bfontaine Dec 05 '22 at 16:20
  • @PabloBianchi Not you but I was missing something basic here. I corrected the command. The recursive flag is not necessary, this folder only contains files (the snaps). – mook765 Dec 05 '22 at 17:05