0

Like many other users have experienced, snaps can quickly take up a lot of space. On one of my systems it was filling up the (small) root/home drive, so I thought I'd symlink the storage folder to another drive with more space. The symlinking is straightforward enough. With snapd disabled and installed snaps unmounted, I moved /var/lib/snapd/snaps and /var/lib/snapd/cache to the other drive, and replaced the directories with symlinks to their new locations. So far so good, and snaps were being mounted from their new image location. I am also able to run through most of the install process, and mount new snaps from the store. However when I try to run anything, or when the install process tries to run install hooks, I get the following error:

cannot snap-exec: cannot find installed snap "firefox" at revision 5701: missing file /var/lib/snapd/snaps/firefox_5701.snap

The file /var/lib/snapd/snaps/firefox_5701.snap is not in fact missing, it exists just fine in its symlinked folder, and can be listed and read with the same permissions as the original non-symlinked image.

When I try to install a new package, snapd will save and mount the image just fine, and then fail when trying to run install hooks with errors saying that it cannot change mount namespace according to change mount (/var/lib/snapd/hostfs/[...] /[...] none bind,ro 0 0): cannot write to "/var/lib/snapd/hostfs/[...]" because it would affect the host in "/var/lib/snapd". So it looks like the symlinked drive does not exist in the mount namespace snap uses.

How can I symlink (or otherwise move) snap packages to another drive?

JanKanis
  • 683

1 Answers1

0

Googling some more I found the answer. The problem is not with namespaces, but apparmour profiles block access to the symlinked drive. If you instead use bind mounts it works. Do make sure that the cache and snaps folders in /var/lib/snapd/ are not separated by a bind mount, because snapd tries to hard link across those folders. The most straightforward solution is to just bind-mount the entire /var/lib/snapd folder to the other drive.

See Move snap packages to another location/directory for more details.

JanKanis
  • 683