Skip to content

Feature request: Check if cpu supports KVM in install script #328

@kt-prc

Description

@kt-prc

Add a check to the installer to flag if the CPU does not support KVM.

Something similar to kvm-ok.sh from Ubuntu's cpu-checker package would work.

I have thrown together a stripped version of kvm-ok below:

#!/bin/sh


verdict() {
	# Return verdict
	if [ "$1" = "0" ]; then
		# KVM is usable
        echo "INFO: KVM acceleration can be used"
		exit 0
	else
        # KVM is not usable
		echo "INFO: KVM acceleration can NOT be used"
		exit 1
	fi
}

# check cpu flags for capability
virt=$(egrep -m1 -w '^flags[[:blank:]]*:' /proc/cpuinfo | egrep -wo '(vmx|svm)') || true
[ "$virt" = "vmx" ] && brand="intel"
[ "$virt" = "svm" ] && brand="amd"

if [ -z "$virt" ]; then
    # no kvm support from CPU
	verdict 1
fi

# Now, check that the device exists
if [ -e /dev/kvm ]; then
    # KVM is usable
	verdict 0
fi


echo "INFO: Your CPU supports KVM extensions"

disabled=0
# check brand-specific registers
if [ "$virt" = "vmx" ]; then
        BIT=$(rdmsr --bitfield 0:0 0x3a 2>/dev/null || true)
        if [ "$BIT" = "1" ]; then
                # and FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX clear (no tboot)
                BIT=$(rdmsr --bitfield 2:2 0x3a 2>/dev/null || true)
                if [ "$BIT" = "0" ]; then
			        disabled=1
                fi
        fi

elif [ "$virt" = "svm" ]; then
        BIT=$(rdmsr --bitfield 4:4 0xc0010114 2>/dev/null || true)
        if [ "$BIT" = "1" ]; then
		    disabled=1
        fi
else
    # Unknown virtualization extension
	verdict 1
fi

if [ "$disabled" -eq 1 ]; then
    # KVM disabled in BIOS
	verdict 1
fi

verdict 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions