Snappy Ubuntu Core for Em­bed­ded and IoT De­vices

Ubuntu Core is a min­i­mal­is­tic ver­sion of Ubuntu. It is light­weight and is de­signed for use with em­bed­ded sys­tems and IoT de­vices. Snaps are univer­sal Linux pack­ages, which are faster to in­stall, eas­ier to cre­ate, and safe to run and work on mul­ti­ple distr

OpenSource For You - - Open Gurus -

The big­gest chal­lenge in de­liv­er­ing Linux ap­pli­ca­tions is de­pen­dency res­o­lu­tion. As dis­tri­bu­tions up­date un­der­ly­ing li­braries fre­quently, it is not al­ways pos­si­ble to of­fer ap­pli­ca­tion bi­na­ries as off­line ar­chives. One can’t think of down­grad­ing an ap­pli­ca­tion if un­der­ly­ing pack­ages are up­graded, which are in turn re­quired by some more ap­pli­ca­tions. Also, it’s not pos­si­ble to keep mul­ti­ple ver­sions of the same li­brary in view of dif­fer­ent ap­pli­ca­tions. Ubuntu Core has a so­lu­tion for all this com­plex­ity, whereby a sin­gle de­vice can host mul­ti­ple iso­lated ap­pli­ca­tions with their own de­pen­den­cies.

Ubuntu ‘snaps’ are univer­sal pack­ages sup­ported on many Linux dis­tri­bu­tions and on var­i­ous de­vices. Any Linux ap­pli­ca­tion can be bun­dled as a snap, which can be eas­ily de­ployed across the dis­tri­bu­tions and across de­vices with iso­lated en­vi­ron­ments. This en­sures se­cure ex­e­cu­tion and bet­ter trans­ac­tional man­age­ment with flex­i­ble upgrad­able or downgrad­able sup­port.

Snaps are based on Ubuntu Core, which is a min­i­mal ren­di­tion of Ubuntu, specif­i­cally de­signed for em­bed­ded and IoT de­vices. The core im­age con­sists of the ker­nel, a min­i­mal set of driv­ers and a ba­sic file sys­tem in the form of a core snap with ba­sic func­tion­al­ity. You can’t up­date the core by adding pack­ages un­like other typ­i­cal Linux dis­tri­bu­tions. Each snap is bun­dled with its own de­pen­den­cies for the func­tion­al­ity not pro­vided by the core. It sup­ports trans­ac­tional up­dates of the snaps, which can be up­graded or down­graded eas­ily with­out af­fect­ing other snaps. Also, snaps can be re­motely up­graded.

The snap for­mat file sys­tem

When Ubuntu Core is in­stalled, the OS snap gets in­stalled ini­tially. This snap is packed with rootfs, pro­vid­ing ba­sic fea­tures like net­work ser­vices, stan­dard li­braries and dae­mon man­age­ment. It is the plat­form for sub­se­quent snaps of­fer­ing ap­pli­ca­tion logic. This en­ables univer­sal pack­ag­ing as all snaps run on the ba­sis of the OS snap pro­vided by the core, elim­i­nat­ing any de­pen­den­cies with the host en­vi­ron­ment.

Each snap comes with an iso­lated file sys­tem in squashfs for­mat, which gets mounted in a sub-di­rec­tory un­der /snap. For ex­am­ple, when foo snap is in­stalled, its file sys­tem is mounted un­der /snap/foo/xx, where xx rep­re­sents a re­vi­sion of the snap. There can be mul­ti­ple

re­vi­sions of file sys­tems un­der /snap/foo but /snap/ foo/cur­rent al­ways points to the de­sired ver­sion as per the re­cent upgrade or down­grade. Each user-ac­ces­si­ble ap­pli­ca­tion of the snap is linked un­der /snap/bin, with the <snap-name>.<app-name> con­ven­tion, e.g., /snap/ bin/foo.test for an ap­pli­ca­tion named test un­der the snap foo. The meta data of the snap is avail­able in the form of meta/snap.yaml un­der the mounted file sys­tem.

Use cases

As the un­der­ly­ing stack is read only and each snap has a self-con­tained file sys­tem, Ubuntu Core is the per­fect choice for in­dus­trial so­lu­tions for which se­cu­rity is a crit­i­cal con­cern. Here are some cases of Ubuntu Core powered so­lu­tions:

IoT gate­ways for in­dus­trial so­lu­tions, like the Dell Edge gate­way

De­viceHive IoT toolkit

Cloud based servers like Nex­tCloud

Dig­i­tal sig­nage

Ro­bots and drones

Some pop­u­lar snaps

Here are some pop­u­lar ap­pli­ca­tions avail­able from the snap store:

Atom, a text ed­i­tor

Nex­tCloud, a cloud based server for data stor­age VLC, a multi-me­dia player

Docker, a con­tainer man­ager

Cas­san­dra, a scal­able NoSQL data­base

Blender, a 3D cre­ation suite

Stel­lar­ium, a plan­e­tar­ium soft­ware

Rocket.Chat, a Web chat server

The Tele­gram desk­top client

Jenk­ins, a lead­ing au­to­ma­tion server for build­ing, test­ing and de­ploy­ments

OpenHAB, a home au­to­ma­tion mid­dle­ware soft­ware Mosquitto, a MQTT bro­ker

Clients for AWS, like Azure cloud so­lu­tions


Ubuntu Core comes with a snap man­ager, snapd, which is present by de­fault in Ubuntu Xe­nial (16.04 LTS) on­wards; for older ver­sions of Ubuntu and other dis­tri­bu­tions you can in­stall the snap man­ager as fol­lows:

