The whole world is moving towards virtualization. Unless you maintain the inventory on CMDB , it is very difficult to find the server location and configuration. The hyper-visors like VMware vSphere, Microsoft Hyper-V, Xen and KVM supports Linux as virtual machine. If you have the proper CMDB for the virtual machine, you can easily find the hyper-visor for the VM and its location. Otherwise, you need to struggle little bit. Here we will examine such a scenario for Redhat Enterprise Linux 7 VM.
1. How to find the whether the system is physical machine or VM ?
Execute command called “virt-what” to know whether you are in physical machine or virtual machine .
[root@foundation1 ~]# virt-what [root@foundation1 ~]# [root@server1-UA ~]#echo $? 0 [root@server1-UA ~]#
If nothing is printed and the script exits with code 0 (no error), then it can mean either that the program is running on bare-metal or the program is running inside a type of virtual machine which we don’t know about or cannot detect.
2.If the system is virtual machine ,you will get the hyper-visor name like below.
[root@foundation1 ~]# virt-what vmware [root@foundation1 ~]#
The above output shows that VM is running on top of VMware hyper-visors. It can be vmware ESXi or VMware workstation/Fusion
3.If the host is running on top of Linux machine using KVM, you will get the output like below.
[root@server1-UA ~]#virt-what kvm [root@server1-UA ~]#
4.Xen virtual machines will display like below.
[root@server1-UA ~]# virt-what xen xen-domU [root@server1-UA ~]#
About virt-what:
virt-what is a shell script which can be used to detect if the program is running in a virtual machine or not. virt-what supports a very large number of different hypervisor types, including common open source hypervisors (KVM, Xen, QEMU, VirtualBox), mainframe systems like IBM Systemz, LPAR, z/VM, hardware partitioning schemes like Hitachi Virtage, proprietary hypervisors like VMWare, Microsoft Hyper-V.
virt-what is already packaged in Fedora (13+), Red Hat Enterprise Linux (5.7+ and 6.1+), Debian, Ubuntu, ArchLinux and Gentoo. If you don’t have the utility , download the source and compile it . virt-what source is available here.
virt-what has been developed by Redhat community.
Hope this article is informative to you. Share it ! Comment it !! Be Sociable !!!
Lingeswaran R says
The below command will help you to find whether the physical machine is supporting KVM or not .
To support KVM , you required, (For intel CPU’s)
1.virtual machine extensions (vmx)
2.Next extension (nx)
3.Long mode (lm)
[root@foundation1 ~]# cat /proc/cpuinfo |egrep -i “vmx|nx|lm”
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase smep
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase smep
[root@foundation1 ~]#
For AMD cpu’s
1.simple virtual machine (svm)
2.Next extension (nx)
3.Long mode (lm)
use the below command to check on AMD based systems.
# cat /proc/cpuinfo |egrep -i “svm|nx|lm”