8

I have Ubuntu installed. I have a partitioned disk with a root / partition of 20 GB and a /home partition of 60 GB. I thought that this would be enough for Ubuntu, but snap is using a lot of storage space.

6,9 GiB [###       ] /snap                                                                                                                                                                                                                                          
5,8 GiB [###       ] /usr
3,9 GiB [##        ] /var
2,3 GiB [#         ] /opt

This is the /snap folder:

1,7 GiB   [##########] /gnome-3-34-1804                                                                                    
1,2 GiB   [#######   ] /gnome-3-28-1804
868,0 MiB [#####     ] /kde-frameworks-5-core18
721,7 MiB [####      ] /postman
653,2 MiB [###       ] /gtk-common-themes
594,0 MiB [###       ] /core
393,8 MiB [##        ] /core20
337,6 MiB [#         ] /core18
293,4 MiB [#         ] /snap-store
238,8 MiB [#         ] /snapd
39,6 MiB  [          ] /canonical-livepatch
4,0 KiB   [          ] /bin
4,0 KiB   [          ]  README

I'm not using KDE and it seems like it's an old version of GNOME. Can I just remove that?

Do you have any other ideas for making some space?

Harm
  • 81
  • 1
    Yeah, 20GB for / will almost certainly turn out to be insufficient. As to Snaps, yes, you are impacted by their biggest weakness. When you install packages with apt-get, all the dependencies of the software (the additional stuffs it needs for operating) will get shared among other apps installed with apt-get, meaning, you need only one of every such additional dependency (its version smartly negotiated). Snaps, on the other hand, don't share with other apps: each snap has their own collection of dependencies: multiple apps meaning multiple copies. That's inefficient on storage space. – Levente Apr 30 '21 at 23:52
  • 20 GB for root is quite OK if you have a separate home partition, and if you do not keep too much old kernel versions around. You can remove the snap packages that are not needed if you need the space, or you can remove snap altogether if you do not want to use it and take any space. – vanadium May 01 '21 at 10:56
  • Yeah, I can just remove the snap directory but I would like to keep using gnome. I'm afraid that Ill end up with a broken system if I remove that folder. Do you not think so? – Harm May 02 '21 at 16:50
  • @vanadium, I disagree. It's my understanding that Gnome Desktop is provided as a snap by default, and then 20 GB is not enough IMO. – Artur Meinild Mar 11 '22 at 13:51
  • What tool are you using to get the #-bars? – Thorbjørn Ravn Andersen May 16 '23 at 09:16

2 Answers2

10

Do you have any other ideas for making some space?

Below there is a script (it is an extract from a personal script that I use to perform a general "spring cleaning" of the root partition) that reduces the overall size of snaps working in three directions:

  1. reduce the maximum numbers of revisions stored in your system (line snap set system refresh.retain=2 of the script)
  2. clean the oldest revisions when you have snap revisions that exceed the maximum number defined in the previous point (while loop in the script)
  3. Clean the snap cache directory (rm /var/lib/snapd/cache/* command in the script)
#!/bin/bash

Error status variables

STATUS_OK=0 STATUS_ERROR=1

Color settings

YELLOW_COLOR="\033[1;33m" RED_COLOR="\033[0;31m" OFF_COLOR="\033[0m"

Set English language

LANG=en_US.UTF-8

Execute it as root user

if [ "${USER}" != root ]; then echo -e "${RED_COLOR}ERROR: must be root! Exiting...${OFF_COLOR}" exit "${STATUS_ERROR}" fi

Current status

USED_BEFORE="$(df -k / | awk 'NR>1 {print $3}')"

snapd revisions clean

if [ -n "$(command -v snap)" ]; then

shellcheck disable=SC2162

read -p "→ Do you want to remove unused snapd revisions? [Y/n] " KEY KEY="${KEY:0:1}" && KEY="${KEY,,}" if [ "${KEY}" = "y" ] || [ "${KEY}" = "" ]; then # remove unused snapd revisions echo "Removing unused snapd revisions..." snap set system refresh.retain=2 # shellcheck disable=SC2162 snap list --all | awk '/disabled/ {print $1, $3}' | while read SNAP_NAME SNAP_REV; do snap remove "${SNAP_NAME}" --revision="${SNAP_REV}"; done if [ -d /var/lib/snapd/cache ] && [ -n "$(ls -A /var/lib/snapd/cache)" ]; then rm /var/lib/snapd/cache/* fi echo "Nothing unused to uninstall" else echo "Task skipped" fi fi

Current status

USED_AFTER="$(df -k / | awk 'NR>1 {print $3}')"

Summary

echo -e "${YELLOW_COLOR}Freed up space: $(( (USED_BEFORE - USED_AFTER)/1024 )) MB${OFF_COLOR}" exit "${STATUS_OK}"

  • Save the above code in a file, for example snap-cleanup.sh
  • Put it in a folder defined in $PATH, for example $HOME/.local/bin
  • Make it executable by chmod +x $HOME/.local/bin/snap-cleanup.sh
  • Call it by sudo bash $HOME/.local/bin/snap-cleanup.sh

As a general consideration, size is a weakeness of the snap format, because shared libraries/dependencies are "duplicated" inside every snap. What you can do, if this is really a problem for you, consists in using the .deb version of an application (from apt install) instead of the snap version.

You can also remove completely snapd, but consider that for the GNOME variant of Ubuntu the number of packages distributed as snap is increasing, and for some of them the decision has been taken not by Canonical but by the package distributor itself (for instance, Mozilla for firefox). In the future the removal of snapd may not be harmless.

Lorenz Keel
  • 8,905
1

I reckon 20 GB is not enough for Ubuntu Desktop these days - this will leave you with very little space for applications.

Snaps take a lot of space, and Gnome Desktop as well as several other applications are included as a snap by default.

I wouldn't recommend anything less than 100 GB for a desktop installation just to be sure, unless you want to spend additional time tinkering and optimizing your disk space.

And for your additional questions: Yes, you should be able to remove gnome-3-28-1804 and kde-frameworks-5-core18 without any issue.

Artur Meinild
  • 26,018