Base snaps

A base snap is a special kind of snap that provides a run-time environment with a minimal set of libraries that are common to most applications. They’re transparent to users, but they need to be considered, and specified, when building a snap.

There are currently four supported bases:

core16 is currently under development. With no current stable release, its beta and candidate releases are classed as experimental. As with core18 (and distinct from core), it’s built without bundling snapd and its associated tools. In both core16 and core18, these are are instead provided by their associated snaps.

:information_source: Older releases of core were occasionally referred to as core 16, but core and core16 are now two distinct packages.

Defining a base

Bases are defined by adding the base: keyword to a snap’s snapcraft.yaml followed by the base name.

For example, to specify core 18, use the following:

base: core18

To specify core, use the following

base: core

The base snap mounts itself as the root filesystem within your snap such that when your application runs, the base’s library paths are searched directly after the paths for your specific snap.

:warning: When building your snap with no specified base, Snapcraft will operate in compatibility mode. This is essentially a prior (2.43-era) version of Snapcraft, and will lose the functionality of newer releases. See Features incompatible with bases for details.

Choosing a base

core18 is the recommended base for the majority of snaps. It’s synonymous with the latest Long Term Support release of Ubuntu, Ubuntu 18.04 LTS, and it’s what the snapcraft init command includes when generating a new project’s template snapcraft.yaml.

But much like choosing a distribution base for a project or server, the best base for an application is dependent on an application’s requirements. If there are specific dependencies that cannot be easily met with core18 then core is a valid and supported alternative.

Base support was added with the release of Snapcraft 3. As noted above, snaps created before this, and snaps not using the base: keyword, can still be built but they cannot use specific new features. Instead, snaps built without bases inherit attributes from their respective build environments.

Snaps that don’t use bases can often migrate to one without too much difficulty. See Upgrading snapcraft for more details on potential differences.

Building a base snap

While it is possible to build your own base snap, its publisher needs to take responsibility for its maintenance and updates. In particular:

  • bases need to be built from stable packages
  • ABI compatibility cannot broken (ie. never replace symbols or libraries, and be strict)
  • security updates must be pro-active

Base snaps can be either bootable or non-bootable. The former needs to include systemd while the latter can be leaner.

build-base

The base keyword on its own does not not take into account the creation of bases. Instead, with older versions of snapcraft, the name keyword was arbitrarily used to determine the build environment:

name: core18
type: base
# base: is not set elsewhere 

The above example uses name to specify the creation of an Ubuntu 18.04 (core18) based build environment.

But the above fails if a base has yet to be bootstrapped, or is otherwise unavailable. For example, the following will currently generate a `launch failed: Unable to find an image matching “futurecore” error:

name: futurecore
type: base
# base: is not set elsewhere 

In cases like the above, where the base has not yet been bootstrapped, the build-base keyword should be used to explicitly define the base to use for the build environment.

To solve the above issue, for example, use the following:

name: futurecore
type: base
build-base: core18
# base: is not set elsewhere 
1 Like

Should this be 2.43-era ?

1 Like

thanks! I’ll update the version in the doc.

While this statement may once have been true:

core16 is a thing, and it’s very much not the same as core (as per How to use core16 as base snap? et cetera)

Perhaps some language like:

and later

would help here?

Thanks for flagging this. I’ve attempted to update the text to make this important distinction clearer.

1 Like

This is great, but could you include some suggestions on choosing a base please? For example suppose these are true:

  • I have a snap that doesn’t currently specify a base and feel like I should add one. Should I choose core, core16, or core18? What difference will it make to my users, and are there any points I need to consider - presumably setting core18 means that the packages in the background change compared to the current snap.

  • I am writing a new snap, what base should I use? What situation might I use core instead of core18?

It feels like the answer is probably “use core18 unless you have reason not to”, but it’s not clear, and effectively changing the OS underneath my application feels like a big update.

1 Like

Thanks for your suggestions. I’ve added a new section on Choosing a base to try and broadly answer what must be a common question, though we can probably do a better job of explaining where core, core16 and core18 (and shortly, core20) fit into the snap ecosystem. I’ll come back to it.

1 Like

Have just build the core20 snap from https://github.com/snapcore/core20.

Then i found a packer, to build a multipass image. https://discourse.ubuntu.com/t/building-multipass-images-with-packer/12361

Now i searching the source, to build the core20 image for multipass…

Could we add a snippet here that explains that if a snap does not declare a base it will use core as it’s base implicitly?

Yep, of course. I’ll add this - thanks!

1 Like

To build a snap based on core20 before Ubuntu 20.04 is released, you can build with snapcraft --destructive-mode inside a daily build of Ubuntu 20.04. For example with lxd you would run:

lxc launch ubuntu-daily:20.04 -c focal
lxc shell focal 
$ snapcraft --destructive-mode # builds your `base: core20` snap

@degville even at the time this doc was written, despite snapcraft error messages, core20 was already bootstrapped and available from stable channel and used by launchpad for staging core20 builds of gadgets / kernels etc.

In the spiriti of making the document timeless, I have changed the examples to attempt to build a “futurecore” whilst using an existing core18 as a build-base.

1 Like

Focal based multipass images already exist, in the daily stream, not release stream.

I don’t know however, how to make multipass / snapcraft use daily stream of focal images.

  1. I have patched snapcraft like this:
    https://github.com/sd-hd/snapcraft/commit/6a928fc5341c75566f30d716d4c3060ff73d5eed#diff-4e5027ec49fe1b99fc6f5674421fb832
  2. Then i build core20 snap from here: https://github.com/snapcore/core20
  3. Put the core20 into my snap directory
  4. Set base to core20 and build-base to core18 like here: https://github.com/sd-hd/termite-snap/blob/master/snap/snapcraft.yaml

Then the build with lxd works. https://github.com/sd-hd/termite-snap/actions/runs/39837558/workflow

But not sure, if there is something more to be done, if you use multipass