Layouts modify the execution environment of a strictly-confined snap.
With layouts, you can make elements in
$SNAP_COMMON accessible from locations such as
/etc. This helps when using pre-compiled binaries and libraries that expect to find files and directories outside of locations referenced by
Layouts can only help within a snap’s environment. They cannot be used to expose elements within a snap to the host environment.
Layouts require snap version 2.36+.
As a simple example, consider an application you want to snap that:
A layout that allows such software to be used without snap-specific modifications can be defined as follows:
layout: /var/lib/foo: bind: $SNAP_DATA/var/lib/foo /usr/share/foo: bind: $SNAP/usr/share/foo /etc/foo.conf: bind-file: $SNAP_DATA/etc/foo.conf
None of the above filesystem modifications are visible to any other snaps, or from the wider user session. They’re only visible within the per-snap mount namespace.
The syntax for defining a layout is:
layout: <target-path>: <declaration> <target-path>: <declaration> ..
Layouts are defined as a key-value map, mapping from a
<target-path> to a layout declaration. Each declaration may be one of the following:
symlink: <source-path>: create a symbolic link. This method is preferred because it is the cheapest; the other methods significantly increase the startup time of your application.
bind: <source-path>: bind-mount a directory.
bind-file: <source-path>: bind-mount a file
type: tmpfs: mount a private temporary in-memory filesystem
<source-path> must refer to either
<target-path> can include nearly any path except for:
See below for further limitations.
<target-path> don’t already exist, they will be automatically created by snapd. This includes the creation of new empty files, but doesn’t include the creation of symbolic link targets. This is because snapd doesn’t know what kind of objects they may eventually point to. In the previous example,
$SNAP_DATA/etc/foo.conf is created before any snap application code is executed.
Layouts can create new directories and files even in read-only locations such as
/usr/share. The following declaration will create
/usr/share/foo, for example, visible only to executing snap applications (it’s assumed that
/usr/share/foo does not exist in the base snap declared by the application developer):
layout: /usr/share/foo: bind: $SNAP/usr/share/foo
To accomplish the above, snapd uses a temporary filesystem (tmpfs) mounted on
/usr/share and populated with a set of empty files and directories. These are then used for bind mounts as well as symlinks to reconstruct the original
/usr/share. This allows snapd to make
/usr/share writable, and consequently, allows snapd to create
/usr/share/foo and configure it as desired.
The following apply as of snapd 2.36:
This functionality only works with strictly-confined snaps, and does not work with snaps using classic confinement. This may change in the future.
Layouts cannot currently create new top-level files or directories. For example, the following layout declaration will not work:
layout: /foo: # Unsupported, cannot create new top-level directories. bind: $SNAP/foo
Layouts cannot replace an existing but incompatible filesystem object. This means, for example, that files cannot replace directories or symbolic links, files cannot replace a directory, and existing symbolic links cannot be redirected to a new target. You can, however, replace a directory with another directory.
Last updated 10 months ago. Help improve this document in the forum.