4

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?

muru
  • 69,900
  • 13
  • 192
  • 292

1 Answers1

6

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.

Wieland
  • 6,353
  • 3
  • 28
  • 31
  • Excellent. Since I was using Debian 8, with systemd, for the container, `systemd-detect-virt` is just fine. – muru Apr 07 '15 at 08:10