create-minimal-container.sh
This commit is contained in:
parent
3669357ffc
commit
2e191f4ab3
58
create-minimal-container.sh
Normal file
58
create-minimal-container.sh
Normal file
@ -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...."
|
Loading…
x
Reference in New Issue
Block a user