120

Whenever I have Virtualbox running, I cannot start an Android emulator image (and vice versa). The error message in the AVD manager is

ioctl(KVM_CREATE_VM) failed: Device or resource busy
ko:failed to initialize KVM

How can I make both run at the same time?

That is a Ubuntu 64 bit, all involved software is of the latest released version.

14 Answers 14

42

Removing the kvm kernel modules (using 'sudo rmmod kvm_intel kvm') makes it possible to run the Virtualbox and the Android emulator at the same time but the performance of the Android emulator in such a setup is extremely bad. If possible it is better to shutdown the Virtualbox emulator and unload its driver (vboxdrv) by running 'sudo /etc/init.d/vboxdrv stop'. Google suggests this "solution" on its Android Emulator page in the section about Linux.

5
  • 11
    My backend required for the app to have data runs on VirtualBox (Vagrant), so that's not a great option :P Nov 20, 2015 at 11:46
  • 4
    This solution #@%!'s due to the fact that i need to run both at the same time .. my HTTPD service is in Virtual Box, while my App is in Android .. /me sighs. Guess, it's time to fire up the Dev Server again.
    – E Net Arch
    Feb 1, 2017 at 19:15
  • 1
    Another option may be to use Docker instead of VirtualBox in conjunction with the Android emulator.
    – Matt Welke
    Feb 6, 2018 at 22:59
  • 1
    Or run Vagrant with KVM. Nov 7, 2018 at 20:17
  • Thanks @MichaelHampton. I installed vagrant-libvert and it worked!
    – jchook
    Jan 13, 2019 at 21:42
33

I got the same VirtualBox conflict. Solved it by using ABI different from "x86" (armeabi-v7a in my case)

7
  • Much more elegant than shtting the existing VM down. Thanks. Feb 3, 2015 at 8:21
  • 4
    Saddened to hear this.
    – MatBee
    Dec 11, 2015 at 19:34
  • Presumably the emulator will run slowly this way, but it is an option. Dec 1, 2016 at 0:55
  • In my case I also need the VirtualBox VM to run (for RDP), so this was a really good advice.
    – Csaba Toth
    Dec 1, 2016 at 5:39
  • 2
    @rudolfbyker, what the answer says is that emulators that run with CPU/ABI x86/x86_64 is a lot faster, but uses the same KVM (Kernel-based Virtual Machine) as VitualBox. Creating an emulator with another CPU, like arm64, will not conflict with VirtualBox, but emulator is a lot slower.
    – jayeffkay
    Jan 18, 2017 at 13:24
19

I stopped the virtual machines I had running with VirtualBox. This made the error disappear.

6
  • 1
    This worked for me in Fedora 20. With bigger displays, more RAM and Gnome 3 workspaces, it's easy to forget you're running another machine somewhere in the background. killall virtualbox should do it.
    – Ray Foss
    Jan 18, 2015 at 4:11
  • Works but not the best solution. You can have them both (see Stanislav's answer) Feb 3, 2015 at 8:22
  • I had this issue with Ubuntu 16 while using docker machine and virtual box drivers. stopping the vms with docker-machine stop machine-name resolved the issue as suggested in this asnwer Jan 3, 2018 at 9:05
  • Turns out just shutting down VirtualBox GUI and VMs won't do the trick. In my case I had several virtualbox processes still running: VBoxSVC, VBoxNetDHCP, VBoxXPCCOMIPCD. Killing them in top/htop solved the issue. Mar 16, 2018 at 6:01
  • 1
    The question was 'How can I make both run at the same time?'. Oct 23, 2018 at 21:07
6

I had the same problem on Ubuntu 13.10. Try to remove kvm and kvm_intel kernel modules.

To do this:

  1. Stop all emulators.
  2. Run command: 'sudo rmmod kvm_intel kvm'

Without these kernel modules Virtualbox and Android emulators can work at the same time.

BTW, I do not know why the modules are loaded.

4
  • 17
    A word of warning: while this does work, removing the KVM kernel modules will cause a substantial decrease in performance with the Intel Android image, since you lose the CPU's hardware acceleration support without the kernel modules.
    – JustJohn
    Aug 10, 2013 at 18:04
  • 2
    @Tajchert: to revert: 'sudo modprobe kvm_intel kvm' Apr 15, 2016 at 8:31
  • x86... emulators refused to run without KVM modules. Bah.
    – Martlark
    Aug 23, 2016 at 3:59
  • both drivers are needed Mar 29, 2018 at 4:06
5

There is finally a fix for this.

Follow these steps for macOS:

  1. In Android Studio Go to Tools -> Android -> SDK Manager

  2. Confirm you have the latest version of Intel Emulator Accelerator HAXM installed (v6.1.1) Preferences panel in Android Studio.

  3. Go to the extras directory of the Android SDK location displayed in the preferences. On MacOS you can do this:

    open ~/Library/Android/sdk/extras

  4. Install the HAXM packing by opening IntelHAXM_6.1.1.dmg, then opening IntelHAXM_6.1.1.mpkg in the mounted folder, and following the installer instructions.

Follow these steps for Windows:

  1. In Android Studio Go to Tools -> Android -> SDK Manager

  2. Confirm you have the latest version of Intel Emulator Accelerator HAXM installed (v6.1.1) Preferences panel in Android Studio.

  3. Go to the extras directory of the Android SDK location displayed in the preferences. Something like:

    C:\Users\<username>\AppData\Local\Android\sdk\extras

  4. In that directory is some kind of file like intelhaxm-android.exe. Run it.

5
  • 4
    Is there also a fix for Ubuntu 16.04.3 ?
    – sanders
    Sep 24, 2017 at 19:08
  • HAXM doesn´t support nested virtual Machines!
    – Jorgesys
    Dec 29, 2017 at 0:22
  • What about KVM? How can I do the same? Mar 28, 2018 at 15:18
  • This is not about nested virtual Machines. The problem in this topic is for side by side virtual machines. And it makes absolutely no sense that this shouldn't work,
    – Lothar
    Jun 17, 2018 at 0:39
  • 2
    And there is no solution for Linux. Bad luck again for Linux usage. This means that i have to choose windows now as my build server.
    – Lothar
    Jun 17, 2018 at 0:57
4

You also can change CPT/ABI setting from x86 to arm in emulator settings.

1
  • 2
    But then the emulator is going to be slow as hell ... but at least you can run both at the same time ;)
    – biophonc
    Aug 7, 2014 at 11:36
