26.5. Identifying guest type and implementation

26.5. Identifying guest type and implementation

The script below can identify if the environment an application or script is running in is a para-virtualized, a fully virtualized guest or on the hypervisor. The script below can be used to identify running on:

#!/bin/bash
declare -i IS_HVM=0
declare -i IS_PARA=0
check_hvm()
{
	IS_X86HVM="$(strings /proc/acpi/dsdt | grep int-xen)"
	  if [ x"${IS_X86HVM}" != x ]; then
	   echo "Guest type is full-virt x86hvm"
	   IS_HVM=1
	fi
}
check_para()
{
	if $(grep -q control_d /proc/xen/capabilities); then
	  echo "Host is dom0"
	  IS_PARA=1
	else
	  echo "Guest is para-virt domU"
	  IS_PARA=1
	fi
}
if [ -f /proc/acpi/dsdt ]; then 
	check_hvm
fi

if [ ${IS_HVM} -eq 0 ]; then
	if [ -f /proc/xen/capabilities ] ; then
		check_para
	fi
     fi
if [ ${IS_HVM} -eq 0 -a ${IS_PARA} -eq 0 ]; then
	echo "Baremetal platform"
fi

Note: This documentation is provided {and copyrighted} by Red Hat®, Inc. and is released via the Open Publication License. The copyright holder has added the further requirement that Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. The CentOS project redistributes these original works (in their unmodified form) as a reference for CentOS-5 because CentOS-5 is built from publicly available, open source SRPMS. The documentation is unmodified to be compliant with upstream distribution policy. Neither CentOS-5 nor the CentOS Project are in any way affiliated with or sponsored by Red Hat®, Inc.