How to use a base image?

Hi everyone!

First of all, I understand that the main point of snaps is to simplify package management by making them relocatable and less dependent of the root filesystem. But since snapcraft allows to choose the base image (base snaps), what are the downsides of it? Why not do this for every second package? It seems to be the simplest way to migrate from an apt package.

Am I missing something?

Well, security comes to my mind, but let’s assume we are ok with classic snaps.

Or if you have a base image, you should manually do something like chroot if you want to use it?

All snaps have a base image. If you don’t specify one, they’ll use core. It includes what we think is a bare minimum needed for a workable system (and some base images are bootable, and can be used to create a snap-only device).

Actually, my question is: how base images are used (I changed the title now)? Let’s say I am no interested in snaps confinement.

Suppose I made a base image in fedora with

dnf install my packages --installroot my-dir

This created something like a root filesystem in that directory.
Now, as I understand, unless you chroot into it, you cannot use it. Am I wrong?

try it! Make that base, and install it locally, and then make a snap that uses it.

There are a lot of little things that need to be “just right” in a base snap, and the process is not yet documented as it’s still evolving somewhat, but it’s doable. snapcraft won’t be helping you much (beyond snapcraft pack), for the base. Maybe look at core's (or bare's) meta/snap.yaml for ideas.

yes, you’re wrong. Or perhaps I’m misunderstanding what you mean. What would you chroot to, and from where, to what purpose?

I’ll turn this around: look at the busybox-static snap. It uses the bare base snap. Now, bare is only available on the edge channel—because again this is still being worked on—so it won’t get pulled in automatically, but you can install it by hand (snap install --edge bare) and then install the snap that uses it (snap install --edge busybox-static). So, do that, and look at what you have in /snap/bare/current/: that is the minimum stuff you need to have for a base to work (some of it shouldn’t be needed, but for now it is), and compare it with the default base, /snap/core/current/, and a snap that uses it (for example, test-snapd-tools). Then, look at /snap/busybox-static/current/. And try snap run --shell busybox-static; also try snap run --shell

Good luck!

1 Like
cannot snap-exec: cannot exec "/bin/bash": no such file or directory

Thank you very much, I’m starting to look into it

The base key of snapcraft.yaml and it’s possible values are not documented:

Yes, documentation of bases is not ready yet. Neither is the feature.

snapcraft does not yet support the base key directly; you can pass it into the snap.yaml using the passthrouogh feature, as I described above. However if you need snapcraft to build the snap for you, you’ll need to hold its hand if you’re using a different base as otherwise it will do entirely the wrong thing.

As for “possible values”, you can use the name of any snap that is type: base. There’s only one supported base, today, the (default or implicit) core base. I know of a few other bases that are in different stages of development, at least two of which I can mention without ruining anybody’s surprise: bare and core18.