4

I finally made this problem obsolete by using Genymotion instead of the standard Android emulator. Besides not having this conflict, it is several times faster than the normal emulator.

4
  • is this a free software? Jan 28, 2016 at 0:06
  • @vishnu viswanath Only for non-commercial purpose use cases. Read more here genymotion.com/legal/terms-and-conditions below "License granted: Limited". Which says: This license is granted to the end user only and exclusively in connection with personal use, the end user is an individual, and not a professional, who downloads the application for personal and private needs, excluding commercial and professional environment.
    – mykolaj
    Jul 18, 2016 at 12:39
  • 1
    This probably disappeared because genymotion didn't use KVM. Neither stable (because at some point they gonna start using it), nor performant solution.
    – Hi-Angel
    Oct 17, 2016 at 8:16
  • Thank you for commenting out this option. I'd install Genymotion for Personal Use in Ubuntu 18.04 and I can now use my VirtualBox machines at the same time :)
    – Fer B.
    Mar 14, 2020 at 19:28
3

Another solution is to use libvirt backed vagrant using vagrant-libvirt plugin.

0
3

For those who are developing on Linux and are stuck with a host of back-end systems running inside virtualbox, a simple solution is simply to create a virtualbox X86 Android VM and expose the 5555 port on the NAT interface tunnelled from localhost through PAT. No need for slow arm AVD, no need for libvirt/vagrant let alone killing kvm!

enter image description here

Then let adb know about it

$ adb tcpip 5555
restarting in TCP mode port: 5555
$ adb connect 127.0.0.1
connected to 127.0.0.1:5555
$ adb devices
List of devices attached adb server
* daemon started successfully
emulator-5554   device

Then, pressing run or debug, in Android Studio will deploy and execute on that VM. You have complete control under Android Studio debugger.

4
  • The device shows up as "offline" when running adb devices :( Jul 17, 2021 at 20:37
  • Connecting to "VirtWifi" in the android virtual machine (inside VirtualBox) solved the problem! Jul 17, 2021 at 20:42
  • Also consider using the terminal emulator in the Android X86 VBox to edit /etc/hosts, or even install an SSHD server (user space) app on the VM. Jul 18, 2021 at 14:10
  • By far the best option
    – Kanchu
    Aug 11, 2022 at 4:41
2

Though it's a workaround either, but definitely better than disabling KVM as everyone suggesting.

Just run the virtualbox guest in KVM instead. For example (kvm here is just a script running a qemu-system-x86_64 -enable-kvm):

kvm Win7.vdi -boot c -m 2G -vga qxl
2
  • This solved the problem for me, however I can't figure out how to get my virtual image to connect to the internet and for some reason the keybord mapping is all messed up..
    – MikeSchem
    Nov 7, 2016 at 23:54
  • @MikeSchem yeah, unfortunately configuring a network in KVM/QEMU is a big deal. Back when I wrote the answer I haven't time to get network up'n'running because after some manipulations Windows guest started falling with BSOD on start up in KVM, whilst still working in VB.
    – Hi-Angel
    Nov 8, 2016 at 6:35
1

In some cases, we need to keep virtualbox machines up and running therefore let all the virtualbox machines keep running, switch to physical mobile device to test your application instead of emulator.

you can use expo if you are doing with react-native or your real android/ios device.

0

I resolved it by installing HAXM 6.1.2.

Please refer to the following link for details :- https://forums.docker.com/t/cant-using-docker-for-mac-with-android-emulator-haxm/8939/11

0

This might be out of topic, due to the fact that OP requested VirtualBox + KVM in the same time, but still, it might be the workaround: I was looking for a way to launch Windows 7 and AVD on Ubuntu 18.10 x64. Turning off KVM is not an option due to the fact that performance of AVD is critical to me. I have installed Windows 7 via Virtual Machine Manager (virt-manager package) and now both the AVD and Windows 7 are hardware accelerated.

0

Here is how solved this issue, using vagrant and it's two plugins 'libvirt' and 'mutate':

  1. Open terminal and set environment variables:

     export VAGRANT_DEFAULT_PROVIDER=libvirt
     export VAGRANT_HOME=/home/directoryToStoreVagrant/
     VBoxManage list vms
    
  2. Now copy the a the code obtained from last command like "c1530713-aec2-4415-a6b5-b057928c7e5f" and use in the following:

    vagrant package --base c1530713-aec2-4415-a6b5-b057928c7e5f --output window7.box

     vagrant init window7
     vagrant up window7 --provider=libvirt 
     vagrant box list
    
  3. You need to install some vagrant plugins like libvirt and mutate. Mutate will convert .box to libvirt VM:

    vagrant plugin install vagrant-libvirt vagrant plugin install vagrant-mutate

  4. Converting vagrant box to libvirt:

    vagrant mutate window7_.box libvirt

  5. Now you can initialise the vagrant VM. If any error persist move to edit your Vagrant file. Like for me I uncomment the line starts with config.vm.network and then run command below:

    vagrant up --provider=libvirt

This is how I was able get rid of this error completely

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.