From 2e191f4ab364cdb2d154edfa84d646822e1ce0df Mon Sep 17 00:00:00 2001 From: holger Date: Sat, 25 May 2024 20:44:58 +0200 Subject: [PATCH] create-minimal-container.sh --- create-minimal-container.sh | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 create-minimal-container.sh diff --git a/create-minimal-container.sh b/create-minimal-container.sh new file mode 100644 index 0000000..b06e84a --- /dev/null +++ b/create-minimal-container.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# create container with systemd-nspawn + +_container="minimal" # this will be your container name +machinectl stop "$_container" 2>/dev/null +sleep 2 +#rm -rf /var/lib/machines/"$_container" +machinectl remove "$_container" + +echo 'kernel.unprivileged_userns_clone=1' >/etc/sysctl.d/nspawn.conf +systemctl restart systemd-sysctl.service + +# create additional config file and enable host network +mkdir -p /etc/systemd/nspawn +echo "[Network]" >/etc/systemd/nspawn/"$_container".nspawn +echo "VirtualEthernet=no" >>/etc/systemd/nspawn/"$_container".nspawn + +#debootstrap --include=systemd,dbus stable /var/lib/machines/"$_container" +debootstrap --force-check-gpg --include=systemd,dbus,\ +apt-transport-https,\ +bash-completion,\ +ca-certificates,\ +mc,\ +mime-support,\ +busybox-static\ + --exclude=nano,vim-tiny,vim-common,dmidecode bookworm /var/lib/machines/"$_container" + +# create link +ln -s /usr/bin/busybox /var/lib/machines/"$_container"/usr/bin/vi + +# provide security repo +echo "deb http://security.debian.org/debian-security bookworm-security main" >>/var/lib/machines/"$_container"/etc/apt/sources.list + +# set hostname +echo "$_container" >/var/lib/machines/"$_container"/etc/hostname + +# create a rc.local DEPRECATED +echo "#!/bin/sh" >/var/lib/machines/"$_container"/etc/rc.local +#echo "apt update && apt dist-upgrade -y" >>/var/lib/machines/"$_container"/etc/rc.local +#echo "rm -f /etc/rc.local" >>/var/lib/machines/"$_container"/etc/rc.local + +chmod ugo+x /var/lib/machines/"$_container"/etc/rc.local + + +#echo "The new created container will start now..." +#echo "set root password with #password" +#echo "and then type logout" +#echo -n "Continue (y)? " +#read answer + +#systemd-nspawn -D /var/lib/machines/"$_container" -U --machine "$_container" + +sleep 2 +machinectl start "$_container" +sleep 2 +machinectl shell "$_container" +echo "Please setup now...."