Android Studio: /dev/kvm device permission denied

后端 未结 27 3124
鱼传尺愫
鱼传尺愫 2020-12-02 03:12

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

/dev/kvm permission denied.

I checked the permissions and ad

相关标签:
27条回答
  • 2020-12-02 04:07

    Under Ubuntu, the permissions of /dev/kvm usually look like this:

    $ ls -l /dev/kvm
    crw-rw---- 1 root kvm 10, 232 May 24 09:54 /dev/kvm
    

    The user that runs the Android emulator (i.e. your user) needs to get access to this device.

    Thus, there are basically 2 ways how to get access:

    • Make sure that your user is part of the kvm group (requires a re-login of your user after the change)
    • Widen the permissions of that device such that your user has access (requires a change to the udev daemon configuration)

    Add User to KVM Group

    Check if your user is already part of the kvm group, e.g.:

    $ id 
    uid=1000(juser) gid=1000(juser) groups=1000(juser),10(wheel)
    

    If it isn't then add it with e.g.:

    $ sudo usermod --append --groups kvm juser
    

    After that change you have to logout and login again to make the group change effective (check again with id).

    Widen Permissions

    Alternatively, you can just can widen the permissions of the /dev/kvm device.

    Example:

    echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
        | sudo tee /etc/udev/rules.d/99-kvm4all.rules
    sudo udevadm control --reload-rules
    sudo udevadm trigger --name-match=kvm
    

    FWIW, this is the default on other distributions such as Fedora and CentOS.

    Check the effectiveness of the above commands with another ls. You should see output similar to:

    $ ls -l /dev/kvm
    crw-rw-rw-. 1 root kvm 10, 232 2020-05-16 09:19 /dev/kvm
    

    Big advantage: You don't need to logout and login again for this change to be effective.

    Non-Solutions

    • calling chmod and chown directly on /dev/kvm - 1) these changes aren't persistent over reboots and 2) since /dev/kvm permissions are controlled by the udev daemon, it can 'fix' its permissions at any time, e.g. after each emulator run
    • adding executable permissions to /dev/kvm - your emulator just requires read and write permissions
    • changing permissions recursively on /dev/kvm - I don't know what's up with that - looks like cargo cult
    • installing extra packages like qemu - you already have your emulator installed - you just need to get access to the /dev/kvm device
    0 讨论(0)
  • 2020-12-02 04:10
    sudo setfacl -m u:$USER:rwx /dev/kvm
    

    Worked for me.

    0 讨论(0)
  • 2020-12-02 04:10

    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.

    0 讨论(0)
提交回复
热议问题