Post

Proxmox上のLXCでSnapを使う

LXCでSnapが使いたい

検証環境としてProxmoxを使用した仮想化基盤を構築しています。

ProxmoxはKVMによるVMとLXCによるコンテナ、2つの仮想化環境を管理することができます。

コンテナ大好き人間(本当か?)ですし、一般にVMとコンテナでは後者の方がオーバーヘッドが少ないといわれているので、コンテナを使って遊んでみることにしました。

少し前からUbuntuの開発元であるCanonical財団がSnapというディストリビューションに依存しないパッケージ管理システムの普及を進めています。

個人的には別にUbuntuやDebianはapt、RH系ならYum、Archならpacmanでいいと思っているのですが、最近の主流がSnapになりそうなので、触っておきます。

ProxmoxのUbuntuのLXCテンプレートにはSnapが入っていない

ProxmoxのUbuntuテンプレートを使ってみようということで、それを使ってコンテナを作成。

Snapのテストのために、hello-worldパッケージを入れるも、そもそもSnapが入っていない。

1
2
3
4
root@snap-test:~# snap install hello-world
Command 'snap' not found, but can be installed with:
apt install snapd
root@snap-test:~# 

「Ubuntuで激押ししてるくせに入っていないのか・・・。」とか思いながら、Snapをインストール。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
root@snap-test:~# apt install snapd -y 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  dbus-user-session dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent
  gpg-wks-client gpg-wks-server gpgconf gpgsm libassuan0 libksba8 libldap-2.5-0
  libldap-common liblzo2-2 libnpth0 pinentry-curses squashfs-tools
Suggested packages:
  pinentry-gnome3 tor parcimonie xloadimage scdaemon pinentry-doc zenity | kdialog
The following NEW packages will be installed:
  dbus-user-session dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent
  gpg-wks-client gpg-wks-server gpgconf gpgsm libassuan0 libksba8 libldap-2.5-0
  libldap-common liblzo2-2 libnpth0 pinentry-curses snapd squashfs-tools
