systemd-container1/create-minimal-container.sh
Holger b7694fe99b Simplify debootstrap options
This will work on Suse to install debian based container
Debootstrap must be installed on Suse
2024-06-19 21:39:40 +02:00

60 lines
1.8 KiB
Bash

#!/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 --arch=amd64 --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...."