Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

  1. Blog
  2. Article

Igor Ljubuncic
on 26 March 2021


Snaps are several things, all at once. They are confined, standalone Linux applications that bundle all their necessary dependencies, which means they do not need to rely on the underlying system, and can run independently of it. Snaps are also packaged as compressed Squashfs filesystems, using the .snap extension. For most users, they are an abstraction to get software on their Linux distro, in a simple, straightforward manner. But you may wonder, what lurks inside?

Unpacking the squashFS filesystem

If you want to check the contents of a snap, you can. First, download it, then extract the snap using the unsquashfs tool on the command line. A large number of Linux distributions should have this utility installed, or available in the archives, and should support the compression methods used for snaps (xz and lzo).

snap download “snap name”
unsquashfs “snap name”

Without any other arguments provided, the snap (with the .snap extension) will be uncompressed into a folder named squashfs-root in the current working directory.

unsquashfs kblocks_79.snap
Parallel unsquashfs: Using 8 processors
563 inodes (697 blocks) to write

[=========================================|] 697/697 100%

created 500 files
created 166 directories
created 62 symlinks
created 0 devices
created 0 fifos

The contents of a snap

To allow applications to run independently of the underlying system, snaps create an isolated environment for the contained applications. For strictly confined snaps, the application will see the base snap as its root filesystem, and thus expect to see the traditional layout of folders inside its environment. Typically, the squashfs-root will contain different folders like /bin, /lib, /usr, and others.

drwxr-xr-x  9 igor igor 4096 Mar  9 14:49 ./
drwxrwxrwx 11 igor igor 4096 Mar 23 12:21 ../
drwxr-xr-x  5 igor igor 4096 Mar  9 14:48 etc/
drwxr-xr-x  2 igor igor 4096 Mar  9 14:48 kf5/
-rwxr-xr-x  1 igor igor 8428 Mar  9 14:43 kf5-launch*
-rwxr-xr-x  1 igor igor 3783 Mar  9 14:43 kf5-locale-gen*
-rwxr-xr-x  1 igor igor  191 Mar  9 14:43 kf5-portal-launch*
drwxr-xr-x  3 igor igor 4096 Mar  9 14:48 lib/
drwxr-xr-x  2 igor igor 4096 Mar  9 14:48 lib64/
drwxr-xr-x  3 igor igor 4096 Mar  9 14:49 meta/
drwxr-xr-x  3 igor igor 4096 Mar  9 14:49 snap/
drwxr-xr-x  5 igor igor 4096 Mar  9 14:48 usr

Some of the paths will be obvious and familiar. Some, including various files, will be different.

Application entry point

When developers package snaps, they need to declare the application name and command in the snapcraft.yaml file. For the most part, there is no strict requirement how these should be specified, and the developers can use any variation they like. The application command does not have to be identical to what it could look like using the traditional Linux packaging.

Furthermore, snapcraft also helps the developers create some of the necessary application runtime environment elements, including different variables and relative paths. You can inspect what this setup looks like by checking any script available inside the snap.

Meta

This folder contains various setup and declarative files that describe the snap’s behavior. It can include several components: snap.yaml file that contains the basic snap details, a list of plugs and slots, any daemons, and more; hooks that are triggered on specific events; GUI elements like icon files and desktop files for the snap.

Snap

The snap directory (if present) can contain the command-chain declaration, a list of commands that are run before the actual application(s) bundled inside the snap. This can help set up the environment that snaps need, without having to resort to convoluted use of wrapper scripts.

And more…

Your snap (or a snap) could have only a handful of folders, or a whole range of them, including custom paths and structure. The contents will differ from one application to another, but at the end of the day, there is no great mystery about what snaps are. Anyone can download, unpack and inspect any snap, and see exactly what they do. In many cases, you will have an exact trail of environment variables and commands that run. If you want to learn a bit more about what else to expect inside a snap, you may want to check the snap format documentation for other useful details.

Finally, if you want to experiment, you can try the handy snap try command – to make quick, live changes to snaps, and test modified behavior. This can be quite useful if you want to speed up your development. That’s all we had today. If you have any comments or suggestions, please join our forum for a discussion.

Photo by Michael Longmire on Unsplash.

Related posts


Holly Hall
15 January 2024

Managing software in complex network environments: the Snap Store Proxy

Internet of Things Article

As enterprises grapple with the evolving landscape of security threats, the need to safeguard internal networks from the broader internet is increasingly important. In environments with restricted internet access, it can be difficult to manage software updates in an easy, reliable way. When managing devices in the field, change management ...


Heather Ellsworth
27 June 2023

Improving snap maintenance with automation

Desktop Article

Co-written with Sergio Costas Rodríguez. As the number of snaps increases, the need for automation grows. Any automation to help us maintain a group of snaps is welcome and necessary for us to be able to scale. The solution detailed in this article has two main benefits: Any users of snaps that have adopted this ...


Igor Ljubuncic
16 June 2023

Snapcraft 8.0 and the respectable end of core18

Ubuntu Article

‘E’s not pinin’! ‘E’s passed on! This base is no more! He has ceased to be! ‘E’s expired and gone to meet ‘is maker! ‘E’s a stiff! Bereft of life, ‘e rests in peace! If you hadn’t nailed ‘im to the perch ‘e’d be pushing up the daisies! ‘Is software processes are now ‘istory! ‘E’s ...