16

I am currently taking an operating systems class and I need to use qemu to run a small operating system that my professor provided. I am trying to use qemu within an ubuntu 12.04 virtual machine on virtualbox on my macbook air 5.2. I know the problems I am having probably have to do with nested virtualization but the specific error I get when I try to run qemu is:

Could not access the KVM kernel module: No such file or directory

failed to initialize KVM: no such file or directory Back to tcg accelerator.

qemu does start up the os but the window flickers quite a lot and I would like to fix the KVM problem if possible. I've done research but I can't find a solution I can understand or that works so any help would be greatly appreciated.

Also for the ubuntu virtual machine in virtualbox I have both Enable VT-x/AMD-V and Enable Nested Paging checked under Hardware Virtualization. I've also tried using

modprobe kvm-intel

and I get this error:

FATAL: Error inserting kvm_intel (/lib/modules.3.5.0-22-generic/kernel/arch/x86/kvm/kvm-intel.ko): Operation not permitted.

Community
  • 1
  • 1
user1820145
  • 227
  • 1
  • 2
  • 4
  • 2
    This question would be more generic if it read 'Can I nest virtualization in a way that it supports qemu KVM?' or something like that, and not regarding your specific case. Remember, StackOverflow is more of a place for questions that may happen to anyone, not to you specifically. – ssice Jan 27 '13 at 00:08
  • just for reference, the errors `Could not access the KVM kernel module: No such file or directory failed to initialize KVM: no such file or directory Back to tcg accelerator.` are not unique to nested virtualization issues. I ran qemu on Ubuntu Precise (without virtualization) and it returned the same error (but then it continued and worked). – Cashew Aug 27 '14 at 16:19

2 Answers2

26

In my case, the virtualization was disabled.

So sudo modprobe kvm-intel kept giving me the following error

could not insert 'kvm_intel': Operation not supported

I just had to go in the BIOS and enable Virtualization.

Dushyant Bangal
  • 6,048
  • 8
  • 48
  • 80
  • Thank you! On my ThinkPad, I enabled specifically "Intel Virtualization Technology" under Security. – Rasmus Aug 25 '21 at 18:49
  • 1
    To verify, you can check `dmesg | grep kvm`. It will say `kvm: disabled by bios` if the setting is disabled. – SaeX Jan 09 '23 at 20:57
  • Thanks for the idea. I need to enable the "Intel Virtualization Technology" Under CPU section. After enabled, one should see vcpu0. – g5thomas Feb 06 '23 at 02:52
13

Try with sudo modprobe kvm-intel.

In order to have the module automatically loaded at the startup of the virtual machine, you can edit the file with any editor that allows you to edit files as root. You can use sudoedit, vscode, sudo -e or any other editor.

To keep the instructions straightforward, the following will work:

  1. Edit the corresponding file from the shell with sudo vi /etc/modules.conf
  2. Possibly enter your username password.
  3. Press the key G to go to the end of the document and then o to begin inserting.
  4. Write kvm-intel and press Enter, producing a new line.
  5. Press Esc to return to the Normal mode of vim. "--INSERT--" will disappear from the bottom.
  6. Save the file and exit vim by writing :wq.

You are done. Try to reboot and load the nested virtual machine.

ssice
  • 3,564
  • 1
  • 26
  • 44
  • 4
    I've already tried that, then it just says the same thing except operation not supported. – user1820145 Jan 26 '13 at 23:46
  • 3
    Operation not supported may mean that you can't actually do virtualization. Make sure your environment supports kvm by trying this command: `egrep '^flags.*(vmx|svm)' /proc/cpuinfo`. If there's no output, your virtual machine can't use KVM. Most probably nested virtualization isn't supported in KVM. – ssice Jan 26 '13 at 23:50
  • 1
    There isn't any output so I guess I won't be able to use kvm, thanks for your help though. – user1820145 Jan 27 '13 at 00:02
  • 1
    No problem. It seems that you can't actually use processor's Ring-0 even with VT-X. So, you'll need to go to your host OS to virtualize your professor's machine if you want it to have native performance. Or use an Ubuntu LiveCD instead of Ubuntu inside a VM. Or install it in a pendrive. There are lots of alternatives! – ssice Jan 27 '13 at 00:07
  • Can anyone help me do this on a machine with an AMD CPU? I'm running Linux Mint 17.1. – PrinceTyke Sep 11 '15 at 18:11