Ubuntu Core介绍及其使用
Canonical公司于最近2016年4月发布了一个新的Ubuntu 16.04系统,并且这个系统是长期支持版(LongTerm Support - LTS).它一如既往地支持debian安装包,但同时它也支持最新的snap安装包.snap安装包是Canonical公司最新发布的一种安装包的格式,它甚至可以在其它的Linux发行版上安装.更多的信息可以在我们的官方开发者网站:https://developer.ubuntu.com/en/desktop/或http://snapcraft.io/查看. Canonical公司也于2016年11月3日发布了专为物联网(IoT)打造的Ubuntu Core 16操作系统.在今天的这篇文章,我们将重点介绍Ubuntu Core系统的一些特点及其具体使用.
1)什么是snap?
- 是一个基于squashFS文件系统的文件.它包含应用代码及包含有一个应用特有的叫做snap.yaml的metadata文件.它含有一个只读的文件系统.一旦安装,它会创建一个应用特有可以写的区域,任何其它的应用都不可以访问这个区域
- 它完全独立于系统.在snap包里,它包含了它可以运行的所有需要的库及runtime(比如python或Java等),并且它可以通过网路更新,同时也可以退回到上一个版本,而不影响系统的其它部分的运行
- 它是受限的.通过安全机制,它具有沙箱的属性,不可以随意访问外部资源,并和系统的其它部分进行隔离.它可以通过良好设计的安全策略和其它的snap进行交互.
Ubuntu Core系统的特点:
-最小的Ubuntu服务器image:由于有较小的内核,所有可以适用于更多的应用场景.应用通过简单的.snap包来提供.snap包不同于先前的debian及手机上的click包.
-事务性更新 (transactional updates):通过商城的channel自动更新.事务性更新提供一个更加可靠的系统.在Ubuntu Core中含有两个root filesystem:A及B(各含有一个系统image).当A启动后,它可以用来更新B.只有B更新完整后并且没有错误后才可以切换过来到B,否则永远处于A.反之依然,我们可以用同样的办法来更新A区.当然,我们在任何时候,也可以rollback,也即回到以前的启动.这样的做法可以保证我们的系统在任何的时候Ubuntu Core及应用的更新都是完整的.这对很多需要稳定工作的环境的系统来说非常重要,比如更新一个远在路口的webcam等.另外,更新应用或系统时只需要更新变化的部分(delta),这样传输的数据更少.
-更强的应用安全:Ubuntu Core具有业界领先的安全性.Ubuntu Core OS系统image只是可读的.任何应用不可以更改它.这样的好处是不至于由于某个应用的安装或升级从而导致系统image得到修改,进而导致有些已经安装的应用不能正常运行.每个应用都有自己的可以读写的空间,并且它们之间是不可以互相访问的.每个应用都运行于受限的沙箱之中.API的访问是由Apparmor及Seccomp来强制受限的.它提供严格的基于MAC(Mandatory-Access-Control)的隔离.传统的Linux应用可以访问任何一个目录,并读写它们之中的文件.这和Snappy系统是不同的.如果一个应用需要特别的库,可以使用snapcraft来安装相应的库到自己的应用的私有目录中.
大家如果想对Ubuntu Core有更多的了解,也可以参阅我的视频"Ubuntu Core 介绍(视频)".
2)16.04桌面支持
从上面的图中,我们可以看出来在16.04的桌面中支持两种格式的安装包:snap及debian.另外我们可以看出,snap包每个安装的应用都是自成一体:每个snap应用包含运行所需要的任何依赖(dependencies);同时我们可以看出每个snap应用都是互相隔离的(请注意OS也是一个snap).和debian包相比较,我们可以看出来每个debian应用的安装依赖于其它包的安装;debian应用之间可以不受限制地互相访问而造成安全问题;删除其中的一个debian应用或包可能导致其它的应用不可以正常运行.相比较而言,不同的snap应用可以安装同样一个软件的不同版本(比如一个安装python 2.7,另外一个应用安装python 3.3)而不造成任何的干扰.从理论上讲,一个snap应用可以安装到任何一个Linux的发行版上,因为它不依赖于操作系统及其发布版本.这对于应用的维护来说是非常好的.
目前在如下的Linux发行版上支持snap包的安装.大家如果有兴趣的话,可以试一下.大家甚至可以直接从源代码编译在它上面运行的snapd环境.
Canonical公司目前正在号召全社区把应用移植成为snap包,并最终把操作系统变为ubuntu core系统,从而打造最安全的操作系统及良好的应用维护.
对于一个All-snap Ubuntu core系统来说(如上面的右图所示),它可以分为两个逻辑部分:
- 只读的最基本的系统
- 这部分包括配置文件,标准目录,库,工具及核心的服务(比如network services, libc, systemd及其它).系统的这部分是只读的,里面的每个元素不可以被分别更新.这个被称之为"system-image".在一个系统中,这种image可以达到两个及以上.这些最基本的系统是一种root filesystem的形式出现的.在启动后它们之间可以互相roll back,也即如果一个系统启动有问题,可以自动切换到先前的或指定的系统image去.这个部分也是通过snap打包来实现的.
- 可写的snap应用及在其之上的架构(framework).它们利用上面的系统所提供的服务达成.
3)安装
$ sudo apt update
$ sudo apt install snapd
$ sudo apt install snapcraft build-essential
在这里,我们简单地介绍一下所使用的术语:
- snapd:它是一个帮我们管理snap安装,卸载及通过事务性更新(transactional update)的一个环境.同时也帮我对老的版本的snap进行垃圾回收(garbage collection).snapd位于我们Ubuntu Core系统的/usr/lib/snapd/snapd
- snapcraft:这是一个帮我们打包一个snap应用的工具.snapcraft.yaml是用来定义如何把一个应用打包为snap包的yaml文件格式.snapcraft工具利用它打包.
$ sudo snap install ss-qt
$ ss-qt
我们可以在我们的电脑的dash中直接运行我们所安装的应用:
liuxg@liuxg:~/snappy/desktop/rssreader$ snap list
Name Version Rev Developer Notes
hello-world 6.3 27 canonical -
hello-world-cli 0.1 x1 -
hello-xiaoguo 1.0 x2 -
rssreader-app 1.0 x2 -
snappy-debug 0.23 22 canonical -
telegram-sergiusens 0.9.50 x1 -
test-license 0.1 x1 -
ubuntu-calculator-app 2.1+snap3 5 ubuntucoredev -
ubuntu-core 16.04+20160531.11-56 122 canonical -
webcam-webui 1.0 x1 -
$ snap info core
name: core
summary: "snapd runtime environment"
publisher: canonical
description: |
The core runtime environment for snapd
type: core
tracking: stable
installed: 16-2 (1337) 78MB -
refreshed: 2017-02-25 06:41:22 +0800 CST
channels:
stable: 16-2 (1337) 78MB -
candidate: 16-2 (1393) 79MB -
beta: 16-2 (1393) 79MB -
edge: 16-2 (1421) 82MB -
$ snap install hello --channel-beta
$ snap install <snap_name> --beta
或:
$ snap refresh hello --channel=beta
Name Version Rev Developer Notes
hello 2.10.1 29 canonical -
hello (beta) installed
https://code.launchpad.net/~dpm/ubuntu-calendar-app/snap-all-things
细心的开发者也许会发现,这个应用实际上是使用了同样一个和Ubuntu手机一样的代码.没有做任何的改变.从某种意义上讲,Ubuntu实现了真正意义上的融合(Convergence)应用设计.在为了,我们只需要一个应用的snap包,它就可以直接运行于不同屏幕尺寸上,并自动适配屏幕尺寸从而得到最佳的显示效果.比如在我们的另外一个教程中"如何把一个qmake的Ubuntu手机应用打包为一个snap应用",它展示了如何把一个手机的应用转换为一个可以在桌面系统运行的snap应用.
$ snap refresh <snap name>
我们也可以通过如下的命令来rollback到以前的版本(从snapd 2.11版本开始支持)
$ snap revert <snap name>
$ snap find ss-qt
$ snap find shadowsocks
liu-xiao-guo@localhost:~$ snap find
Name Version Developer Notes Summary
docker 1.11.2-9 canonical - The docker app deployment mechanism
lxd 2.6.2 canonical - LXD - the container lighervisor
liu-xiao-guo@localhost:~$ snap find --section=internet-of-things
Name Version Developer Notes Summary
openhab 2.0.0.b4-5-offline canonical - openhab 2.0 smart home server, offline versions
nextcloud 10.0.2snap1 nextcloud - Nextcloud Server
liuxg@liuxg:~$ sudo snap install oxide-digitalsignage --devmode --channel=beta
error: cannot install "oxide-digitalsignage": snap "oxide-digitalsignage" has changes in progress
通常如果我们中断一个正在安装的应用时,会出现上面的情况.那么我们怎么来处理这个问题呢?
liuxg@liuxg:~$ snap changes
ID Status Spawn Ready Summary
219 Done 2016-12-08T05:43:09Z 2016-12-08T05:43:09Z Refresh all snaps in the system
220 Done 2016-12-08T13:06:21Z 2016-12-08T13:06:23Z Remove "livevideo" snap
221 Done 2016-12-08T13:06:32Z 2016-12-08T13:06:32Z Refresh all snaps in the system
222 Done 2016-12-08T13:06:36Z 2016-12-08T13:06:38Z Install "livevideo" snap from file "livevideo_0.1_amd64.snap"
223 Done 2016-12-08T13:06:54Z 2016-12-08T13:06:57Z Remove "livevideo" snap
224 Done 2016-12-08T22:54:32Z 2016-12-08T22:54:32Z Refresh all snaps in the system
225 Done 2016-12-08T23:58:11Z 2016-12-08T23:58:28Z Install "snaplint" snap
226 Doing 2016-12-09T00:54:06Z - Install "oxide-digitalsignage" snap from "beta" channel
我们可以通过snap changes命令来查看目前正在进行的操作,然后,我们利用如下的命令来放弃我们当前的操作:
liuxg@liuxg:~$ snap abort 226
error: access denied (try with sudo)
liuxg@liuxg:~$ sudo snap abort 226
4)删除一个snap应用
liuxg@liuxg:~$ snap list
Name Version Rev Developer Notes
hello-world 6.1 26 canonical -
rssreader 1.0 x1 devmode
rssreader-app 1.0 x2 -
snaptest 1 x1 devmode
snaptest-app 1 x3 devmode
ubuntu-calculator-app 2.1+snap3 5 ubuntucoredev -
ubuntu-core 16.04+20160531.11-56 122 canonical -
webcam-webui 1 x1 -
liuxg@liuxg:~$ sudo snap remove ubuntu-calculator-app
[sudo] password for liuxg: Done
liuxg@liuxg:~$ snap list
Name Version Rev Developer Notes
hello-world 6.1 26 canonical -
rssreader 1.0 x1 devmode
rssreader-app 1.0 x2 -
snaptest 1 x1 devmode
snaptest-app 1 x3 devmode
ubuntu-core 16.04+20160531.11-56 122 canonical -
webcam-webui 1 x1
显然我们再也找不到ubuntu-calculator-app应用了.
5)在哪里找到安装的文件
liuxg@liuxg:~$ snap list
Name Version Rev Developer Notes
hello-world 6.1 26 canonical -
rssreader 1.0 x1 devmode
rssreader-app 1.0 x2 -
snaptest 1 x1 devmode
snaptest-app 1 x3 devmode
ubuntu-calculator-app 2.1+snap3 5 ubuntucoredev -
ubuntu-core 16.04+20160531.11-56 122 canonical -
webcam-webui 1 x1 -
对于一些开发者来说,snap的一些命令可能比较陌生.我们可以通过如下的方法来得到帮助:
$ snap --help # Or use 'snap <command> --help' for help on a specific command
安装好我们的应用后,我们可以在如下的路径找到我们的snap安装文件:
liuxg@liuxg:/var/lib/snapd/snaps$ ls
hello-world_26.snap rssreader_x1.snap snaptest-app_x3.snap ubuntu-core_122.snap
rssreader-app_x1.snap snaptest-app_x1.snap snaptest_x1.snap webcam-webui_x1.snap
rssreader-app_x2.snap snaptest-app_x2.snap ubuntu-calculator-app_5.snap
我们可以通过如下的方法查看系统中的mount的情况:
liuxg@liuxg:~$ mount | grep calculator
/var/lib/snapd/snaps/ubuntu-calculator-app_5.snap on /snap/ubuntu-calculator-app/5 type squashfs (ro,relatime)
在我们删除一个snap应用时,实际上就只要删除在系统的这个.snap文件即可.从上面我们可以看出来,实际上我们是把/var/lib/snapd/snaps/ubuntu-calculator-app_5.snap文件通过mount的方法使之可以在/snap/ubuntu-calculator-app/5目录中可以看见.一般来说,一个snap应用在被成功安装后,它位于/snap/$name/$version/目录中.
liuxg@liuxg:/snap/ubuntu-calculator-app/5$ tree -L 2
.
├── bin
│ └── calculator
├── build
│ └── ubuntu-calculator-app
├── command-calculator.wrapper
├── etc
│ ├── apparmor.d
│ ├── dbus-1
│ ├── default
│ ├── drirc
│ ├── fonts
│ ├── gps.conf
│ ├── gss
│ ├── init
│ ├── init.d
│ ├── ldap
│ ├── pki
│ ├── pulse
│ ├── ucf.conf
│ ├── X11
│ └── xdg
├── lib
│ ├── systemd
│ └── x86_64-linux-gnu
├── meta
│ ├── gui
│ └── snap.yaml
├── usr
│ ├── bin
│ ├── lib
│ └── share
└── var└── lib
细心的读者也许已经发现,在被mount的目录中的文件就像另外一个Linux的安装文件结构.它实际上是把这个calculator所需要的所有需要的文件安装到同样的一个根目录中,从而摆脱对系统文件的任何需求.理论上讲,我们的应用不会因为系统的升级或版本的变化而造成不能运行的情况.这对于一些软件开发商来说无疑是一个天大的利好!我们今天设计好的软件,在Ubuntu升级为未来的20.4时或其它版本时,我们不需要做任何的修改.这样做有一个非常大的好处就是我们应用的设计完全摆脱了对发行版本的依赖.当然,我们也可以把我们的应用部署到其它的任何一个支持snap包安装的Linux发行版上,它也可以运行得非常好.我们不需要考虑它到底运行的是什么版本的Linux系统及什么版本的发行.
liuxg@liuxg:/snap/bin$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
-rw-r--r-- 1 liuxg liuxg 122M 7月 12 12:00 ubuntu-calculator-app_2.1+snap3_amd64.snap
从上面可以看出来,我们的snap包的大小达到122M.如果我们想查看我们所在包里面的内容,我们可以通过如下的命令来实现:
$ unsquashfs -l ubuntu-calculator-app_2.1+snap3_amd64.snap | less
squashfs-root
squashfs-root/bin
squashfs-root/bin/calculator
squashfs-root/command-calculator.wrapper
squashfs-root/etc
squashfs-root/etc/X11
squashfs-root/etc/X11/Xreset
squashfs-root/etc/X11/Xreset.d
squashfs-root/etc/X11/Xreset.d/README
squashfs-root/etc/X11/Xresources
squashfs-root/etc/X11/Xresources/x11-common
squashfs-root/etc/X11/Xsession
squashfs-root/etc/X11/Xsession.d
squashfs-root/etc/X11/Xsession.d/20x11-common_process-args
squashfs-root/etc/X11/Xsession.d/30x11-common_xresources
squashfs-root/etc/X11/Xsession.d/35x11-common_xhost-local
squashfs-root/etc/X11/Xsession.d/40x11-common_xsessionrc
squashfs-root/etc/X11/Xsession.d/50x11-common_determine-startup
squashfs-root/etc/X11/Xsession.d/60x11-common_localhost
squashfs-root/etc/X11/Xsession.d/60x11-common_xdg_path
...
$ unsquashfs ubuntu-calculator-app_2.1+snap3_amd64.snap
$ cd squashfs-root
# Hack hack hack and go back to the previous dir
$ snapcraft snap squashfs-root
375M ./ubuntu-calculator-app/
也就是说一个应用安装后的空间大小是350M大小.当然这也依赖于我们所安装的应用类型.针对我们的ubuntu-calculator-app来说,我们在包里把我们所需要的Qt库及其它需要的任何东西都打入到包里面了.对于其它的任何python应用来说,也是同样的,我们可以把python版本所需要的任何库都打入到我们的包里面.我们根本不需要担心它会不会对其它的应用造成任何的影响.
$ snap download <snap-name>
再通过上面的方法来进行hacking.当然在我们使用时,还是需要尊重开发者的原创.
6)发布我们的应用到商店
$ snapcraft login
我们首先通过上面的命令登陆,让后使用如下的命令上传应用:
$ snapcraft register
$ snapcraft upload
最后我们通过如下的命令退出:
$ snapcraft logout
liuxg@liuxg:/snap/my-alias/current$ snapcraft login
Enter your Ubuntu One SSO credentials.
Email: xiaoguo.liu@canonical.com
Password:
Second-factor auth: 063065Login successful.
liuxg@liuxg:/snap/my-alias/current$ snapcraft list-registered
Name Since Visibility Price Notes
chrome-browser 2016-11-07T23:58:12Z public - -
my-chrome 2016-11-07T23:47:36Z public - -
mychrome 2016-11-08T00:14:14Z public - -
piglow-music 2016-12-15T08:24:12Z public - -
ss-qt 2016-11-02T05:56:55Z public - -
ssocks 2016-11-22T02:49:50Z public - -
v-top 2016-12-20T03:03:32Z public - -
7)受限的snap应用
当一个snap应用被安装后,在运行时,它被置于一个受限的安全的沙箱之中,并且每个应用都是互相隔离的.在默认的情况下,每个snap包中的每个应用都可以互相访问对方,并协同工作.但是,如果它访问其它的不在自己包里的应用或其它资源,它将是受限的.
$ sudo snap install hello-world
$ hello-world.env | grep SNAP
liuxg@liuxg:~$ hello-world.env | grep SNAP
SNAP_USER_COMMON=/home/liuxg/snap/hello-world/common
SNAP_LIBRARY_PATH=/var/lib/snapd/lib/gl:
SNAP_COMMON=/var/snap/hello-world/common
SNAP_USER_DATA=/home/liuxg/snap/hello-world/27
SNAP_DATA=/var/snap/hello-world/27
SNAP_REVISION=27
SNAP_NAME=hello-world
SNAP_ARCH=amd64
SNAP_VERSION=6.3
SNAP=/snap/hello-world/27
$ sudo snap connect webcam-webui:camera ubuntu-core:camera
liuxg@liuxg:~$ snap interfaces
Slot Plug
:camera -
:cups-control -
:firewall-control -
:gsettings -
:home rssreader-app,snaptest-app
:locale-control -
:log-observe -
:modem-manager -
:mount-observe -
:network -
:network-bind webcam-webui
:network-control -
:network-manager -
:network-observe -
:opengl rssreader-app,snaptest-app,ubuntu-calculator-app
:optical-drive -
:ppp -
:pulseaudio -
:snapd-control -
:system-observe -
:timeserver-control -
:timezone-control -
:unity7 rssreader-app,snaptest-app,ubuntu-calculator-app
:x11 -
上面显示了在我的电脑系统中每个snap应用所定义的plug.在上面的左边显示的所有的slot其实是OS snap (ubuntu-core)的尽管显示的很简捷.右边显示的是每个应用所定义的plug.
name: foo
apps:bar:command: bin/barplugs: [ home, unity7 ]
在这里,home及unity7和ubuntu core直接的连接是自动完成的.我们可以在文档Snaps interfaces看到所有的interface及它们是否可以自动连接.有了这样的plugs的定以后,这样我们的snap应用就可以访问到$HOME目录了.否则我们就可能在/var/log/syslog文件中发现denied错误信息.更多关于安全的介绍可以参阅文章"Snap security policy and sandboxing".
$ sudo snap install <package.snap> --devmode
就像上面指出的那样,这是一种在developer mode下的开发.它可以让开发者在起始开发应用时放开安全问题(不受限制)大胆开发.在发布应用时,我们再进行安全的调试.更多这方面的介绍,我们可以参阅文章"Learn to make a snap"或文章"helloworld Snap例程".
/var/snap/<name>/current/ ← $SNAP_DATA is the versioned snap data directory
/var/snap/<name>/common/ ← $SNAP_COMMON will not be versioned on upgrades
$ snap interfaces <snap> to find the slots offered and plugs used by the specified snap.
$ snap interfaces <snap>:<slot or plug> for details of only the specified slot or plug.
$ snap interfaces -i=<interface> [<snap>] to get a filtered list of plugs and/or slots.
liuxg@liuxg:~$ snap interfaces telegram-sergiusens
Slot Plug
:home telegram-sergiusens
:network telegram-sergiusens
:network-bind telegram-sergiusens
:unity7 telegram-sergiusens
8)如何得到snap帮助
liuxg@liuxg:~$ snap --help
Usage:snap [OPTIONS] <command>The snap tool interacts with the snapd daemon to control the snappy software platform.Application Options:--version print the version and exitHelp Options:-h, --help Show this help messageAvailable commands:abort Abort a pending changeack Adds an assertion to the systemchange List a change's taskschanges List system changesconnect Connects a plug to a slotcreate-user Creates a local system userdisconnect Disconnects a plug from a slotfind Finds packages to installhelp Helpinstall Install a snap to the systeminterfaces Lists interfaces in the systemknown Shows known assertions of the provided typelist List installed snapslogin Authenticates on snapd and the storelogout Log out of the storerefresh Refresh a snap in the systemremove Remove a snap from the systemrun Run the given snap commandtry Try an unpacked snap in the system
针对每个snap下面的命令,我们可以通过如下的方式来得它的帮助信息:
liuxg@liuxg:~$ snap install -h
Usage:snap [OPTIONS] install [install-OPTIONS] <snap>The install command installs the named snap in the system.Application Options:--version print the version and exitHelp Options:-h, --help Show this help message[install command options]--channel= Use this channel instead of stable--edge Install from the edge channel--beta Install from the beta channel--candidate Install from the candidate channel--stable Install from the stable channel--devmode Install the snap with non-enforcing security
通过上面的方法,我们可以对snap命令有更深的理解.
9)如编译一个snap应用
- 安装snapcraft.请参阅文章的开始部分
- 在项目的根目录下,直接键入"snapcraft"即可.在项目的根目录下通常含有snapcraft.yaml文件或.snapcraft.yaml文件.
$ git clone https://github.com/ubuntu/snappy-playpen.git
$ cd snappy-playpen
目前已经有如下的项目可以供我们参考:
atom/ idea/ openttd/ tinyproxy/
cloudfoundry-cli/ imagemagick-edge/ plank/ tyrant-unleashed-optimizer/
consul/ imagemagick-stable/ qcomicbook/ ubuntu-clock-app/
dcos-cli/ keepassx/ qdriverstation/ ubuntukylin-icon-theme/
deis-workflow-cli/ kpcli/ ristretto/ vault/
dosbox/ leafpad/ scummvm/ vlc/
ffmpeg/ minetest/ shotwell/ wallpaperdownloader/
galculator/ moon-buggy/ smplayer/ youtube-dl/
gitter-im/ mpv/ snap-template/
heroku/ openjdk-demo/ snaptest/
$ snapcraft
当项目被成功编译完后,我们可以直接在项目的根目录下找到一个扩展名为.snap的文件.这就是我们所需要的snap安装文件.我们可以参照我们上面讲述的方法来安装这个应用.
$ snapcraft clean
更多关于snapcraft的知识可以参阅它的帮助:
liuxg@liuxg:~$ snapcraft --help
snapcraftUsage:...The available commands are:help Obtain help for a certain plugin or topicinit Initialize a snapcraft project.list-plugins List the available plugins that handle different types of part.login Authenticate session against Ubuntu One SSO.logout Clear session credentials.register Register the package name in the store.tour Setup the snapcraft examples tour in the specified directory,or ./snapcraft-tour/.upload Upload a snap to the Ubuntu Store.The available lifecycle commands are:clean Remove content - cleans downloads, builds or install artifacts.cleanbuild Create a snap using a clean environment managed by lxd.pull Download or retrieve artifacts defined for a part.build Build artifacts defined for a part. Build systems capable ofrunning parallel build jobs will do so unless"--no-parallel-build" is specified.stage Stage the part's built artifacts into the common staging area.prime Final copy and preparation for the snap.snap Create a snap.Parts ecosystem commandsupdate Updates the parts listing from the cloud.define Shows the definition for the cloud part.search Searches the remotes part cache for matching parts.Calling snapcraft without a COMMAND will default to 'snap'
在snapcraft打包的过程中,它经历如下的几个阶段:
pull Download or retrieve artifacts defined for a part.build Build artifacts defined for a part. Build systems capable ofrunning parallel build jobs will do so unless"--no-parallel-build" is specified.stage Stage the part's built artifacts into the common staging area.prime Final copy and preparation for the snap.snap Create a snap.
我们可以通过snapcraft来对每个阶段分别处理来查看每一步到底做什么.比如"snapcraft pull"等.打包的顺序是按照上面所列举的顺序执行的.更多关于如何打包的过程请参阅连接http://snapcraft.io/create/.
10)如何运行一个snap应用
snapcraft.yaml
name: snaptest-app
version: 1
summary: This is a summary
description: This is the description
confinement: devmodeapps:test:command: desktop-launch $SNAP/lib/x86_64-linux-gnu/bin/snaptestplugs: [home,unity7,opengl]parts:application:source: ./srcplugin: qmakeqt-version: qt5build-packages:- cmake- gettext- intltool- ubuntu-touch-sounds- suru-icon-theme- qml-module-qttest- qml-module-qtsysteminfo- qml-module-qt-labs-settings- qtdeclarative5-u1db1.0- qtdeclarative5-qtmultimedia-plugin- qtdeclarative5-qtpositioning-plugin- qtdeclarative5-ubuntu-content1- qt5-default- qtbase5-dev- qtdeclarative5-dev- qtdeclarative5-dev-tools- qtdeclarative5-folderlistmodel-plugin- qtdeclarative5-ubuntu-ui-toolkit-plugin- xvfbstage-packages:- ubuntu-sdk-libs- qtubuntu-desktop- qml-module-qtsysteminfostage:- -usr/share/pkgconfig/xkeyboard-config.pc snap:- -usr/share/doc- -usr/includeafter: [desktop/qt5]
$ snaptest-app.test
也就是说,我们可以通过<<package-name>>.<<application-name>>来启动我们的应用.如果大家想对snapcraft有更多的了解,请参阅我们录制的视频"Snapcraft操作演示--教你如何snap一个应用"
hello-world:
$ cat meta/snap.yaml
name: hello-world
version: 6.1
architectures: [ all ]
summary: "The 'hello-world' of snaps"
description: |This is a simple snap example that includes a few interesting binariesto demonstrate snaps and their confinement.* hello-world.env - dump the env of commands run inside app sandbox* hello-world.evil - show how snappy sandboxes binaries* hello-world.sh - enter interactive shell that runs in app sandbox* hello-world - simply output text
apps:env:command: bin/envevil:command: bin/evilsh:command: bin/shhello-world:command: bin/echo
从上面我们可以看出来,包名和应用的名称都是hello-world,那么我们可以直接使用hello-world来运行这个应用.对于其它的应用来说,我们必须使用诸如hhello-world.env来运行.
11)如何让我们的系统恢复到没有snap安装的起始状态
git clone https://github.com/zyga/devtools/
让后运行如下下载的命令:
$ sudo ./reset-state
我们按照命令所指出的提示进行操作.这样我们就可以把我之前所有已经安装过的snap应用及环境都删除.我们的系统恢复到原来没有安装过任何snap的状态!
12)如何启动或取消一个已经安装的snap
liuxg@liuxg:~$ snap list
Name Version Rev Developer Notes
hello-xiaoguo 1.0 x1 -
ubuntu-core 16.04.1 423 canonical -
webcamhtml 0.1 x1 devmode
liuxg@liuxg:~$ sudo snap disable hello-xiaoguo
hello-xiaoguo disabled
liuxg@liuxg:~$ snap list
Name Version Rev Developer Notes
hello-xiaoguo 1.0 x1 disabled
ubuntu-core 16.04.1 423 canonical -
webcamhtml 0.1 x1 devmode
liuxg@liuxg:~$ hello-xiaoguo.env
hello-xiaoguo.env: command not found
liuxg@liuxg:~$ sudo snap enable hello-xiaoguo
hello-xiaoguo enabled
liuxg@liuxg:~$ snap list
Name Version Rev Developer Notes
hello-xiaoguo 1.0 x1 -
ubuntu-core 16.04.1 423 canonical -
webcamhtml 0.1 x1 devmode
liuxg@liuxg:~$ hello-xiaoguo.env
runtime/cgo: LC_PAPER=zh_CN.UTF-8
这里,我们可以看到我们可以通过snap disable/enable的方法来把我们的snap进行启动或取消的动作.
13)Ubuntu Core snap应用到底和Docker有什么区别
14) 在哪里可以下载Ubuntu Core Image
15)如何开发一个snap应用
- helloworld Snap例程
- WebCam snap应用实例
16)更多的学习资源
$ sudo apt update
$ sudo apt install snapd snapcraft snapcraft-examples
当然我们也可以直接把snapcraft源码下载下来:
$ git clone https://github.com/snapcore/snapcraft
$ git clone https://github.com/ubuntu/snappy-playpen
$ snapcraft tour
Snapcraft tour initialized in ./snapcraft-tour/
Instructions are in the README, or http://snapcraft.io/create/#tour
$ sudo apt install snapcraft-examples
$ sudo snap install snap-codelabs
http://localhost:8123/
我们可以利用这些资源来参考学习所有已经有的应用.
- https://github.com/snapcore/snapcraft/tree/master/docs
- https://github.com/snapcore/snapd/tree/master/docs
- https://developer.ubuntu.com/en/desktop/
- https://developer.ubuntu.com/en/snappy/
- http://snapcraft.io/
- https://developer.ubuntu.com/en/desktop/examples/#snap-qt
- http://askubuntu.com/
- http://docs.ubuntu.com/core/en/
- http://www.ubuntu.com/snappy
- https://tutorials.ubuntu.com/
Ubuntu Core介绍及其使用相关推荐
- 到底snappy ubuntu core是什么?
我不知到大家有没有听过snappy ubuntu core.反正我第一次听到Snappy时,不是很理解.如果我们查查字典,它的意思是爽快的,敏捷的,精力充沛的.听起来非常不错哦!对了Snappy就是C ...
- 微软azure云在Ubuntu Core中的应用
在今天的教程中,我们来展示如何在Ubuntu Core中使用azure的IoT hub来开发我们的应用.Azure IoT Hub目前提供了一个框架对我们的IoT设备进行管理,并可以通过预置解决方案来 ...
- Ubuntu Core 18 发布:提供 10 年安全更新;美劳工部指控甲骨文薪酬歧视
(给技术最前线加星标,每天看技术热点) 转自:开源中国.solidot.cnBeta.腾讯科技.快科技等 [技术资讯] 0.嵌入式系统 Ubuntu Core 18 发布:提供 10 年安全更新 Ca ...
- [导入]ubuntu全面介绍 与 ubuntu截图
ubuntu全面介绍 与 ubuntu截图 详情进入 甘先生 2006-05-10 17:33 文章来源:http://www.blogjava.net/gump/archive/2006/05/10 ...
- Ubuntu版本介绍
转自Ubuntu版本介绍 经常有人问起Ubuntu的版本选择问题,论坛中虽有帖子提及,但不是很详细,不集中,我就尝试把Ubuntu上的这点东东翻译一下,供大家参考,水平有限,敬请包涵.指正. Ubu ...
- Ubuntu Core 给物联网提供更多安全支持
开发四年只会写业务代码,分布式高并发都不会还做程序员? Canonical 是 Ubuntu 的一个桌面环境,该公司目前在云服务业务赚到了钱.因为 Ubuntu Core 为嵌入式设备带来了 Ub ...
- ASP.NET Core 介绍
原文:Introduction to ASP.NET Core 作者:Daniel Roth.Rick Anderson.Shaun Luttin 翻译:江振宇(Kerry Jiang) 校对:许登洋 ...
- Ubuntu Core for Raspberry Pi 使用笔记
Ubuntu Core for Raspberry Pi 使用笔记 snap install classic --edge --devmode Snapping DBus https://apache ...
- Interview with Dustin Kirkland, Ubuntu Core Developer about encryption in Ubuntu
Ubuntu老大对eCryptfs的访问, 有很多有意思的问题. Dustin Kirkland is an Ubuntu Core Developer, working for Canonical ...
- Ubuntu Core 将支持物联网 Matter
导读 Canonical 近日宣布,它已经加入了 Connectivity Standards Alliance (CSA 连接标准联盟,原 Zigbee 联盟),他们将为物联网制定新的安全和可靠性标 ...
最新文章
- cookie 和 session 机制
- ios中常用数据类型相互转换
- Linux下不同服务器间数据传输
- 6.3 优化-机器学习笔记-斯坦福吴恩达教授
- 通过实例理解Spring的Bean工厂和AOP框架
- C++中STL和容器、迭代器、算法之间的关系
- cmd 调用JLink.exe 下载程序
- Qt中标绘功能的实现方法对比
- 灵活强大的MySQL代理中间件ProxySQL应用实战(2)
- hive load data外部表报错_从0开始学大数据-Hive基础篇
- IDEA快捷键整理(最详细的)
- Effective C++读书笔记05
- 区块链专家洪蜀宁:实现全民普惠的专业化产品设计 | 11月24日【区块链技术与实践】论坛...
- 实战:解密拼多多玩法—砍价
- 华为彩信显示尚未激活服务器,华为手机无法接收彩信提示要开通gprs
- 如何才能高效的学习,99%的人不知道的高效学习法
- 如何根据vin码查询_vin查配置 车辆VIN码查询车辆基本配置信息 知道车辆vin码怎么查配置...
- python操作微信自动发消息(微信聊天机器人)
- 【转】使用matlab软件打开一幅图片并且分别提取其中的RGB分量并显示
- qmail邮件系统(五)vpopmail和qmailadmin对用户的管理