Getting Started with Ubuntu Core and Snaps

Watch out! This tutorial is over 2 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.
Tutorial Difficulty Level    

Ubuntu Core is a transactional version of the Ubuntu Linux OS, made specifically for internet of things (IoT) devices and large container deployments. This OS powers many digital signs, robotics and gateways, and uses the same kernel, libraries and system software as the standard Ubuntu, but on a much smaller scale.

Ubuntu Core can be run as a VM, or on the following platforms:

  • Raspberry Pi 2 and 3;
  • Compute Module 3;
  • Qualcomm DragonBoard 410c;
  • Intel NUC;
  • Intel Joule;
  • Samsung Artik;
  • KVM;
  • Amazon Web Services (AWS);
  • Microsoft Azure; and
  • Google Cloud Platform.
Transactional operating systems divide work into complete, indivisible operations. Ubuntu Core works through the use of snap packages. Snaps are zip files that contain a containerized application and its dependencies, as well as instructions to run securely and communicate with other software. Snaps run on any Linux desktop, server or cloud device, isolated from the underlying OS for safe installation of an application.Snaps are read-only and immutable, which prevents any modification while installed on a system. Alongside the application and its dependencies, snaps contain two segregated, writable storage spaces, one of which is versioned and saves copies of any data upgrade, and the other stores large volumes of static data that doesn’t need reduplication.Because of Ubuntu Core’s use of snaps, its security profile for the applications in containers is heightened. Even the OS and kernel are delivered as snaps, so any snap can be updated without affecting, or relying upon, other installed snaps. Using Ubuntu Core for containerization is now more feasible with the update that makes Docker compatible with Raspberry Pi.Let’s install Ubuntu Core on a Raspberry Pi 3 and then move on to setting up our first snap.

First Steps

  1. Start by creating an Ubuntu SSO account
  2. Import an SSH Key into your Ubuntu SSO account on this page. Instructions to generate an SSH Key on your (Linux or Mac) machine can be found here. See here for Windows machines.

Hardware and software requirements

Installation instructions

  1. Copy the Ubuntu Core image on the SD card. We like Etcher for this. It just works.
  2. Attach the monitor and keyboard to the board.
  3. Insert the SD card you just images and plug the power adaptor into the board.

First boot

  1. The system will boot then become ready to configure
  2. The device will display the prompt “Press enter to configure”
  3. Press enter then select “Start” to begin configuring your network and an administrator account. Follow the instructions on the screen, you will be asked to configure your network and enter your Ubuntu SSO credentials
  4. At the end of the process, you will see your credentials to access your Ubuntu Core machine:
User login

Once setup is done, you can login with SSH into Ubuntu Core, from a machine on the same network, using the following command:

The user name is your Ubuntu SSO user name, it has been reminded to you at the end of the account configuration step.

First boot tips
  • During setup,console-conf will download the SSH key registered with your Store account and configure it so you can log into the device via ssh <Ubuntu SSO account name>@<device IP address> without a password.
  • There is no default ubuntu user on these images, but you can run sudo passwd <account name> to set a password in case you need a local console login.

Installing and running your first snap

The snapd daemon manages the snap environment on the local system. Its installation will include the snap tool for interacting with snaps. You can check both are installed by attempting to run snap version on the command line:

If snapd is not present for some reason, simply install it

Here is how you can now find any “hello world” kind of snaps in the store:

snap find <search terms> will query the store and list the results with their version number, developer names and description.

Install and execution

As you can see, a number of developers uploaded snaps related to “hello world”. Let’s just install one of them.

To run the command, simply type hello in the command line (which is a command provided by the hello snap):
This is obviously just a simple example, what it has in common with all other snaps though, is that it runs fully confined and can only access its own data. A more advanced example would be running a kiosk-style device or use your imagination and design your own IOT device! Here are some ideas.