Detecting hardware virtualization in Linux

By jbayer - Last updated: Friday, May 10, 2013 - Save & Share - Leave a Comment

For historical reasons, most systems which ship have the virtualization flag turned off.  If you aren’t expecting this, and try to install KVM in a Linux system, you can get unusual errors which don’t necessarily indicate the problem.

This script performs a few simple tests to see if virtualization is active or not.  I can’t guarantee that it is complete, but it works on the systems I’ve tested it on.  Please use it, and if you find an exception, please let me  know so I can update it.

#!/bin/bash
cpuinfo=`egrep '^flags.*(vmx|svm)' /proc/cpuinfo`
if [ "$cpuinfo" = "" ]; then
 echo "There doesn't appear to be any hardware support for virtualization"
 exit
fi
hardware=`dmesg | grep kvm | grep -i 'no hardware support'`
bios=`dmesg | grep kvm | grep -i 'disabled by bios'`
if [ "$hardware" != "" ]; then
 echo "No hardware support for KVM"
 exit
fi
if [ "$bios" != "" ]; then
 echo "KVM disabled by bios"
 exit
fi

			
Posted in Bash, Virtulization • Tags: , , , Top Of Page
175 views

Write a comment