snap 格式 Ubuntu 应用包

发布时间: 更新时间: 总字数:1275 阅读时间:3m 作者: IP属地: 分享 复制网址

.snap包是Ubuntu 16.04 LTS发布时引入的新应用格式包,当前主流的Linux发行版均支持snap格式的包。本文介绍snap包的相关使用。

介绍

snap 包的优势:

  • 安全,snap 安装时在根目录下会出现如 /dev/loop0 的挂载点,这就是 snap 软件包的目录
    • Snap 使用 squashFS 文件系统(一种开源的压缩,只读文件系统,基于GPL协议发行)
    • 一旦 snap 被安装后,其就有一个只读的文件系统和一个可写入的区域。应用自身的执行文件、库、依赖包都被放在这个只读目录,意味着该目录不能被随意篡改和写入
    • 每个snap默认都被严格限制(confined),即限制系统权限和资源访问。当然可通过授予权限策略来获得对系统资源的访问
    • snap 包支持通过 interface(接口) 定义来做资源交换

snap 商店

snap 商店是 snap 包的仓库,使用 snapcraft 发布,release 类型包括:

  • stable:稳定
  • candidate:候选
  • beta:测试
  • edge:边缘

本质

snap 包本质包含一个私有的 root 文件系统,里面包含了依赖的软件包

# snap 文件包
$ file /var/lib/snapd/snaps/go_10008.snap
/var/lib/snapd/snaps/go_10008.snap: Squashfs filesystem, little endian, version 1024.0, compressed, -8706422325634924544 bytes, 1043595264 inodes, blocksize: 512 bytes, created: Mon Jul 26 11:05:07 1982

# 借助 loop 设备只读方式挂载在 /snap/go/10008,卸载时,loop 占用会释放
$ mount -l | grep go
/var/lib/snapd/snaps/go_10008.snap on /snap/go/10008 type squashfs (ro,nodev,relatime,errors=continue,x-gdu.hide)

$ df -lh | grep go
/dev/loop8      106M  106M     0 100% /snap/go/10008

# 以 go 命令为例,执行 go 命令时,通过 /usr/bin/snap 转发到 /snap/go/10008/bin/go
$ which go
/snap/bin/go

$ ls -lhart /snap/bin/go
lrwxrwxrwx 1 root root 13 Jan 11 15:01 /snap/bin/go -> /usr/bin/snap

$ file /usr/bin/snap
/usr/bin/snap: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=246e9f196e72a715fe7e9f2e2bc859ed9f33234c, for GNU/Linux 3.2.0, stripped

$ ls /snap/go/10008/bin/
go  gofmt

使用

  • 安装 snapd
apt install snapd
  • 删除 snapd
apt purge snapd

help

snap-help
snap --help
The snap command lets you install, configure, refresh and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.

Usage: snap <command> [<options>...]

Commonly used commands can be classified as follows:

         Basics: find, info, install, remove, list
        ...more: refresh, revert, switch, disable, enable, create-cohort
        History: changes, tasks, abort, watch
        Daemons: services, start, stop, restart, logs
    Permissions: connections, interface, connect, disconnect
  Configuration: get, set, unset, wait
    App Aliases: alias, aliases, unalias, prefer
        Account: login, logout, whoami
      Snapshots: saved, save, check-snapshot, restore, forget
         Device: model, reboot, recovery
      ... Other: warnings, okay, known, ack, version
    Development: download, pack, run, try

For more information about a command, run 'snap help <command>'.
For a short summary of all commands, run 'snap help --all'.

$ snap help --all
The snap command lets you install, configure, refresh and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.

Usage: snap <command> [<options>...]

Commands can be classified as follows:

  Basics (basic snap management):
    find             Find packages to install
    info             Show detailed information about snaps
    install          Install snaps on the system
    remove           Remove snaps from the system
    list             List installed snaps

  ...more (slightly more advanced snap management):
    refresh          Refresh snaps in the system
    revert           Reverts the given snap to the previous state
    switch           Switches snap to a different channel
    disable          Disable a snap in the system
    enable           Enable a snap in the system
    create-cohort    Create cohort keys for a set of snaps

  History (manage system change transactions):
    changes          List system changes
    tasks            List a change's tasks
    abort            Abort a pending change
    watch            Watch a change in progress

  Daemons (manage services):
    services         Query the status of services
    start            Start services
    stop             Stop services
    restart          Restart services
    logs             Retrieve logs for services

  Permissions (manage permissions):
    connections      List interface connections
    interface        Show details of snap interfaces
    connect          Connect a plug to a slot
    disconnect       Disconnect a plug from a slot

  Configuration (system administration and configuration):
    get              Print configuration options
    set              Change configuration options
    unset            Remove configuration options
    wait             Wait for configuration

  App Aliases (manage aliases):
    alias            Set up a manual alias
    aliases          List aliases in the system
    unalias          Remove a manual alias, or the aliases for an entire snap
    prefer           Enable aliases from a snap, disabling any conflicting aliases

  Account (authentication to snapd and the snap store):
    login            Authenticate to snapd and the store
    logout           Log out of snapd and the store
    whoami           Show the email the user is logged in with

  Snapshots (archives of snap data):
    saved            List currently stored snapshots
    save             Save a snapshot of the current data
    check-snapshot   Check a snapshot
    restore          Restore a snapshot
    forget           Delete a snapshot
    export-snapshot  Export a snapshot
    import-snapshot  Import a snapshot

  Device (manage device):
    model            Get the active model for this device
    reboot           Reboot into selected system and mode
    recovery         List available recovery systems

  Warnings (manage warnings):
    warnings         List warnings
    okay             Acknowledge warnings

  Assertions (manage assertions):
    known            Show known assertions of the provided type
    ack              Add an assertion to the system

  Introspection (introspection and debugging of snapd):
    version          Show version details
    debug            Run debug commands

  Development (developer-oriented features):
    download         Download the given snap
    pack             Pack the given directory as a snap
    run              Run the given snap command
    try              Test an unpacked snap in the system
    prepare-image    Prepare a device image

For more information about a command, run 'snap help <command>'.

基础使用

安装

安装软件,可使用如下命令或图形界面的 Ubuntu software store 完成:

sudo snap install snap-store

卸载

sudo snap remove snap-store

搜索

snap find snap-store

查看 snap 信息

snap info snap-store

查看已安装的 snap

snap list

更新snap

//channel来指定通道版本
sudo snap refresh snap-store channel=latest/stable

Account

$ snap login
Personal information is handled as per our privacy notice at
https://www.ubuntu.com/legal/dataprivacy/snap-store

Email address: 8@xiexianbin.cn
Password of "8@xiexianbin.cn":
Login successful

扩展

Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数