Mount another disk on `/var/snap`

The disk mounted in /var is too small, so I want to use another disk for /var/snap to avoid getting out of space. I imagine that the normal procedure to do this is:

cp -r /var/snap/* $NEW_SNAP_DIR
rm -fr /var/snap
ln -s $NEW_SNAP_DIR /var/snap 

The directory $NEW_SNAP_DIR resides in a big disk, so I have no danger of getting out of space.

However, I think that before doing this task I have to stop every snap related process. Is there a recommended way to do this? It seems there are several running processes that depends on directories under /var/snap. I don’t want to break them.

You can try this:

  • stop all snaps
  • discard their mount views:
for s in $(snap list | tail -n +2 | awk '{ print $1}' | sort -u); \
do \
  sudo /usr/lib/snapd/snap-discard-ns $s || true; \
done
  • create a mount unit named var-snap.mount:
[Unit]
Description=mount /var/snap from larger disk

[Mount]
What=/you/new/var/snap
Where=/var/snap
Options=bind

I have never created a mount unit (I didn’t even know they existed). I have always used fstab to automatically mount files. I read that mount units are defined in files ended by .mount and define automatic mounting points for systemd. Where I have to create the file var-snap.mount?

Two other questions (maybe too newbie).

  1. You say I can stop all snaps with snap-discard-ns. How can I restart these snaps after I created the mount unit?

  2. I imagine I have to copy all contents from /var/snap to /your/new/var/snap before creating the mount unit. Is this true?

stopping and the snap-discard-ns steps are two separate things … you just stop the snaps (i.e. any daemons you installed as snap) with snap stop <snap name> … then discard their namespace with the command and do your mount change … once you start them again (with the snap start ... command) they will automatically claim a namespace again … though i’d suggest to reboot anyway (which would do all the namespace cleaning and restarting of snaps), just for safety, to make sure everything is fine with the mount unit on a fresh boot.

Thank @mborzecki and @ogra. You help me a lot to solve my problem :slight_smile: