Score:1

Can Snaps be transferred from one installation to another?

fr flag

When you install a package on a Linux system, it creates and modifies a set of files on your system. Typically, it isn't possible to move all of those files from one system to another and end up with a functioning program. This is for a few reasons, but a big one is that the system libraries the program depends on will differ between the two versions of Ubuntu.

Since Snaps are more self-contained with their dependencies than programs installed as Apt packages, I'm curious to know what the obstacles are to moving a Snap from one version of Ubuntu to the next when upgrading and still have it work on the new system. Even if it's not possible, figuring out exactly why it's not possible should be as educational as figuring out how to do it.

As an exercise, I'm trying to move a Snap from one installation (Ubuntu 20.04) to another (Ubuntu 22.04). The Snap I'm using to experiment with is Authy, and it was originally installed in the normal way using snap install authy on the 20.04 system. So far, I've moved the following files and folders from the 20.04 to the 22.04 system:

  • ~/snap/authy/
  • /snap/authy/
  • /snap/bin/authy
  • /var/snap/authy/

as well as everything in /var/lib/snapd/ that has "authy" in its name:

  • /var/lib/snapd/snaps/authy_12.snap
  • /var/lib/snapd/snaps/authy_11.snap
  • /var/lib/snapd/inhibit/authy.lock
  • /var/lib/snapd/sequence/authy.json
  • /var/lib/snapd/seccomp/bpf/snap.authy.authy.src
  • /var/lib/snapd/seccomp/bpf/snap.authy.authy.bin
  • /var/lib/snapd/cookie/snap.authy
  • /var/lib/snapd/mount/snap.authy.user-fstab
  • /var/lib/snapd/mount/snap.authy.fstab
  • /var/lib/snapd/apparmor/profiles/snap-update-ns.authy
  • /var/lib/snapd/apparmor/profiles/snap.authy.authy
  • /var/lib/snapd/desktop/applications/authy_authy.desktop

When I moved ~/snap/authy/, I also changed all greppable uses of the 20.04 username to that of the 22.04 username. No files in anything else I moved contained a reference to system usernames.

Moving the authy_authy.desktop file caused the Authy program to appear in the system menu, as you might expect. The executable command associated with this launcher is

env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/authy_authy.desktop /snap/bin/authy %U

Selecting the program from the system menu does nothing. Trying it from the command line (remove the %U because it doesn't work and isn't needed) results in a boilerplate list of snap commands:

$ env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/authy_authy.desktop /snap/bin/authy
The snap command lets you install, configure, refresh and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.

Usage: snap <command> [<options>...]

Commonly used commands can be classified as follows:

         Basics: find, info, install, remove, list
        ...more: refresh, revert, switch, disable, enable, create-cohort
        History: changes, tasks, abort, watch
        Daemons: services, start, stop, restart, logs
    Permissions: connections, interface, connect, disconnect
  Configuration: get, set, unset, wait
    App Aliases: alias, aliases, unalias, prefer
        Account: login, logout, whoami
      Snapshots: saved, save, check-snapshot, restore, forget
         Device: model, reboot, recovery
      ... Other: warnings, okay, known, ack, version
    Development: download, pack, run, try

For more information about a command, run 'snap help <command>'.
For a short summary of all commands, run 'snap help --all'.

So no error message, but also no functioning Authy program.

That's all of the Authy-Snap-related files I can find to transfer. I'm posting to ask

  1. Is there something I missed that I should also try moving?
  2. Is there a concrete explanation of why something like this would never work?

Thanks in advance.

Update

A comment brought up systemd unit files, which I hadn't considered. I found these Authy unit files:

/etc/systemd/system/snap-authy-11.mount
/etc/systemd/system/snap-authy-12.mount

and corresponding enabled symlinks in

/etc/systemd/system/default.target.wants/
/etc/systemd/system/multi-user.target.wants/

I copied the two unit files between systems, enabled them ($ sudo systemctl enable snap-authy-12.mount), and reloaded systemd ($ sudo systemctl daemon-reload). This didn't change the issue; I still get the same boilerplate Snap info from trying to open Authy.

Anyway, I'm giving up on this to focus on other things. Everyone's welcome to post more ideas if the problem interests you, but only if you understand that this is about identifying and moving sets of files, not about running snap install on a local file.

user535733 avatar
cn flag
Does this answer your question? [How can I install a Snap package from a local file](https://askubuntu.com/questions/1266894/how-can-i-install-a-snap-package-from-a-local-file)
guiverc avatar
cn flag
I've not tried moving a whole *snap* from one system to another, but I have moved a browser config (*snap* web browser) from one machine to another (*which I bet contained different release but I can't recall*)
mook765 avatar
cn flag
Installing a snap will produce one or more systemd-services (needed to mount the snap) which need to be enabled. There is probably more than that. I'd simply install the snap on the newer system, why to make it difficult when you can have it easy... You can make snapshots of the user data of a snap to get them imported in the new system.
JonahHuron avatar
fr flag
@user535733 Not directly, and probably not at all. That answer concerns the use of `snap install` on a local, custom Snap. Without a detailed (that is, file-by-file) explanation of what `snap install` will do, I can't apply it to my case.
guiverc avatar
cn flag
You can download snaps, and then use `snap install` to install them on different boxes. Articles are written on doing this for those without good internet or bandwidth limited connections (inc. only part of the day). There have been a number of posts by various people (*inc. Alan Pope or popey, who combined many of his snap details in his posts into one soon after he left Canonical; the others I couldn't recall who wrote them so I'm using popey's as example only*) & possibly even some mention in official Ubuntu blogs (*less detailed as I recall*). I don't know about installed snaps though.
JonahHuron avatar
fr flag
To be clear to everyone, I'm not asking how to install a Snap from the `.snap` file. I know how to do that. I'm interested in moving an entire installation as-is between two systems, which I thought might be practical since I'd heard Snaps were supposed to be self-contained. It is not.
guiverc avatar
cn flag
The *snap* packages themselves are more contained than for example a *deb* package, but that's per-installation. I'm sure you could move an installed *snap* application (since we're not talking about packages now) just as you can installed *deb* applications, but the applications vary in complexity, and not all *snap* packages have the same confinement model, so I'd expect there to be variation (let alone some having *connections* to other snaps) Possible I believe yes, but I'd just transfer the uninstalled *snap* package & install that to ensure no errors.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.