启动 Android 模拟器失败:failed to initialize KVM: Device or resource busy

更新日期: 2017-08-04 阅读次数: 12610 分类: Android

上午 Android 模拟器还用的好好的,下午刚打开就报错

$ emulator -avd Nexus_5X_API_24 -netspeed full -netdelay none -use-system-libs

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

Google 了一下,原来是 Android 模拟器与 virtualbox 有冲突,我才想起,上午更改另一个项目的代码时,临时启动了 vagrant 的开发环境。而当时 vagrant 在 android 模拟器关闭的情况下也没有启动成功。不断在报 Remote connection disconnect 的错误信息

default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Remote connection disconnect. Retrying...

我猜测 virtualbox 的进程还是没有死干净

$ ps axuw | grep virtualbox
zhongwei   842  0.0  0.0  15968   940 pts/28   S+   13:58   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn virtualbox
zhongwei 17982  0.0  0.1 168440 12684 ?        S    11:45   0:05 /usr/lib/virtualbox/VBoxXPCOMIPCD
zhongwei 17987  0.1  0.2 628168 21592 ?        Sl   11:45   0:12 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
zhongwei 18641  1.2  0.9 1731708 78304 ?       Sl   11:46   1:36 /usr/lib/virtualbox/VBoxHeadless --comment vagrant_ytparty_default_1477971142925_47867 --startvm 364de668-bc5f-43ba-af88-d9fdf5a0e69c --vrde config
zhongwei 18657  0.0  0.1 162576 12852 ?        S    11:46   0:00 /usr/lib/virtualbox/VBoxNetDHCP --ip-address 192.168.56.100 --lower-ip 192.168.56.101 --mac-address 08:00:27:70:DF:90 --netmask 255.255.255.0 --network HostInterfaceNetworking-vboxnet0 --trunk-name vboxnet0 --trunk-type netflt --upper-ip 192.168.56.254

果然如此。

杀死所有包含 virtualbox 关键词的进程

sudo pkill -f virtualbox

The pattern is normally only matched against the process name. When -f is set, the full command line is used.

再次启动 Android 模拟器就没有问题了。

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式