Snap mount directory migration on openSUSE

Hi all,

Some you may have noticed a post in the openSUSE Factory mailing list announcing our plan to submit snapd to openSUSE:Factory, which I sent a while ago:

https://lists.opensuse.org/archives/list/factory@lists.opensuse.org/thread/DNGZP4GVR7WMR4GJDQ7UAGVQUCCYQUHM/

As part of this effort we have decided to make /var/lib/snapd/snap the default location for installations on openSUSE going forward starting with 2.73 or 2.74 snapd release (the actual version is TBD). Our intention is not to break any existing installations and no automatic steps for migration will be taken. Users are welcome to either keep their current setups untouched, or use a migration script included in the snapd package to migrate the mount directory to a new location (read below).

With the recent changes that enable support for reexecution, snapd will automatically detect the snap mount directory at runtime. On either a new installation, or a migrated setup, one can run the following command to confirm the mount location like this:

$ snap debug paths
SNAPD_MOUNT=/var/lib/snapd/snap
SNAPD_BIN=/var/lib/snapd/snap/bin
SNAPD_LIBEXEC=/usr/libexec/snapd

Where SNAP_MOUNT will show either /var/lib/snapd/snap on migrated systems, or /snap on systems using the old mount location.

:warning: Note for openSUSE 15.x users

On openSUSE 15.x, SNAPD_LIBEXEC has value /usr/lib/snapd. OpenSUSE 16.x, Tumbleweed, Slowroll, all use /usr/libexec/snapd.

Manual migration

:warning: Due to the nature of operation, all snap applications and services to be stopped for the duration of the process.

Checks

The tool includes a command to perform checks whether the system migration can be executed. The same set of checks are performed by the migration command, but you can use the check command as a convenience to make sure that the system state is as expected.

Invoke the command like this:

sudo /usr/libexec/snapd/snap-mgmt --check-mount-dir-migration

When snap applications or services are detected the output will indicate that:

$ sudo /usr/libexec/snapd/snap-mgmt --check-mount-dir-migration
Checking snap mount directories presence...

Checking snap applications and services...
Found active snap services or applications in the following cgroups:
- /sys/fs/cgroup/user.slice/user-0.slice/user@0.service/app.slice/snap.hello.hello-1f3f450b-c7d7-47f0-87ee-198b4b203fa8.scope
  likely owned by snap: 'hello'
  PIDs: 26918
Found running snap services or applications.

Mount directory migration cannot continue.

Whereas a ‘ready’ state is indicated like the following:

$ sudo /usr/libexec/snapd/snap-mgmt --check-mount-dir-migration
Checking snap mount directories presence...

Checking snap applications and services...
System is ready for migration.

Migrate

The snapd package includes a tool for migration, which can be invoked in the following manner:

sudo /usr/libexec/snapd/snap-mgmt --migrate-mount-dir

Due to the nature of operation, the script expects all snap applications and services to be stopped.

System reboot is recommended after completing the migration. You can run snap debug paths command again to confirm that the new mount location has been detected. Additionally the output of snap list should not show any snaps with a note broken. For instance:

$ snap debug paths
SNAPD_MOUNT=/var/lib/snapd/snap
SNAPD_BIN=/var/lib/snapd/snap/bin
SNAPD_LIBEXEC=/usr/libexec/snapd
$ snap list
Name                     Version                 Rev    Tracking       Publisher   Notes
core                     16-2.61.4-20251009      17284  latest/edge    canonical✓  core
core24                   20250829                1196   latest/stable  canonical✓  base
snapd                    1337.2.72+g193.b6dc25e  x1     -              -           snapd
test-snapd-service       1.0                     x1     -              -           -
test-snapd-sh-core24     1.0                     x3     -              -           -
test-snapd-user-service  1.0                     x1     -              -           -

Post migration cleanup

The migration script keeps a copy of the old snap mount directory as /snap.old. Remove the directory after completing the migration and rebooting the system.