Quite recently I started using systemd-nspawn to set up other OS instances on my Arch box. One thing I'd like to do is detect if I'm inside a container, and if so, add the distro name (from lsb_release) to the terminal title. On Debian-based systems, the default .bashrc uses debian_chroot for a similar purpose. How do I detect if I am running inside a nspawn container?


systemd-detect-virt can tell you whether your system is running in a VM/container. This requires systemd-detect-virt inside your container, but the systemd documentation on minimal builds suggests that you can just build a package that only includes systemd-detect-virt.

  • Excellent. Since I was using Debian 8, with systemd, for the container, systemd-detect-virt is just fine. – muru Apr 7 '15 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.