Skip to content

Commit 12eee8d

Browse files
authored
Merge pull request #54 from AkihiroSuda/dev
examples: add Debian and fix Fedora
2 parents 01808c5 + 8ae7e80 commit 12eee8d

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ It may work on NetBSD and Windows hosts as well.
2525

2626
✅ Intel on ARM
2727

28-
✅ Ubuntu guest
29-
30-
✅ Fedora guest
28+
✅ Various guest Linux distributions: Ubuntu, Debian, Fedora, ...
3129

3230
Related project: [sshocker (ssh with file sharing and port forwarding)](https://github.com/AkihiroSuda/sshocker)
3331

examples/debian.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
images:
2+
- location: "https://cloud.debian.org/images/cloud/bullseye/daily/20210608-662/debian-11-generic-amd64-daily-20210608-662.qcow2"
3+
arch: "x86_64"
4+
- location: "https://cloud.debian.org/images/cloud/bullseye/daily/20210608-662/debian-11-generic-arm64-daily-20210608-662.qcow2"
5+
arch: "aarch64"
6+
mounts:
7+
- location: "~"
8+
writable: false
9+
- location: "/tmp/lima"
10+
writable: true
11+
ssh:
12+
# localPort is changed from 60022 to avoid conflicting with the default.
13+
# (TODO: assign localPort automatically)
14+
localPort: 60030

pkg/cidata/user-data.TEMPLATE

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ write_files:
2323
set -eux -o pipefail
2424
2525
{{- if .Containerd.User}}
26-
# Enable rootless containers
26+
# Set up env
27+
for f in .profile .bashrc; do
28+
if ! grep -q "# Lima BEGIN" "/home/{{.User}}.linux/$f"; then
29+
cat >>"/home/{{.User}}.linux/$f" <<EOF
30+
# Lima BEGIN
31+
# Make sure iptables and mount.fuse3 are available
32+
PATH="$PATH:/usr/sbin:/sbin"
33+
# fuse-overlayfs is the most stable snapshotter for rootless
34+
CONTAINERD_SNAPSHOTTER="fuse-overlayfs"
35+
export PATH CONTAINERD_SNAPSHOTTER
36+
# Lima END
37+
EOF
38+
chown "{{.User}}" "/home/{{.User}}.linux/$f"
39+
fi
40+
done
41+
# Enable cgroup delegation (only meaningful on cgroup v2)
2742
if [ ! -e "/etc/systemd/system/[email protected]/lima.conf" ]; then
2843
mkdir -p "/etc/systemd/system/[email protected]"
2944
cat >"/etc/systemd/system/[email protected]/lima.conf" <<EOF
@@ -33,6 +48,7 @@ write_files:
3348
fi
3449
systemctl daemon-reload
3550
51+
# Set up sysctl
3652
sysctl_conf="/etc/sysctl.d/99-lima.conf"
3753
if [ ! -e "${sysctl_conf}" ]; then
3854
if [ -e "/proc/sys/kernel/unprivileged_userns_clone" ]; then
@@ -43,10 +59,12 @@ write_files:
4359
sysctl --system
4460
fi
4561
46-
# Do additional setup for the user
62+
# Set up subuid
4763
for f in /etc/subuid /etc/subgid; do
4864
grep -qw "{{.User}}" $f || echo "{{.User}}:100000:65536" >> $f
4965
done
66+
67+
# Start systemd session
5068
loginctl enable-linger "{{.User}}"
5169
{{- end}}
5270
@@ -69,7 +87,7 @@ write_files:
6987
# We do not use per-once.
7088
path: /var/lib/cloud/scripts/per-boot/00-base.boot.sh
7189
permissions: '0755'
72-
{{- if or .Mounts .Containerd.User}}
90+
{{- if or .Mounts .Containerd.System .Containerd.User }}
7391
- content: |
7492
#!/bin/bash
7593
set -eux -o pipefail
@@ -80,16 +98,26 @@ write_files:
8098
{{- if .Mounts}}
8199
apt-get install -y sshfs
82100
{{- end }}
101+
{{- if or .Containerd.System .Containerd.User }}
102+
apt-get install -y iptables
103+
{{- end }}
83104
{{- if .Containerd.User}}
84-
apt-get install -y uidmap
105+
apt-get install -y uidmap fuse3 dbus-user-session
85106
{{- end }}
86107
elif command -v dnf 2>&1 >/dev/null; then
87108
: {{/* make sure the "elif" block is never empty */}}
88109
{{- if .Mounts}}
89110
dnf install -y fuse-sshfs
90111
{{- end}}
112+
{{- if or .Containerd.System .Containerd.User }}
113+
dnf install -y iptables
114+
{{- end }}
91115
{{- if .Containerd.User}}
92-
dnf install -y shadow-utils
116+
dnf install -y shadow-utils fuse3
117+
if [ ! -f /usr/bin/fusermount ]; then
118+
# Workaround for https://github.com/containerd/stargz-snapshotter/issues/340
119+
ln -s fusermount3 /usr/bin/fusermount
120+
fi
93121
{{- end}}
94122
fi
95123
# Modify /etc/fuse.conf to allow "-o allow_root"
@@ -130,17 +158,36 @@ write_files:
130158
cat >"/home/{{.User}}.linux/.config/containerd/config.toml" <<EOF
131159
version = 2
132160
[proxy_plugins]
161+
[proxy_plugins."fuse-overlayfs"]
162+
type = "snapshot"
163+
address = "/run/user/{{.UID}}/containerd-fuse-overlayfs.sock"
133164
[proxy_plugins."stargz"]
134165
type = "snapshot"
135166
address = "/run/user/{{.UID}}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
136167
EOF
137168
chown -R "{{.User}}" "/home/{{.User}}.linux/.config"
138169
fi
170+
selinux=
171+
if command -v selinuxenabled 2>&1 >/dev/null && selinuxenabled; then
172+
selinux=1
173+
fi
139174
if [ ! -e "/home/{{.User}}}}.linux/.config/systemd/user/containerd.service" ]; then
140175
until [ -e "/run/user/{{.UID}}/systemd/private" ]; do sleep 3; done
176+
if [ -n "$selinux" ]; then
177+
echo "Temporarily disabling SELinux, during installing containerd units"
178+
setenforce 0
179+
fi
180+
sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" systemctl --user enable --now dbus
141181
sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" containerd-rootless-setuptool.sh install
142182
sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" containerd-rootless-setuptool.sh install-buildkit
143-
sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" containerd-rootless-setuptool.sh install-stargz
183+
sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" containerd-rootless-setuptool.sh install-fuse-overlayfs
184+
if ! sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" containerd-rootless-setuptool.sh install-stargz; then
185+
echo >&2 "WARNING: rootless stargz does not seem supported on this host (kernel older than 5.11?)"
186+
fi
187+
if [ -n "$selinux" ]; then
188+
echo "Restoring SELinux"
189+
setenforce 1
190+
fi
144191
fi
145192
{{- end}}
146193
owner: root:root

0 commit comments

Comments
 (0)