LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

systemd-detect-virt

Detect virtualization environment

TLDR

Report which virtualization is in use, if any
$ systemd-detect-virt
copy
Report through the exit status only, printing nothing
$ systemd-detect-virt --quiet
copy
Use it as a condition in a script
$ systemd-detect-virt --quiet && echo "[running virtualized]"
copy
Only consider container technologies
$ systemd-detect-virt --container
copy
Only consider full machine virtualization
$ systemd-detect-virt --vm
copy
Detect a chroot
$ systemd-detect-virt --chroot
copy
Detect a user namespace
$ systemd-detect-virt --private-users
copy
List everything it can recognize
$ systemd-detect-virt --list
copy

SYNOPSIS

systemd-detect-virt [options]

DESCRIPTION

systemd-detect-virt detects whether the system is running in a virtualized environment and prints the detected virtualization technology. It returns exit code 0 if virtualization is detected, non-zero otherwise.Detectable technologies include: KVM, QEMU, VMware, VirtualBox, Xen, Hyper-V, Docker, LXC, systemd-nspawn, and many others. The --list option shows all supported technologies.

PARAMETERS

--list

List all detectable virtualization technologies
-q, --quiet
Suppress output, only return exit code
-c, --container
Only detect container virtualization
-v, --vm
Only detect hardware VM virtualization
-r, --chroot
Detect chroot environment
--private-users
Detect user namespace

INSTALL

sudo apt install systemd
copy
sudo dnf install systemd
copy
sudo pacman -S systemd
copy
sudo zypper install systemd
copy
brew install systemd
copy
nix profile install nixpkgs#systemd
copy

CAVEATS

Detection relies on various heuristics and may not detect all virtualization types. Some nested virtualization scenarios may report only the innermost layer. Part of the systemd suite.

SEE ALSO

Copied to clipboard
Kai