Android Studio: /dev/kvm device permission denied

回眸只為那壹抹淺笑 提交于 2019-11-27 08:55:20

问题


When I try to run my Android app on an emulator I get this error:

/dev/kvm permission denied.

I checked the permissions and added the user I am currently logged in with to the kvm group. What is wrong?


回答1:


As mentioned in the comments, starting with Ubuntu 18.04 and Linux Mint Tara you need to first sudo apt install qemu-kvm.

To check the ownership of /dev/kvm use

ls -al /dev/kvm

The user was root, the group kvm. To check which users are in the kvm group, use

grep kvm /etc/group

This returned

kvm:x:some_number:

on my system: as there is nothing rightwards of the final :, there are no users in the kvm group.

To add your user to the kvm group, you could use

sudo adduser $USER kvm

which adds the user to the group, and check once again with grep kvm /etc/group.

As mentioned by @marcolz, the command newgrp kvm should change the group membership live for you. If that did not work, @Knossos mentioned that you might want to log out and back in (or restart), for the permissions to take effect.


To open a terminal, see https://askubuntu.com/questions/183775/how-do-i-open-a-terminal#183777.

To find out your username, see https://askubuntu.com/questions/333718/how-can-i-find-out-my-user-name#333832.




回答2:


This is how I got it to work in Ubuntu 18.04

sudo apt install qemu-kvm

Add your user to kvm group using:

sudo adduser <Replace with username> kvm

If still showing permission denied:

sudo chown <Replace with username> /dev/kvm

Try it.




回答3:


Try this, it worked for me:

  1. sudo apt install qemu-kvm

  2. sudo chown -R <username>:<username> /dev/kvm –




回答4:


Have you also tried following, it should work:

sudo chown <username> /dev/kvm
sudo chmod o+x /dev/kvm



回答5:


This is because /dev/kvm is not accessible. To make is accessible from android studio run the below command

sudo chmod 777 -R /dev/kvm

It will ask for your password. After that restart Android Studio.

KVM is required to rum emulator. If you have not install it yet then install it

sudo apt install qemu-kvm



回答6:


I countered the same problem and to solve this issue just type the following commands in terminal for Linux clients

   sudo apt-get install qemu-kvm

    // type your password

   sudo chmod 777 -R /dev/kvm

and after that try running simulator it'll work




回答7:


I am using linux debian, and i am facing the same way. In my AVD showing me a message "/dev/kvm permission denied" and i tried to find the solution, then what i do to solve it is, in terminal type this :

sudo chmod -R 777 /dev/kvm

it will grant an access for folder /dev/kvm,then check again on your AVD , the error message will disappear, hope it will help.




回答8:


sudo chown $USER /dev/kvm

Simply running that one command worked for me here in September 2019 running:

Description: Ubuntu 18.04.3

LTS Release: 18.04

Codename: bionic




回答9:


sudo setfacl -m u:$USER:rwx /dev/kvm

Worked for me.




回答10:


This Worked For Me on Linux (x18) ☑ Hope It Will Work For You Aswell

sudo chown hp /dev/kvm



回答11:


Open Terminal and log as admin

sudo su

Go to the dev folder

cd /dev/

Change the kvm mode

chmod 777 -R kvm



回答12:


I am using ubuntu 18.04. I was facing the same problem. I run this piece of command in terminal and problem is resolved.

sudo chown $USER /dev/kvm

the above command is for all the user present in your system.

If you want to give access to only a specific user then run this command

sudo chown UserNameHere /dev/kvm



回答13:


There's absolutely no need to install qemu-kvm (and all its dependencies) if you only want to run the Android Studio Emulator.

The only thing you have to do is to give your user (i.e. the one you are logged in with) the right to access the /dev/kvm-device.

This is done in three simple steps.

First:

Create the kvm-group

groupadd -r kvm

The option -r creates a system group, i.e. with a GID <= 999 (see /etc/login.defs => SYS_GID_MAX)

Second:

Change permissions on /dev/kvm. This could be done as part of the qemu-kvm-installation, because one of the dependencies is installing qemu-system-common (on current Ubuntu systems, package name may vary), which in turn installs the file /lib/udev/rules.d/60-qemu-system-common.rules containing the following:

KERNEL=="kvm", GROUP="kvm", MODE="0660"

So if you are just create a file /etc/udev/rules.d/60-qemu-permissions.rules containing the above line, you are done with the first step.

Third:

Add your username to the group by executing

usermod -a -G kvm <your_username> - the -a is important for adding your user to the kvm-group. Without that you will overwrite the group-settings for your user to only belonging to "kvm"...

That's it.

For the new udev rule and group setting to take effect it's easiest to reboot and login again.

You can also execute

udevadm control --reload-rules && udevadm trigger

for reloading the rules but you still have to logout and login again with regard to the new group.




回答14:


Just one slight improvement on Jerrin's answer on fixing this error with Ubuntu 18.04 by utilizing $USER variable available in the bash terminal. So you could use the following commands two commands:

sudo apt install qemu-kvm

Add the current user to the kvm group

sudo adduser $USER kvm

Also if you are still having issues, one other problem for me was the way in which I installed Ubuntu. I made the mistake of checking the box during installation for installing 3rd party software which did not play nice with my nvidia graphics card for development. So I reinstalled Ubuntu with this third party software unchecked.

Then after installation, open up Software & Updates and go to the Additional Drivers tab. Select the most up to date proprietary drivers that have also been tested and apply changes. Should restart the machine for the changes to take affect.




回答15:


I was in a similar situation with the same error of permissions on /dev/kvm I had done the necessary installations but not added the user to the kvm group All I had to do was

sudo adduser <Replace with username> kvm

and ofcourse DON'T forget to restart your Ubuntu instance.




回答16:


I got this error after updating my ubuntu to 18.04.1. I just download new system image for emulator or you can say that download new emulator and it is worked for me.




回答17:


This is a brief version of Gerd's answer

open the terminal and run following commands

sudo groupadd -r kvm

sudo gedit /lib/udev/rules.d/60-qemu-system-common.rules

Add the following line to the opened file and save it

KERNEL=="kvm", GROUP="kvm", MODE="0660"

Finally run:

usermod -a -G kvm <your_username>

Reboot your PC and Done!




回答18:


Type in terminal:

sudo apt install qemu-kvm -y
sudo chown $USER /dev/kvm



回答19:


Running the below command in Ubuntu 18.04 worked for me sudo chown -R /dev/kvm




回答20:


If you open your ide with sudo. You are not going to have this problem.



来源:https://stackoverflow.com/questions/37300811/android-studio-dev-kvm-device-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!