8

In order to run a virtual machine, VirtualBox tells me to disable the KVM kernel module. I googled around and found out that KVM is included in the qemu-*-packages, but none of them is/was installed on my system (Debian Wheezy).

After that I simply tried to unload the module, but this doesn't want to work because it is in use:

# modprobe -r kvm_intel
FATAL: Module kvm_intel is in use.
# modprobe -r kvm
FATAL: Module kvm is in use.

I don't know what program is using it and I have really no idea what that could be. I also tried with the -f option but I get the same result.

My question is: How can I remove or disable the KVM Kernel module?

Update:

Here is the output of the lsmod command:

# lsmod | grep kvm
kvm_intel             138825  3 
kvm                   404853  1 kvm_intel
msrd0
  • 490
  • 2
  • 8
  • 22
  • Sometimes you can use `lsmod` to try and backtrack what is using the module. – mchid Nov 06 '14 at 19:51
  • @mchid I added the output of `lsmod` to the question. What programs should I terminate? – msrd0 Nov 06 '14 at 19:54
  • it says that kvm_intel is also in use, what is using kvm_intel? – mchid Nov 06 '14 at 19:55
  • @mchid Where can I know what is using `kvm_intel`? – msrd0 Nov 06 '14 at 19:59
  • I think I found it, try this command: `sudo service qemu-kvm stop` then check to see if it's still in use. – mchid Nov 06 '14 at 20:12
  • @mchid There is no such service, and I also wrote in the question that no `qemu-*` package is installed – msrd0 Nov 06 '14 at 20:13
  • 3
    you can `lsof | grep kvm` and then kill the PID running see http://stackoverflow.com/questions/9029526/how-to-find-the-list-of-processes-using-a-particular-kernel-module and you could also force rmmod http://stackoverflow.com/a/449211/3393576 – mchid Nov 06 '14 at 20:19
  • @mchid Thanks, I found out that a program called `kvm-irqfd-clean` is running, but even `killall kvm-irqfd-clean` doesn't terminate that program – msrd0 Nov 06 '14 at 20:25
  • I found an answer on stackoverflow http://stackoverflow.com/a/14645023/3393576 – mchid Nov 06 '14 at 20:26
  • http://stackoverflow.com/questions/14644904/fatal-module-kvm-intel-is-in-use/14645023#14645023 – mchid Nov 06 '14 at 20:27
  • @mchid Thanks for that link but that package is also not installed on my system ... – msrd0 Nov 06 '14 at 20:29
  • you can send SIGKILL: `sudo kill -9 {PID}` using the PID of kvm-irqfd-clean to kill it. – mchid Nov 06 '14 at 20:45
  • Check if the process has zero size; if so it's a kernel thread. – goldilocks Nov 06 '14 at 21:04
  • Out of curiosity, is there some special reason you want to use VirtualBox instead of Qemu/KVM? – peterph Jul 18 '15 at 14:17

2 Answers2

6

As you noticed, there was an application using the module. The KVM module actually presents (part of) its functionality through the/dev/kvm device file. So find out what application is using it - e.g. with

$ lsof | grep /dev/kvm
peterph
  • 30,520
  • 2
  • 69
  • 75
  • This worked for me. Though the libvirtd service was stopped, qemu-system-x86_64 was still running, thus the module was still in use. lsof's output made it far more obvious. :) – zaTricky Aug 02 '16 at 11:52
3

Sometimes you can use lsmod to try and backtrack what is using the module.

Here's an example:

kvm_intel             143597  0 
kvm                   459817  1 kvm_intel

On my machine it says that kvm is used by kvm_intel. Also, kvm is not in use. If this were the case you should be able to run:

sudo modprobe -r kvm_intel 

and then,

sudo modprobe -r kvm
mchid
  • 1,421
  • 2
  • 15
  • 21
  • 1
    This does not work, `kvm_intel` is also in use – msrd0 Nov 06 '14 at 19:58
  • @msrd0 yes the output says kvm_intel is in use because it has a "3" instead of a "0". So, run `lsmod` alone without grep and look for what is using kvm_intel. You have to go back and start with the module that is using that is not in use. Go down the line from there one by one. – mchid Nov 06 '14 at 20:01
  • 1
    Why should I stop using grep? How do I benefit from that? Since grep only returns those two lines, it seems that there is no other module using kvm or kvm_intel – msrd0 Nov 06 '14 at 20:03
  • @msrd0 Actually, that won't help. nevermind – mchid Nov 06 '14 at 20:06