Base snaps

A base snap is a special kind of snap that provides a run-time environment with a cardinal 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.

Supported base snaps

There are currently six supported bases:

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

In most Ubuntu bases (except core), snapd and its associated tools are provided by their relevant snaps.

Warning:

core16 should no longer be used. With no current stable release, its beta and candidate releases are classed as experimental, and packages previously using it should be moved to a more recent base.

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 core20, use the following:

base: core20

To specify core22, use the following

base: core22

Deprecated base snaps

The latest releases of Snapcraft do not support older bases. Prior major Snapcraft releases are still supported and can be installed from Snapcraft’s tracks.

core18

To build core18 snaps, install snapcraft 7 from the 7.x track:

$ snap install snapcraft --channel 7.x

core

To build core snaps, install snapcraft 4 from the 4.x track:

$ snap install snapcraft --channel 4.x

For snaps using core, we highly recommend reading Snapcraft and Extended Security Maintenance for essential support details.

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:

Compatibility mode and ESM Support

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

This compatibility mode is no longer supported starting in Snapcraft 5.0. Snapcraft 4 can be installed from the 4.x track on the Snap Store (snap install snapcraft --channel 4.x). See Snapcraft and Extended Security Maintenance for essential support details.

Choosing a base

core22 is the currently recommended base for the majority of snaps. 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 and which plugins or extensions a base supports. If there are specific dependencies that cannot be easily met with core22 then core20 is a valid and supported alternative.

Snapcraft extensions are a great way to easily bundle a set of common requirements into a snap, such as for running KDE Plasma or GNOME applications, but you need to select a base that’s supported by the extension you require. See Supported extensions for a list of which extensions support which bases.

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 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 snapcraft 7 and newer, a build-base keyword can be used to explicitly define the base to use for the build environment where the base has not yet been bootstrapped.

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

name: futurecore
type: base
build-base: core24
# 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

While there is considerable discussion about using a base of “core”, this page clearly says:

“Building a snap with core is no longer supported in Snapcraft 5.0.”

But in downloading snaps to examine their YAML files, I did:

$ snap download tree

as a simple example, and its snapcraft.yaml file contains the line:

base: core

So I’m confused. BTW, this is all on the daily build of 22.04.

Thanks for commenting on this. core was the default base before core18 and core20 were developed. As a result, many snaps were originally built using core and may still be using it. The tree snap is a good example as it hasn’t been updated since 2019.

core is based on Ubuntu 16.04 LTS which is now supported only via Extended Support Maintenance (see Snapcraft and Extended Security Maintenance). Consequently, core was dropped from the main development branch of Snapcraft as Snapcraft’s architecture and plugin system changed.

Snapcraft 4.x remains compatible with core and will be updated and maintained on its own track for the duration of the the ESM period of Ubuntu 16.04 LTS.

I’ve attempted to update the document to make this clearer.

" core20, built from the latest LTS release … cannot currently be used with Snapcraft extensions …"

Really? I’m pretty sure they can. Is this claim out of date?

Yep. You’re right. I’ve updated this to link to our Supported extensions page. Thanks!

This paragraph might need a bit of an update, minimally to remove the terminology ‘both’ before listing 3 core versions, but possibly also to de-emphasise core16 since its use has been discouraged for several years.

Perhaps something like:

The first paragraph under “Choosing a base” still recommends core18, but under “Supported base snaps” it recommends core20.

The joys of updating documentation for new releases :slight_smile: