Cleaning up storage allocated by lxd and multipass snaps

Hello folks,

I have an older laptop where the root partition is separate from /home, and isn’t very large in total size. Recently I installed snapcraft 3, lxd and multipass snaps (replacing older apt-installed snapcraft 2 and lxd), and tried new builds of a snap I’m responsible for which generates fairly large build artefacts (not included in the final snap).

The result is that the containerized storage generated by lxd and multipass has now taken up a substantial chunk of the root partition. Freeing this seems non-trivial: for example lxc storage delete default won’t work because it’s in use by the default profile, and the default profile itself cannot be deleted.

Can anyone advise how to effectively clean up all the images allocated by lxd and multipass? I’m fine with uninstalling everything, removing all images, and starting from scratch, but I would also be fine with finding some way to remove files from inside the images if that would shrink them.

Thanks & best wishes,

  -- Joe

You can remove the LXD snap with the purge option and will take away the storage.
If for some reaaon you would rather keep the installation, you can create a new storage device that is based on 'dir`, then rename it to default and remove the old one.

If you are already using the dir storage, then you can remove all you can find in lxc list and lzc image list, and disk space will to go zero.

With multipass, you remove all VMs, then multipass purge to expunge them.


We intend to improve snapcraft to help with this case… but here is a script to help in case you have a large number of instances:

#!/bin/bash -x

# Remove snapcraft-created multipass VMs
for vm in $(multipass list | awk '{print $1}' | grep ^snapcraft-); do
	multipass delete $vm --purge

# Remove snapcraft-created LXD containers
for c in $(lxc list | awk '{print $2}'  | grep ^snapcraft- | grep -v snapcraft-dev); do
	lxc delete $c --force

These will delete any VMs/containers with names that start with “snapcraft-”.

When you do use snapcraft, you can run snapcraft clean in your project directory to clean up the instance once you are done with it.

1 Like