|
| 1 | +#!/bin/sh |
| 2 | +set -xe |
| 3 | + |
| 4 | +# generic system setup |
| 5 | +apt install -y debootstrap systemd-container |
| 6 | +systemctl enable machines.target |
| 7 | +echo 'kernel.unprivileged_userns_clone=1' > /etc/sysctl.d/nspawn.conf |
| 8 | +echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.d/nspawn.conf |
| 9 | +systemctl restart systemd-sysctl.service |
| 10 | +systemctl enable systemd-networkd |
| 11 | +systemctl start systemd-networkd |
| 12 | + |
| 13 | +# params |
| 14 | +name=test |
| 15 | +container=/var/lib/machines/$name/ |
| 16 | + |
| 17 | +# destroy existing setup |
| 18 | +systemctl disable systemd-nspawn@$name.service |
| 19 | +systemctl stop systemd-nspawn@$name.service |
| 20 | +rm -f /etc/systemd/nspawn/$name.nspawn |
| 21 | +rm -rf $container |
| 22 | + |
| 23 | +# create new setup |
| 24 | +debootstrap --include=systemd-container,ca-certificates buster $container |
| 25 | +echo 'deb http://security.debian.org/ buster/updates main contrib non-free' >> $container/etc/apt/sources.list |
| 26 | +echo 'deb http://deb.debian.org/debian buster-updates main contrib non-free' >> $container/etc/apt/sources.list |
| 27 | +echo 'deb [trusted=yes] file:///repo ./' >> $container/etc/apt/sources.list |
| 28 | +cp -rv repo $container/ |
| 29 | +systemd-nspawn -D $container -E DEBIAN_FRONTEND=noninteractive apt update -y |
| 30 | +systemd-nspawn -D $container -E DEBIAN_FRONTEND=noninteractive apt upgrade -y |
| 31 | +systemd-nspawn -D $container -E DEBIAN_FRONTEND=noninteractive apt dist-upgrade -y |
| 32 | + |
| 33 | +systemd-nspawn -D $container systemctl enable systemd-networkd.service |
| 34 | + |
| 35 | +mkdir -p /etc/systemd/nspawn/ |
| 36 | +echo "[Network]" > /etc/systemd/nspawn/$name.nspawn |
| 37 | +echo "Zone=$name" >> /etc/systemd/nspawn/$name.nspawn |
| 38 | +systemctl enable systemd-nspawn@$name.service |
| 39 | +systemctl start systemd-nspawn@$name.service |
0 commit comments