Snap

出自 Arch Linux 中文维基

本文或本節需要翻譯。要貢獻翻譯,請訪問簡體中文翻譯團隊

附註: 請提供模板的第一個位置參數以更詳細的指示。(在 Talk:Snap# 中討論)

Snap 是一個軟體部署和包管理系統。這些包被稱為「Snap 軟體包」(「snaps」),可以通過「snapd」來管理「Snap 軟體包」。它適用於一系列 Linux 發行版,因此允許與發行版無關的上游軟體開發。Snap 的開發商 Canonical 管理 Snap Store 服務。用戶可以通過該服務安裝 Snap 軟體包。

snapd 是一個用於管理 Snap 軟體包的 REST API 守護進程。用戶可以通過使用 snap 客戶端與它進行交互,該客戶端是 snapd 包的一部分。

用戶可以使用 AppArmor 限制 Snap 軟體包。現在內核中默認啟用了該功能。請查閱相關維基頁面,了解在系統中啟用 AppArmor 的步驟。

警告:
  • 如果您的系統中未啟用AppArmor,則所有快照都將以 devel 模式運行,這意味著它們將與從Arch Linux存儲庫安裝的應用程式一樣,可以不受限制地訪問您的系統。
  • 運行不受信任的代碼永遠是不安全的,沙盒也無法改變這一點。

安裝[編輯 | 編輯原始碼]

安裝 snapdAUR 包組。

提示:snapd/etc/profile.d/snapd.sh 中安裝了一個腳本,記錄了snapd軟體包和桌面軟體的二進位安裝文件路徑。重啟後才會使改變生效。

如果你在你的系統中啟用了 AppArmor,snapd 是支持這種安全模型的,請根據 AppArmor#Installation 進行安裝。

如果你在使用 AppArmor,請確保啟用並打開了apparmor.servicesnapd.apparmor.service服務。

配置[編輯 | 編輯原始碼]

請啟用/開啟snapd.socket服務以使snapd守護線程正常運行,這樣才能正常使用snap

使用[編輯 | 編輯原始碼]

The snap tool is used to manage the snaps.

snap 工具被用來管理snaps。

查找軟體包[編輯 | 編輯原始碼]

用下面的命令可以在Ubuntu Store中查詢你想要安裝的snap軟體包:

$ snap find searchterm

安裝軟體包[編輯 | 編輯原始碼]

一但你找到想要安裝的snap了,用下面的命令去安裝它:

# snap install snapname

這將需要root權限。目前還不能為每個用戶安裝snap。為了使其可以被系統使用,snap會把下載的內容放到/var/lib/snapd/snaps目路並掛載到/var/lib/snapd/snap/snapname

It will also create mount units for each snap and add them to /etc/systemd/system/multi-user.target.wants/ as symlinks to make all snaps available when the system is booted. Once that is done you should find it in the list of installed snaps together with its version number, revision and developer using:

$ snap list

You can also sideload snaps from your local hard drive with:

# snap install --dangerous /path/to/snap

Updating[編輯 | 編輯原始碼]

To update your snaps manually use:

# snap refresh

Snaps are refreshed automatically according to snap refresh.timer setting.

To view the next/last refresh times use:

# snap refresh --time

To set a different refresh time, eg. twice a day:

# snap set core refresh.timer=0:00~24:00/2

See system options documentation page for details on customizing the refresh time.

移除軟體包[編輯 | 編輯原始碼]

Snaps can be removed by executing:

# snap remove snapname

提示與技巧[編輯 | 編輯原始碼]

Classic snaps[編輯 | 編輯原始碼]

Some snaps (e.g. Julia and Pycharm) use classic confinement. However, classic confinement requires the /snap directory, which is not FHS-compliant. The snapd package does not ship this directory, however the user can manually create a symbolic link between /var/lib/snapd/snap and /snap to allow the installation of classic snaps:

# ln -s /var/lib/snapd/snap /snap

Confinement[編輯 | 編輯原始碼]

When using AppArmor, snapd will generate the same profiles for snaps as on Ubuntu. The AppArmor parser is smart enough to drop the rules that are not yet supported by the mainline kernel.

To verify that basic confinement is working, install hello-world snap. Then run the following:

$ hello-world.evil
Hello Evil World!
This example demonstrates the app confinement
You should see a permission denied error next
/snap/hello-world/27/bin/evil: 9: /snap/hello-world/27/bin/evil: cannot create /var/tmp/myevil.txt: Permission denied

The denial was caused by AppArmor and should have been logged:

# dmesg
...
[  +0.000003] audit: type=1327 audit(1540469583.966:257): proctitle=2F62696E2F7368002F736E61702F68656C6C6F2D776F726C642F32372F62696E2F6576696C
[ +12.268939] audit: type=1400 audit(1540469596.236:258): apparmor="DENIED" operation="open" profile="snap.hello-world.evil" name="/var/tmp/myevil.txt" pid=10835 comm="evil" requested_mask="wc" denied_mask="wc" fsuid=1000 ouid=1000
[  +0.000006] audit: type=1300 audit(1540469596.236:258): arch=c000003e syscall=2 success=no exit=-13 a0=55d991ba6bc8 a1=241 a2=1b6 a3=55d991ba6be0 items=0 ppid=31349 pid=10835 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts2 ses=3 comm="evil" exe="/bin/dash" subj==snap.hello-world.evil (enforce)
...

If you do not see the denial, verify that the profiles were loaded:

# aa-status | grep snap.hello-world
   snap.hello-world.env
   snap.hello-world.evil
   snap.hello-world.hello-world
   snap.hello-world.sh

Also, you can check what sandbox features are available in the system according to snapd:

$ snap debug sandbox-features
apparmor:             kernel:caps kernel:domain kernel:file kernel:mount kernel:namespaces kernel:network_v8 kernel:policy kernel:ptrace kernel:query kernel:rlimit kernel:signal parser:unsafe policy:default support-level:partial
confinement-options:  devmode
dbus:                 mediated-bus-access
kmod:                 mediated-modprobe
mount:                freezer-cgroup-v1 layouts mount-namespace per-snap-persistency per-snap-profiles per-snap-updates per-snap-user-profiles stale-base-invalidation
seccomp:              bpf-argument-filtering kernel:allow kernel:errno kernel:kill_process kernel:kill_thread kernel:log kernel:trace kernel:trap

Hide the snap folder[編輯 | 編輯原始碼]

See XDG Base Directory#Hiding unwanted directories to hide the snap folder.

Sudo[編輯 | 編輯原始碼]

With secure_path being enabled in sudo by default, the /var/lib/snapd/snap/bin directory is no longer present in the default $PATH environment variable of the process started by sudo. Commands such as sudo lxc list will fail, as the lxc symbolic link can no longer be found by the shell process.

This can be addressed on per user basis by adding the following snippet to /etc/sudoers.d/90_snap:

# Add snap binaries installation dir to PATH
Defaults:<your-user-name> secure_path="/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/snapd/snap/bin"

Where <your-user-name> must be replaced with the desired $USER.

Troubleshooting[編輯 | 編輯原始碼]

Text unreadable[編輯 | 編輯原始碼]

If you are seeing squares instead of readable characters, you need to clear the font cache:

# rm -f /var/cache/fontconfig/*
$ rm -f ~/.cache/fontconfig/*
# fc-cache -r -v

Snapctl also stores internal caches for each individual snap, which need to be cleared seperately. First, find them by running:

$ find ~/snap/ -wholename '*/.cache/fontconfig'
... /home/darth_vader/snap/mailspring/common/.cache/fontconfig
... /home/darth_vader/snap/authy/common/.cache/fontconfig
... /home/darth_vader/snap/icedrive/common/.cache/fontconfig
... /home/darth_vader/snap/discord/common/.cache/fontconfig
... /home/darth_vader/snap/bitwarden/common/.cache/fontconfig

Then either remove them individually or use this simple loop.

Finally, Restart your session.

Error: cannot mount squashfs[編輯 | 編輯原始碼]

Snap packages use the SquashFS file system. In the event of an error similar to the following:

error: system does not fully support snapd: cannot mount squashfs image using "squashfs"

you may verify that the SquashFS kernel module is loaded with

$ lsmod
Module                  Size  Used by
squashfs               xxxxx  x
...
提示:If you have recently installed the snapd package to your system, you may need to reboot Arch Linux before installing Snap packages.

Error: /user.slice/user-1000.slice/session-1.scope is not a snap cgroup[編輯 | 編輯原始碼]

You need to set your DBUS_SESSION_BUS_ADDRESS environment variable like so:

export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"

To make this change permanent and also available in your GUI session, consider adding this line to your ~/.xprofile file.

For more information and full discussion about this issue, please read here

Graphical management[編輯 | 編輯原始碼]

本文或本章節的事實準確性存在爭議。

原因: snap plugin for gnome-software is not built by default(在 Talk:Snap 中討論)


Both Gnome Software Center and KDE Discover can provide native snap support. For KDE Discover install discover-snapAUR package.

The Snap Store can be installed via snap

# snap install snap-store

Support[編輯 | 編輯原始碼]

Arch Linux related mailing lists and other official Arch Linux support channels are not an appropriate place to request help with snaps on Arch Linux. An appropriate place to ask for support is the Snapcraft forum.

See also[編輯 | 編輯原始碼]