From 2d4ab833f92e68f13ef9a50164f94a83b28cd40a Mon Sep 17 00:00:00 2001 From: idroz Date: Tue, 25 Aug 2026 13:58:40 +0100 Subject: [PATCH] update incus install script --- scripts/enable_incus.sh | 59 ++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/scripts/enable_incus.sh b/scripts/enable_incus.sh index 1c19e2e..d3406c7 100644 --- a/scripts/enable_incus.sh +++ b/scripts/enable_incus.sh @@ -1,20 +1,22 @@ +#!/bin/sh +set -e + hwclock -s -> /etc/apk/repositories -echo "http://dl-cdn.alpinelinux.org/alpine/v3.18/main" >> /etc/apk/repositories +> /etc/apk/repositories +echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories apk update apk upgrade +apk add --no-cache zfs incus incus-client ip6tables lxc linux-pam shadow-uidmap -apk add --no-cache zfs incus incus-client ip6tables - +# Make sure config directories exist before writing into them +mkdir -p /etc/lxc /etc/pam.d /etc/conf.d /var/lib/incus > /etc/init.d/incusd - cat > /etc/init.d/incusd <<'endmsg' #!/sbin/openrc-run - command="/usr/sbin/incusd" command_args="${INCUSD_OPTIONS}" command_background="true" @@ -22,26 +24,15 @@ pidfile="/run/incus/${RC_SVCNAME}.pid" retry="${INCUSD_STOP_TIMEOUT:-60}" extra_started_commands="quit" description_quit="Daemon quits and leaves the instances running" - : ${INCUSD_FORCE_STOP:="no"} - depend() { need net cgroups dbus use lxcfs after firewall } - start_pre() { checkpath --directory "${pidfile%/*}" --mode 0750 - # Required for running systemd containers - #if [ -d /sys/fs/cgroup/unified ] && ! [ -d /sys/fs/cgroup/systemd ]; then - # checkpath --directory --owner root:lxd /sys/fs/cgroup/systemd - # mount -t cgroup \ - # -o rw,nosuid,nodev,noexec,relatime,none,name=systemd \ - # cgroup /sys/fs/cgroup/systemd - #fi } - stop() { ebegin "Stopping ${RC_SVCNAME}" if [ "$INCUSD_FORCE_STOP" = "no" ]; then @@ -50,7 +41,6 @@ stop() { $command shutdown --force fi } - quit() { ebegin "Quitting ${RC_SVCNAME}" start-stop-daemon --signal SIGQUIT --pidfile $pidfile --quiet @@ -58,20 +48,33 @@ quit() { } endmsg +chmod +x /etc/init.d/incusd + echo "session optional pam_cgfs.so -c freezer,memory,name=systemd,unified" >> /etc/pam.d/system-login echo "lxc.idmap = u 0 100000 65536" >> /etc/lxc/default.conf echo "lxc.idmap = g 0 100000 65536" >> /etc/lxc/default.conf echo "root:100000:65536" >> /etc/subuid echo "root:100000:65536" >> /etc/subgid - -# If you plan to run systemd based Linux distributions (Debian, Ubuntu, etc.) -echo "systemd_container=yes" >> /etc/conf.d/lxc - - -# Sort out UID mappings -chmod -x /usr/bin/newgidmap - -rc-update add lxc -rc-update add incusd +echo "systemd_container=yes" >> /etc/conf.d/lxc + +chmod u+s /usr/bin/newuidmap /usr/bin/newgidmap + +# Ensure DNS resolution works before incusd starts — it fetches instance-type +# data from images.linuxcontainers.org on first run and needs working DNS. +if ! grep -q '^nameserver' /etc/resolv.conf 2>/dev/null; then + echo "nameserver 1.1.1.1" >> /etc/resolv.conf +fi + +echo "Waiting for network connectivity..." +for i in $(seq 1 30); do + if ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then + echo "Network is up." + break + fi + sleep 1 +done + +rc-update add incusd default +rc-service incusd start reboot \ No newline at end of file