systemd nspawn

A light system container environment.

Here are some notes to install a CentOS on Fedora in the ~/sfroot directory using a local ip:

Setup chroot

cat <<EOF>sf.repo
mkdir sfroot
sudo dnf -c sf.repo --disablerepo=* --enablerepo=sf-master --installroot ~/sfroot install systemd sf-config passwd openssh-server vim yum openssh-clients hostname selinux-policy

Setup root access

sudo systemd-nspawn -D ~/sfroot/
chroot> passwd -d root
chroot> rm /etc/securetty
chroot> systemctl enable sshd

Boot with network

sudo systemd-nspawn -bD ~/sfroot -n

On the host:

sudo ip a add dev ve-sfroot
sudo ip link set ve-sfroot up
sudo iptables -t nat -A POSTROUTING -s -j MASQUERADE
sudo cp /etc/resolv.conf ~/sfroot/etc/
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
echo | sudo tee -a /etc/hosts

On the container:

ip a add dev host0
ip link set host0 up
ip route add default via

Stop from the host by running killall systemd-nspawn.

Links to this page