apt-get in­stall snapd

If you are plan­ning to build cus­tom snaps, in­stall snapcraft also, as fol­lows:

apt-get in­stall snapcraft

Re­place apt-get with any other pack­age man­ager like yum, dnf, zyp­per, pac­man, poky, etc, for non-De­bian based dis­tri­bu­tions.

Ubuntu Core is avail­able for ded­i­cated in­stal­la­tion for var­i­ous em­bed­ded tar­gets like Rasp­berry Pi Mod­els 2 and 3, Com­pute Mod­ule 3, In­tel Joulie, Dragon Board, In­tel NUC kit, Sam­sung Ar­tik, etc. Also, Ubuntu Core can be in­stalled through KVM on any desk­top as a vir­tual ma­chine, for which you can down­load the core im­age for the AMD 64 ar­chi­tec­ture, ex­tract the ar­chive and run the fol­low­ing com­mand:

qemu-sytem-x86_64 -smp 2 -m 1500 -net­dev user, id=mynet0, host­fwd=tcp::8022-:22,host­fwd=tcp::8090-:80 -de­vice vir­tionet­pci,net­dev=mynet0 ­drive file=ubuntu­core­16­amd64. img,for­mat=raw

Now log in to the core us­ing ssh as fol­lows: ssh user­name@lo­cal­host -p 8022

Work­ing with snaps

Let’s try work­ing with snaps in CLI mode, as­sum­ing osfy as the snap’s name.

To search for avail­able snaps based on the osfy key­word, use the fol­low­ing com­mand:

snap find osfy

To in­stall a spe­cific snap from the store, use the com­mand given be­low:

snap in­stall osfy

Ob­serve the file hi­er­ar­chy in /snap/osfy/cur­rent. Run the ap­pli­ca­tion as­so­ci­ated with snap by us­ing

the fol­low­ing com­mand: osfy.test #from /snap/bin

For list­ing of in­stalled snaps, use the com­mand given be­low:

snap list

To check the in­for­ma­tion about a par­tic­u­lar in­stalled snap, use the fol­low­ing com­mand:

snap info osfy The fol­low­ing com­mand up­dates all in­stalled snaps: \sudo snap re­fresh

The fol­low­ing com­mand up­dates a par­tic­u­lar in­stalled snap:

sudo snap re­fresh osfy

To roll back a snap to a pre­vi­ous ver­sion, use the com­mand given be­low:

sudo snap re­vert osfy The next com­mand unin­stalls a spe­cific snap: sudo snap re­move osfy

The fol­low­ing com­mand re­moves sym­links of the apps in /snap/bin and stops the as­so­ci­ated ser­vices:

sudo snap dis­able osfy

To start the snap ser­vices and make sym­links for the apps avail­able in /snap/bin, use the fol­low­ing com­mand:

sudo snap en­able osfy

To list the en­vi­ron­ment vari­ables as­so­ci­ated with a snap, use the com­mand given be­low:

sudo snap run osfy.env

Clas­sic snap

Since the core is read-only and not meant for de­vel­op­ment pur­poses, you can in­stall ‘clas­sic snap’ to en­ter in clas­sic mode on de­vices de­ployed with solely Ubuntu Core. Nor­mal pack­age man­age­ment with apt-get is al­lowed in clas­sic mode. But avoid this clas­sic snap if se­cure de­ploy­ment is the prime con­cern. sudo snap in­stall --de­v­mode clas­sic sudo clas­sic

Now, in the prompt en­abled by clas­sic mode, you can try any de­vel­oper com­mands such as those shown be­low:

sudo apt-get up­date sudo apt-get in­stall vim gcc snapcraft


In­ter­faces al­low snaps to ex­change ser­vices with each other. A snap pro­vides the ser­vice in the form of slot and an­other snap can con­sume it in the form of plug. Some im­por­tant in­ter­faces are net­work, net­work-bind, cam­era, blue­tooth­con­trol, fire­wall­con­trol, log­ob­serve, etc. To list out all pos­si­ble in­ter­faces and con­sumer snaps plugged into each of them, use the fol­low­ing com­mand:

snap in­ter­faces

To list in­ter­faces plugged by a par­tic­u­lar snap, the fol­low­ing com­mand should be used:

snap in­ter­faces osfy

In the ab­sence of a plugs en­try in the apps sec­tion of the man­i­fest file, we need to con­nect the in­ter­faces man­u­ally. For ex­am­ple, if a foo snap is pro­vid­ing a bar in­ter­face slot and osfy snap wants to plug into it, run the fol­low­ing com­mand:

snap con­nect osfy:bar foo:bar

Build­ing cus­tom snaps

You can pack­age any Linux ap­pli­ca­tion as a snap. For this, cre­ate an empty di­rec­tory and run the fol­low­ing com­mand to cre­ate the ba­sic skele­ton of meta­data in the name of snapcraft.yaml:

snapcraft init

Now edit the parts, apps sec­tions of snapcraft.yaml as per the tu­to­rial in­snaps/your­first­snap. And, fi­nally, run the snapcraft com­mand to build the snap by re­triev­ing all re­quired sources, build­ing each part, and stag­ing and prim­ing the out­come of all parts in stage, prime direc­to­ries. Fi­nally, the con­tents of the prime sub-di­rec­tory will be bun­dled

Fig­ure 1: The snap ex­e­cu­tion en­vi­ron­ment

Fig­ure 2: Snap in­ter­faces

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.