Check Virtualization type for a running Linux

Are you running VPS as a hosting solution? And do you want to know what kind of virtualization is it running on? Is it OpenVZ, V-server, Xen or UML, and how can I confirm this?
Since the hosting providers normally do not tell you these kind of detailed info, here we created a simple script:

#!/usr/bin/python
#
# Check what kind of virtual machine for a running Linux. It supports (openvz/vserver/xen/uml).
# Please copy & save this script and run it as root.
#
# By Joseph Chen <https://www.admon.org/> 2011-12-10

import sys, os
import re

def main():
    if os.getuid() != 0:
        print "It must be run as root"
        sys.exit(0)

    # Check OpenVZ/Virtuozzo
    if os.path.exists("/proc/vz"):
        if not os.path.exists("/proc/bc"):
            print "openvz container"
        else:
            print "openvz node"

    # Check V-server
    if os.path.exists("/proc/self/status"):
	s = open("/proc/self/status", "r")
	txt = s.read()
	s.close()

        reobj = re.compile(r"^(s_context|VxID):[[:blank:]]*[0-9]/")
        if reobj.match (txt):
            if os.path.exists("/proc/virtual"):
                print "vserver_host"
            else:
                print "vserver"

    # Check Xen
    if os.path.exists("/proc/xen/capabilities"):

	f = open("/proc/xen/capabilities", "r")
	text = f.read()
	f.close()

        if (len(text) > 0):
            print "xen dom0"
        else:
            print "xen domU"

    # Check User Mode Linux (UML)
    f = open("/proc/cpuinfo", "r"); t = f.read(); f.close()
    if (t.find("UML") > 0):
        print "uml"

if __name__=="__main__":
    main()

Here is a running example on a Xen dom0 node:

root@pekdev230:~ # python check-vm.py 
xen dom0

Note that, the check for vserver may not work since I didn’t get an environment for testing. Sorry about that, but if you any updates, please kindly let me know.

Share Button

Leave a comment

Your email address will not be published. Required fields are marked *