diff --git a/Makefile b/Makefile index e42871cec3..527afa82fe 100644 --- a/Makefile +++ b/Makefile @@ -269,7 +269,7 @@ dotenv-force: .PHONY: environment-bootstrap # Bootstrap the local development environment. -environment-bootstrap: wsl2-systemd-check install-python-dev install-lint security-apparmor-teardown network-dns-setup network-ipv6-disable +environment-bootstrap: wsl2-systemd-check install-python-dev install-lint security-apparmor-teardown network-dns-setup network-ipv6-disable kernel-loop-load .PHONY: environment-teardown # Tear down the local development environment. @@ -372,6 +372,12 @@ install-system-python: install-venv: install-system-python @bash scripts/install/venv.sh +.PHONY: kernel-loop-load +# Load the kernel loop driver the swarm backup DR drill needs. +# Note: node containers have no udev and cannot load modules, so the host must carry it. +kernel-loop-load: + @sudo bash scripts/system/kernel/loop/load.sh + .PHONY: lint # Run all lint checks in parallel. # Note: each check runs on host or in docker per INFINITO_LINT_RUNNER. diff --git a/aliases b/aliases index 81888efe1f..712a6fc111 100644 --- a/aliases +++ b/aliases @@ -40,6 +40,7 @@ alias i8dofo='m dotenv-force' alias i8fi='m fix-chmod' alias i8fido='m fix-dockerignore' alias i8he='m help' +alias i8kelo='m kernel-loop-load' alias i8la='m alias' alias i8li='m lint' alias i8lica='m lint-action' diff --git a/scripts/system/kernel/loop/load.sh b/scripts/system/kernel/loop/load.sh new file mode 100755 index 0000000000..47a9b83830 --- /dev/null +++ b/scripts/system/kernel/loop/load.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# shellcheck shell=bash +# +# Load the kernel's loop driver so the swarm backup DR drill can attach its +# simulated LUKS 'USB'. The drill runs inside a node container that has no +# udev and cannot load modules itself: it materialises /dev/loopN with mknod, +# but those nodes are dead until the driver is present on the host. Without +# it cryptsetup aborts with "loop device with autoclear flag is required" +# roughly three hours into a swarm round. +# +# Use `make kernel-loop-load` rather than calling this script directly. + +set -euo pipefail + +modprobe loop + +if [ ! -c /dev/loop-control ]; then + echo "FAILURE: /dev/loop-control absent after 'modprobe loop'" >&2 + exit 1 +fi + +echo "loop driver ready: $(losetup -a | wc -l) device(s) currently attached" diff --git a/scripts/tests/deploy/swarm/routine/backup/02_luks_device.sh b/scripts/tests/deploy/swarm/routine/backup/02_luks_device.sh index d7053f169e..00240cb4ae 100755 --- a/scripts/tests/deploy/swarm/routine/backup/02_luks_device.sh +++ b/scripts/tests/deploy/swarm/routine/backup/02_luks_device.sh @@ -4,6 +4,12 @@ # device mountpoint; the deployed svc-bkp-local-2-device unit then syncs # onto it like a real plug event. # +# Loop devices need two things the node container cannot supply itself. It has +# no udev, so LOOP_CTL_GET_FREE hands out a minor whose /dev node never appears +# and cryptsetup aborts with "loop device with autoclear flag is required" — +# hence the mknod loop below. And it cannot load kernel modules, so those nodes +# stay dead unless the host carries the loop driver: `make kernel-loop-load`. +# # Arguments: # $1 USB_IMG loop image path to create # $2 MOUNT_DIR configured services.local-2-device.mount path @@ -24,6 +30,16 @@ USB_MAPPER="${4:?}" USB_PASS="${5:?}" USB_SIZE_MB="${6:-512}" +for _minor in $(seq 0 7); do + [ -b "/dev/loop${_minor}" ] || mknod "/dev/loop${_minor}" b 7 "${_minor}" +done + +if ! losetup -f >/dev/null 2>&1; then + echo "FAILURE: no loop device available in this node; the nodes above are dead" >&2 + echo " without the host-side driver. Run 'make kernel-loop-load' on the host." >&2 + exit 1 +fi + losetup -ln 2>/dev/null | awk '/\(deleted\)/ {print $1}' | xargs -r -n1 losetup -d 2>/dev/null || true # nocheck: shell-or-true -- grandfathered: worked in practice; TODO: sharpen to catch only the exact tolerated error losetup -j "${USB_IMG}" 2>/dev/null | cut -d: -f1 | xargs -r -n1 losetup -d 2>/dev/null || true # nocheck: shell-or-true -- grandfathered: worked in practice; TODO: sharpen to catch only the exact tolerated error