On the webhostingtalk Forum, some foreign profiteers sell virtual machines as independent servers. In last July, a Chinese compatriot was cheated and posted a post on the WHT. The evidence is conclusive, even the service provider admitted that there were 355 replies. Hostatree.com, an independent server/VPs provider, boldly sold openvz VPs virtual machines as independent servers, at least one vmware/KVM/xen hvm should be created (more difficult to find it a virtual machine ), using openvz containers is also a bully: yesterday, I received an email from a netizen asking me how to determine whether I bought an independent server or a virtual machine. Vpsee briefly introduces the identification tips for common virtual technologies (including container technology) on the market.
Determine openvz/xen PV/UML
It is easiest to judge openvz/xen PV/UML. You can check the related directories and files in/proc directly. For example, the/proc/VZ file will exist in openvz VPs; the/proc/xen/directory is available on the xen PV virtual machine, and there are some things in the directory. The/proc/cpuinfo file printed on UML will find the UML mark. I wrote a simple Python script for detection:
#! /Usr/bin/Python # Check if a Linux system running on a virtual machine (openvz/xen PV/UML) # written by http://www.vpsee.comimport sys, osdef main (): If OS. getuid ()! = 0: Print "must be run as root" sys. exit (0) # Check openvz/unzip ozzo if OS. path. exists ("/proc/VZ"): If not OS. path. exists ("/proc/BC"): Print "openvz container" else: Print "openvz node" # Check xen if OS. path. exists ("/proc/xen/capabilities"): If (OS. path. getsize ("/proc/xen/capabilities")> 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 ()
Determine vmware/xen hvm/KVM
if you are using a full virtual machine such as vmware/xen hvm/KVM, it is more difficult to judge. The most accurate method is to read cpuid for determination, the following section of the xen Source Code checks whether the C language is xen Code Tools/MISC/ xen-detect.c, this Code provides a good example. vpsee overwrites the code, replaces the function with macros, and adds recognition of VMware and KVM. It can be run after compilation with GCC:
/** Check if a Linux system running on a virtual machine (vmware/xen hvm/KVM) * written by http://www.vpsee.com */# include stdio. h # include string. h # define hypervisor_info 0x40000000 # define cpuid (idx, eax, EBX, ECx, EDX) \ ASM volatile (\ "test % 1, % 1; JZ 1f; ud2a ;. ASCII \ "xen \"; 1: cpuid "\:" = B "(* EBX)," = A "(* eax)," = C "(* ECx ), "= D" (* EDX) \: "0" (idx); int main (void) {unsigned int eax, EBX, ECx, EDX; char string [13]; cpuid (hypervisor_info, & eax, & EBX, & ECx, & EDX); * (unsigned int *) (string + 0) = EBX; * (unsigned int *) (string + 4) = ECx; * (unsigned int *) (string + 8) = edX; string [12] = 0; If (strncmp (string, "xenvmmxenvmm ", 12) = 0) {printf ("xen hvm \ n");} else if (strncmp (string, "vmwarevmware", 12) = 0) {printf ("VMware \ n");} else if (strncmp (string, "kvmkvmkvm", 12) = 0) {printf ("KVM \ n ");} else printf ("Bare hardware \ n"); Return 0 ;}
Determine virtualbox/virtual PC
What? This kind of home desktop virtual machine is installed by itself will not know ?! If you do not know, you can also run the dmidecode tool in Linux and then find the manufacturer: innotek GmbH and Manufacturer: Microsoft Corporation keywords to correspond to virtualbox and Virtual PC.