Offline snap installation

Hi,

I’m trying to install lxd with snap on ubuntu 16.04 server.
As the server has no internet acces, I’ve download the .assert and .snap using ‘snap download lxd’.
This gives me a .snap and .assert file:
lxd_8011.assert
lxd_8011.snap

After copying to the server, I would like to install it with:

$ sudo snap ack lxd_8011.assert
$ sudo snap install lxd_8011.snap

The install fails with:

$ sudo snap ack lxd_8011.assert
$ sudo snap install lxd_8011.snap
-- ensure prerequisites for "lxd" are available (get https://api.snapcraft.io/api/vs/snaps/details/core?channel=stable&fields=anon_dowload_url%2Carchitecture%2Cchannel%2Cdownload_sha4_384%2Csummary%2Cdescription%2Cdeltas%2Cbinary_fileize%2Cdownload_url%2Cepoch%2Cicon_url%2Clast_updated%2Cpackage_name%2Cprices%2Cpublisher%2Cratings_average%2Crevision%2Cscreenshot_urls%2Csnap_id%2Clicense%2Cbase%2Csupport_url%2Ccontact%2Ctitle%2Ccontent%2Cversion%2Corigin%2Cdeveloper_id%2Cprivate%2Cconfinement%2Cchannel_maps_list : dial tcp: lookup api.snapcraft.io on [::1]:53: read udp [::1]:53788 -> [::1]:53 read: connection refused)

Indicating to me that the snap tries to connect to the internet to find prerequisites. I’ve searched snap documentation, but I feel this is snap-specific.

tl;dr: Offline install isn’t working. Has this been tested for LXD?

It worked for me. Below, I create a container with nesting support, then snap download LXD. Finally, I perform the installation.

$ lxc launch ubuntu:18.04 offline --config security.nesting=true
Creating offline
Starting offline

$ lxc ubuntu offline
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@offline:~$ sudo snap download lxd
Fetching snap "lxd"
Fetching assertions for "lxd"
Install the snap with:
   snap ack lxd_8011.assert
   snap install lxd_8011.snap
ubuntu@offline:~$ sudo snap ack lxd_8011.assert 
ubuntu@offline:~$ sudo snap install lxd_8011.snap
2018-08-01T12:46:12Z INFO Waiting for restart...
lxd 3.3 from 'canonical' installed
ubuntu@offline:~$ 

I see, thank you for your fast reply.
Does your container have internet acces?
Because manual installation succeeds if I have internet acces, but fails otherwise:

$ lxc launch ubuntu:16.04 offline
Creating offline
Starting offline

$lxc exec offline -- sudo --login --user ubuntu
ubuntu@offline:~$ sudo snap download lxd
Fetching snap "lxd"
Fetching assertions for "lxd"
Install the snap with:
    snap ack lxd_8011.assert
    snap install lxd_8011.snap
ubuntu@offline:~$ sudo ifdown eth0
ubuntu@offline:~$ sudo snap ack lxd_8011.assert
ubuntu@offline:~$ sudo snap install lxd_8011.snap
error: cannot perform the following tasks:
- Ensure prerequisites for "lxd" are available (Post https://api.snapcraft.io/v2/snaps/refresh: dial tcp: lookup api.snapcraft.io on [::1]:53: read udp [::1]:37859->[::1]:53: read: connection refused)
ubuntu@offline:~$ sudo ifup eth0
ubuntu@offline:~$ sudo snap install lxd_8011.snap
ubuntu@offline:~$ sudo snap download lxd
2018-08-01T14:07:42Z INFO Waiting for restart...
lxd 3.3 from 'canonical' installed

So with working network it’s fine, without it fails.

edit: I saved somewhere halfway through my post

Okay, I managed to reproduce what you get.

When you perform the snap install of the .snap package, it indeed tries to connect to api.snapcraft.io to perform a POST to https://api.snapcraft.io/v2/snaps/refresh.

This is a snap issue, and there are some discussions like https://forum.snapcraft.io/t/offline-snap-installers-and-possibility-to-update/275
I believe snap install performs a validity check on the downloaded .snap package.

It would be suitable to ask about this on https://forum.snapcraft.io/ and pick their brains.

Thank you, so it’s not my setup.

The snap install validity check should be fine because of the snap ack lxd*.assert. Other snaps do install offline, so I figured it might be the way the lxd snap is set up. I will check with the snapcraft forum, and if any answers come up I’ll post them here as well.

Does passing --dangerous and not using the assertion somehow work?

If there is no bug in snapd, I believe that snapd would try to figure out whether an offline snap package has been retracted, etc.

Otherwise, it could be a bug in snapd.

After removing the snap that was succesfully installed, it would reinstall offline. The ‘core’ snap was missing. (although i had manually installed the ubuntu-core snap, as suggested by snap documentation.)

Trying it now on a physical machine

edit: installing core first solves the problem:

$ sudo snap download core
$ sudo snap download lxd

and then on the offline device:

$ sudo snap ack /path/to/core\*assert
$ sudo snap install /path/to/core\*snap
$ sudo snap ack /path/to/lxd\*assert
$ sudo snap install /path/to/lxd\*snap

succesfully installs withouth network connection.

Note: the core snap is a prerequisite for every snap application.

Thanks for the help!

1 Like