How to Detect Virtualization Type (OpenVZ, KVM, Xen) on a Linux VPS


9 views

When working with a Linux VPS, it's often necessary to determine the underlying virtualization technology. This information can be crucial for system configuration, troubleshooting, or performance optimization. Here are several methods to identify your VPS's virtualization platform.

The simplest method is using the built-in systemd-detect-virt command:

systemd-detect-virt

This will output the virtualization type if detected (kvm, xen, openvz, etc.) or "none" if running on bare metal.

Examine CPU flags for virtualization clues:

grep -E "vmx|svm|hypervisor" /proc/cpuinfo

Look for these indicators:

  • KVM: QEMU Virtual CPU or kvm_clock present
  • Xen: Xen or xen-dom0 in flags
  • VMware: hypervisor present

The kernel ring buffer often contains virtualization information:

dmesg | grep -i virtual

This might reveal messages like "Booting paravirtualized kernel on Xen" or similar.

The virt-what package provides comprehensive detection:

sudo apt-get install virt-what  # Debian/Ubuntu
sudo yum install virt-what      # CentOS/RHEL
virt-what

This script performs multiple checks and returns the most likely virtualization type.

Different hypervisors leave different traces:

# For OpenVZ:
if [ -f /proc/vz ]; then echo "OpenVZ detected"; fi

# For LXC:
if [ -f /.dockerenv ]; then echo "Docker/LXC detected"; fi

# For KVM:
if [ -d /sys/bus/virtio ]; then echo "KVM detected"; fi

For systems with DMI support:

sudo dmidecode -s system-manufacturer
sudo dmidecode -s system-product-name

This might return values like "QEMU", "VirtualBox", or "VMware Virtual Platform".

Virtualization often creates characteristic network interfaces:

ip link show | grep -E 'venet|veth|virbr'

Where:

  • venet: OpenVZ
  • veth: LXC/Docker
  • virbr: KVM/libvirt

Other approaches include:

# Check for Xen:
if [ -f /proc/xen/capabilities ]; then echo "Xen detected"; fi

# Check for Hyper-V:
if dmesg | grep -qi "Hyper-V"; then echo "Hyper-V detected"; fi

# Check for VirtualBox:
if lsmod | grep -q vboxguest; then echo "VirtualBox detected"; fi

By combining several of these methods, you can reliably determine your VPS's virtualization technology even when some indicators might be masked or modified.


When working with cloud instances or VPS environments, knowing your underlying virtualization technology is crucial for:

  • System compatibility checks
  • Performance optimization
  • Driver selection
  • Troubleshooting hypervisor-specific issues

Here are the most reliable techniques to identify your virtualization platform:

Method 1: Using systemd-detect-virt

The modern approach for systems with systemd:

systemd-detect-virt

Sample outputs:

kvm
xen
openvz
none  # indicates bare metal

Method 2: Checking /proc/cpuinfo

Examine processor flags and hypervisor information:

grep -E 'vmx|svm|hypervisor' /proc/cpuinfo

Interpretation guide:

  • vmx/svm: Hardware virtualization support (Intel VT-x/AMD-V)
  • hypervisor: Running under a hypervisor

Method 3: Virt-what Script

The traditional detection tool:

wget https://gitlab.com/esr/virt-what/-/raw/master/virt-what
chmod +x virt-what
./virt-what

This comprehensive script detects:

kvm
xen
openvz
lxc
vmware
virtualbox
parallels

KVM Detection

lsmod | grep kvm
dmesg | grep -i kvm

Xen Detection

xl list
xentop
dmesg | grep -i xen

OpenVZ Detection

cat /proc/vz/version
ls /proc/vz/

For environments where standard methods don't work:

Checking DMI Information

dmidecode -s system-product-name
dmidecode | grep -i vendor

Timing Analysis

Some virtualization technologies leave timing artifacts:

time sh -c 'for i in $(seq 1 10000); do true; done'

Here's a comprehensive detection script:

#!/bin/bash

echo "=== Virtualization Detection ==="

# Try systemd first
if command -v systemd-detect-virt &>/dev/null; then
    echo -n "systemd-detect-virt: "
    systemd-detect-virt 2>/dev/null || echo "none"
fi

# Check for virt-what
if [ -x /usr/sbin/virt-what ]; then
    echo "virt-what: $(/usr/sbin/virt-what 2>/dev/null || echo 'none')"
fi

# Check CPU flags
echo -n "CPU Features: "
grep -E 'vmx|svm|hypervisor' /proc/cpuinfo | head -1

# Platform specific checks
[ -d /proc/vz ] && echo "OpenVZ detected: $(cat /proc/vz/version 2>/dev/null)"
[ -f /proc/xen/capabilities ] && echo "Xen detected: $(cat /proc/xen/capabilities)"
dmesg | grep -qi kvm && echo "KVM hints found in dmesg"

# Fallback to DMI info
echo -n "DMI System: "
dmidecode -s system-product-name 2>/dev/null || echo "Unknown"