0 upgraded, 20 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.6 MB of archives.
After this operation, 110 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 dbus-user-session amd64 1.12.20-2ubuntu4.1 [9442 B]
~略~
Get:20 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 snapd amd64 2.58+22.04.1 [23.8 MB]
Fetched 26.6 MB in 46s (577 kB/s)                                                   
Selecting previously unselected package dbus-user-session.
(Reading database ... 17109 files and directories currently installed.)
Preparing to unpack .../00-dbus-user-session_1.12.20-2ubuntu4.1_amd64.deb ...
Unpacking dbus-user-session (1.12.20-2ubuntu4.1) ...
~略~
Selecting previously unselected package snapd.
Preparing to unpack .../19-snapd_2.58+22.04.1_amd64.deb ...
Unpacking snapd (2.58+22.04.1) ...
Setting up libksba8:amd64 (1.6.0-2ubuntu0.2) ...
~略~
Created symlink /etc/systemd/system/final.target.wants/snapd.system-shutdown.service -> /lib/systemd/system/snapd.system-shutdown.service.
snapd.failure.service is a disabled or a static unit, not starting it.
snapd.mounts-pre.target is a disabled or a static unit, not starting it.
snapd.mounts.target is a disabled or a static unit, not starting it.
snapd.snap-repair.service is a disabled or a static unit, not starting it.
Setting up gpg-wks-client (2.2.27-3ubuntu2.1) ...
Setting up gnupg (2.2.27-3ubuntu2.1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for install-info (6.8-4build1) ...
root@snap-test:~# 

再度インストールを試すも、

1
2
3
4
5
root@snap-test:~# snap install hello-world
error: system does not fully support snapd: cannot mount squashfs image using
       "squashfs": mount: /tmp/syscheck-mountpoint-3028863455: mount failed:
       Operation not permitted.
root@snap-test:~# 

squashfs関連で怒られました。

そんな・・・。

動くように試行錯誤

インターネットを漁ったらLXCではSnapが動かないという話も出てきましたが、

どうやらfuseを使ってごにょごにょすれば動きそうです。

先にホスト機からLXCコンテナの設定を変更します。

1
2
3
4
5
root@pve1:~# vi /etc/pve/lxc/101.conf
---
features: mount=fuse,nesting=1
lxc.mount.entry = /dev/fuse dev/fuse none bind,create=file 0 0
---

コンテナ内でsquashfuseをインストールします。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
root@snap-test:~# apt install squashfuse
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libfuse2 libsquashfuse0
The following NEW packages will be installed:
  libfuse2 libsquashfuse0 squashfuse
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 122 kB of archives.
After this operation, 466 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libfuse2 amd64 2.9.9-5ubuntu3 [90.3 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libsquashfuse0 amd64 0.1.103-3 [24.6 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/universe amd64 squashfuse amd64 0.1.103-3 [7516 B]
Fetched 122 kB in 1s (86.9 kB/s)    
Selecting previously unselected package libfuse2:amd64.
(Reading database ... 17470 files and directories currently installed.)
Preparing to unpack .../libfuse2_2.9.9-5ubuntu3_amd64.deb ...
Unpacking libfuse2:amd64 (2.9.9-5ubuntu3) ...
Selecting previously unselected package libsquashfuse0:amd64.
Preparing to unpack .../libsquashfuse0_0.1.103-3_amd64.deb ...
Unpacking libsquashfuse0:amd64 (0.1.103-3) ...
Selecting previously unselected package squashfuse.
Preparing to unpack .../squashfuse_0.1.103-3_amd64.deb ...
Unpacking squashfuse (0.1.103-3) ...
Setting up libfuse2:amd64 (2.9.9-5ubuntu3) ...
Setting up libsquashfuse0:amd64 (0.1.103-3) ...
Setting up squashfuse (0.1.103-3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
root@snap-test:~# 

再度試行するも、だめ。

1
2
3
4
5
6
7
root@snap-test:~# snap install hello-world
error: cannot perform the following tasks:
- Setup snap "core" (15925) security profiles (cannot reload udev rules: exit status 1
udev output:
Failed to send reload request: No such file or directory
)
root@snap-test:~# 

どうやらfuseが足りないようなのでインストール。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
root@snap-test:~# apt install fuse -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  fuse3 ntfs-3g
The following NEW packages will be installed:
  fuse
0 upgraded, 1 newly installed, 2 to remove and 0 not upgraded.
Need to get 27.0 kB of archives.
After this operation, 1307 kB disk space will be freed.
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 fuse amd64 2.9.9-5ubuntu3 [27.0 kB]
Fetched 27.0 kB in 1s (35.8 kB/s)
(Reading database ... 17495 files and directories currently installed.)
Removing ntfs-3g (1:2021.8.22-3ubuntu1.2) ...
Removing fuse3 (3.10.5-1build1) ...
Selecting previously unselected package fuse.
(Reading database ... 17419 files and directories currently installed.)
Preparing to unpack .../fuse_2.9.9-5ubuntu3_amd64.deb ...
Unpacking fuse (2.9.9-5ubuntu3) ...
Setting up fuse (2.9.9-5ubuntu3) ...
Installing new version of config file /etc/fuse.conf ...
Processing triggers for man-db (2.10.2-1) ...
root@snap-test:~# 

三度目の正直。。。

1
2
3
4
root@snap-test:~# snap install hello-world
2023-08-28T08:44:31Z INFO Waiting for automatic snapd restart...
hello-world 6.4 from Canonical** installed
root@snap-test:~# 

インストール成功。

なんかがおかしい(未解決)

snapでインストールしたhello-worldは「Hello, World!」を返してくれるはずなんですが、返してくれない・・・。

1
2
3
4
5
root@snap-test:~# hello-world
root@snap-test:~# tail -2 /var/log/syslog 
Aug 28 10:11:34 snap-test systemd[1]: Started snap.hello-world.hello-world-c819a1fc-f2cc-45e5-93c5-651f00786e50.scope.
Aug 28 10:11:34 snap-test systemd[1]: snap.hello-world.hello-world-c819a1fc-f2cc-45e5-93c5-651f00786e50.scope: Deactivated successfully.
root@snap-test:~# 

KVM上のUbuntuで動かすとちゃんと動くんだけどなぁ・・・。

1
2
3
4
5
jo3qma@kvm-test:~$ hello-world
Hello World!
jo3qma@kvm-test:~$ tail -1 /var/log/syslog
Aug 28 10:13:54 kvm-test systemd[2456]: Started snap.hello-world.hello-world-717ce107-7c96-4b84-be04-06336e272b3d.scope.
jo3qma@kvm-test:~$
コンテンツは CC BY-NC-SA 4.0 の下で利用できます。