Try   HackMD

systemd-nspawn Container Terminated rightaway when entering shell (systemd-nspawn, Ubuntu Focal, systemd 245.4-4ubuntu3)

Author: Junner
Date: 5/10/2025

There is a BUG for systemd-nspawn container, Ubuntu Focal. When entering a working machine, the caintainer terminated immediately.

┌──(junnerℵ₀pop-os)-[~]
└─$ sudo systemctl start systemd-nspawn@agents

┌──(junnerℵ₀pop-os)-[~]
└─$ machinectl list
MACHINE CLASS     SERVICE        OS     VERSION ADDRESSES
agents  container systemd-nspawn ubuntu 20.04   -

1 machines listed.

┌──(junnerℵ₀pop-os)-[~]
└─$ sudo machinectl shell agents
Connected to machine agents. Press ^] three times within 1s to exit session.

Connection to machine agents terminated.    

That is because the systemd from host machine (version ≥249) conflicts to the one in container (version 245.4-4ubuntu3). There is a detail description from +bug 1959475. So we need to update systemd to the version higher than or equal to 3.18.

How to update systemd

See my article here:
https://hackmd.io/@JunnerX/Update-systemd-Ubuntu-Focal-Fossa