@@ -23,7 +23,22 @@ write_files:
23
23
set -eux -o pipefail
24
24
25
25
{{- 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)
27
42
if [ ! -e "/etc/systemd/system/[email protected] /lima.conf" ]; then
28
43
mkdir -p "/etc/systemd/system/[email protected] "
29
44
cat >"/etc/systemd/system/[email protected] /lima.conf" <<EOF
@@ -33,6 +48,7 @@ write_files:
33
48
fi
34
49
systemctl daemon-reload
35
50
51
+ # Set up sysctl
36
52
sysctl_conf="/etc/sysctl.d/99-lima.conf"
37
53
if [ ! -e "${sysctl_conf}" ]; then
38
54
if [ -e "/proc/sys/kernel/unprivileged_userns_clone" ]; then
@@ -43,10 +59,12 @@ write_files:
43
59
sysctl --system
44
60
fi
45
61
46
- # Do additional setup for the user
62
+ # Set up subuid
47
63
for f in /etc/subuid /etc/subgid; do
48
64
grep -qw "{{.User}}" $f || echo "{{.User}}:100000:65536" >> $f
49
65
done
66
+
67
+ # Start systemd session
50
68
loginctl enable-linger "{{.User}}"
51
69
{{- end}}
52
70
@@ -69,7 +87,7 @@ write_files:
69
87
# We do not use per-once.
70
88
path: /var/lib/cloud/scripts/per-boot/00-base.boot.sh
71
89
permissions: '0755'
72
- {{- if or .Mounts .Containerd.User}}
90
+ {{- if or .Mounts .Containerd.System .Containerd. User }}
73
91
- content : |
74
92
#!/bin/bash
75
93
set -eux -o pipefail
@@ -80,16 +98,26 @@ write_files:
80
98
{{- if .Mounts}}
81
99
apt-get install -y sshfs
82
100
{{- end }}
101
+ {{- if or .Containerd.System .Containerd.User }}
102
+ apt-get install -y iptables
103
+ {{- end }}
83
104
{{- if .Containerd.User}}
84
- apt-get install -y uidmap
105
+ apt-get install -y uidmap fuse3 dbus-user-session
85
106
{{- end }}
86
107
elif command -v dnf 2>&1 >/dev/null; then
87
108
: {{/* make sure the "elif" block is never empty */}}
88
109
{{- if .Mounts}}
89
110
dnf install -y fuse-sshfs
90
111
{{- end}}
112
+ {{- if or .Containerd.System .Containerd.User }}
113
+ dnf install -y iptables
114
+ {{- end }}
91
115
{{- 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
93
121
{{- end}}
94
122
fi
95
123
# Modify /etc/fuse.conf to allow "-o allow_root"
@@ -130,17 +158,36 @@ write_files:
130
158
cat >"/home/{{.User}}.linux/.config/containerd/config.toml" <<EOF
131
159
version = 2
132
160
[proxy_plugins]
161
+ [proxy_plugins."fuse-overlayfs"]
162
+ type = "snapshot"
163
+ address = "/run/user/{{.UID}}/containerd-fuse-overlayfs.sock"
133
164
[proxy_plugins."stargz"]
134
165
type = "snapshot"
135
166
address = "/run/user/{{.UID}}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
136
167
EOF
137
168
chown -R "{{.User}}" "/home/{{.User}}.linux/.config"
138
169
fi
170
+ selinux=
171
+ if command -v selinuxenabled 2>&1 >/dev/null && selinuxenabled; then
172
+ selinux=1
173
+ fi
139
174
if [ ! -e "/home/{{.User}}}}.linux/.config/systemd/user/containerd.service" ]; then
140
175
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
141
181
sudo -iu "{{.User}}" "XDG_RUNTIME_DIR=/run/user/{{.UID}}" containerd-rootless-setuptool.sh install
142
182
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
144
191
fi
145
192
{{- end}}
146
193
owner: root:root
0 commit comments