check if VT-x is activated without having to reboot in Linux?
You can use rdmsr from msr-tools to read register IA32_FEATURE_CONTROL (address 0x3a). The kernel module msr has to be loaded for this.
On most Linux systems:
sudo modprobe msr
sudo rdmsr 0x3a
Values 3
and 5
mean it's activated.
Is there a way to check if virtualisation is enabled on the BIOS using C++?
To check if VMX or SVM (Intel and AMD virtualization technologies) are enabled you need to use the cpuid
instruction.
This instruction comes up so often in similar tests that the mainstream compilers all have an intrinsic for it, you don't need inline assembly.
For Intel's CPUs you have to check CPUID.1.ecx[5]
, while for AMD's ones you have to check CPUID.1.ecx[2]
.
Here's an example. I only have gcc on an Intel CPU, you are required to properly test and fix this code for other compilers and AMD CPUs.
The principles I followed are:
- Unsupported compilers and non-x86 architecture should fail to compile the code.
- If run on an x86 compatible CPU that is neither Intel nor AMD, the function return
false
.
The code assumes cpuid
exists, for Intel's CPUs this is true since the 486. The code is designed so that cpuid_ex
can return false
to denote that cpuid
is not present, but I didn't implement a test for it because that would require inline assembly. GCC and clang have a built-in for this but MSVCC doesn't.
Note that if you only build 64-bit binaries you always have cpuid
, you can remove the 32-bit architecture check so that if someday somebody tries to use a 32-bit build, the code fails to compile.
#if defined(_MSC_VER)
#include <intrin.h>
#elif defined(__clang__) || defined(__GNUC__)
#include <cpuid.h>
#endif
#include <string>
#include <iostream>
#include <cstdint>
//Execute cpuid with leaf "leaf" and given the temporary array x holding the
//values of eax, ebx, ecx and edx (after cpuid), copy x[start:end) into regs
//converting each item in a uint32_t value (so this interface is the same even
//for esoteric ILP64 compilers).
//If CPUID is not supported, returns false (NOTE: this check is not done, CPUID
//exists since the 486, it's up to you to implement a test. GCC & CLANG have a
//nice macro for this. MSVCC doesn't. ICC I don't know.)
bool cpuid_ex(unsigned int leaf, uint32_t* regs, size_t start = 0, size_t end = 4)
{
#if ( ! defined(__x86_64__) && ! defined(__i386__) && ! defined(_M_IX86) && ! defined(_M_X64))
//Not an x86
return false;
#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
//MS & Intel
int x[4]
__cpuid((int*)x, leaf);
#elif defined(__clang__) || defined(__GNUC__)
//GCC & clang
unsigned int x[4];
__cpuid(leaf, x[0], x[1], x[2], x[3]);
#else
//Unknown compiler
static_assert(false, "cpuid_ex: compiler is not supported");
#endif
//Conversion from x[i] to uint32_t is safe since GP registers are 32-bit at least
//if we are using cpuid
for (; start < end; start++)
*regs++ = static_cast<uint32_t>(x[start]);
return true;
}
//Check for Intel and AMD virtualization.
bool support_virtualization()
{
//Get the signature
uint32_t signature_reg[3] = {0};
if ( ! cpuid_ex(0, signature_reg, 1))
//cpuid is not supported, this returns false but you may want to throw
return false;
uint32_t features;
//Get the features
cpuid_ex(1, &features, 2, 3);
//Is intel? Check bit5
if (signature_reg[0] == 0x756e6547 && signature_reg[1] == 0x6c65746e && signature_reg[2] == 0x49656e69)
return features & 0x20;
//Is AMD? check bit2
if (signature_reg[0] == 0x68747541 && signature_reg[1] == 0x69746e65 && signature_reg[2] == 0x444d4163)
return features & 0x04;
//Not intel or AMD, this returns false but you may want to throw
return false;
}
int main()
{
std::cout << "Virtualization is " << (support_virtualization() ? "": "NOT ") << "supported\n";
return 0;
}
virtualbox - virtualization is enabled but not working
I seach for 2 days and nothing worked for me.. then i find the solution:
The problem is in Windows 10... u need to disable Hyper-V Manager ...
1) make sure in your BIOS cpu virtualization is enable.
2) open your CMD as administrator
3) in your desktop folder type bcdedit
and look for hypervisorlaunchtype in the bottom ... if it is Auto or enable we need to disable it !!!!!!
See this picture
4) type in your cmd bcdedit /set hypervisorlaunchtype off
5) Restart your OS and be happy !!!
i know this is a old question ... but for everyone who have a similar problem i hope it helps !!
Related Topics
Any Way to Exit Bash Script, But Not Quitting the Terminal
Excluding Directory When Creating a .Tar.Gz File
Custom Linux Gui: Where to Begin
Implementing an Update/Upgrade System for Embedded Linux Devices
How to Get Diff Between All Files Inside 2 Folders That Are on the Web
Symbolic Link to a Hook in Git
How to Recompile Just a Single Kernel Module
Linux Cmd to Search for a Class File Among Jars Irrespective of Jar Path
How to Create a Directory and Give Permission in Single Command
How to Enable Scrolling in Tmux Panels with Mouse Wheel
Suppress Echo of Command Invocation in Makefile
Centos/Linux Setting Logrotate to Maximum File Size for All Logs
Linux Script to Kill Java Process
Skipping Acquire of Configured File 'Main/Binary-I386/Packages'
How to Find Out What Inotify Watches Have Been Registered
Choosing Between Multiple Executables with Same Name in Linux