Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect permissions on /dev/kvm #7149

Closed
1 of 2 tasks
davisjr opened this issue Jul 5, 2021 · 15 comments
Closed
1 of 2 tasks

Incorrect permissions on /dev/kvm #7149

davisjr opened this issue Jul 5, 2021 · 15 comments

Comments

@davisjr
Copy link
Member

davisjr commented Jul 5, 2021

Windows Build Number

Microsoft Windows [Version 10.0.22000.51]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.16

Distro Version

Ubuntu 20.04

Other Software

KVM

Repro Steps

Incorrect permissions on /dev/kvm is preventing startup of Android emulator although the user is a member of the required group.

$ emulator -avd api29
emulator: Android emulator version 30.6.5.0 (build_id 7324830) (CL:N/A)
ProbeKVM: This user doesn't have permissions to use KVM (/dev/kvm).
The KVM line in /etc/group is: [kvm:x:108:davisj]

If the current user has KVM permissions,
the KVM line in /etc/group should end with ":" followed by your username.

If we see LINE_NOT_FOUND, the kvm group may need to be created along with permissions:
    sudo groupadd -r kvm
    # Then ensure /lib/udev/rules.d/50-udev-default.rules contains something like:
    # KERNEL=="kvm", GROUP="kvm", MODE="0660"
    # and then run:
    sudo gpasswd -a $USER kvm

If we see kvm:... but no username at the end, running the following command may allow KVM access:
    sudo gpasswd -a $USER kvm

You may need to log out and back in for changes to take effect.

handleCpuAcceleration: feature check for hvf
emulator: ERROR: x86 emulation currently requires hardware acceleration!
CPU acceleration status: This user doesn't have permissions to use KVM (/dev/kvm).
The KVM line in /etc/group is: [kvm:x:108:davisj]

If the current user has KVM permissions,
the KVM line in /etc/group should end with ":" followed by your username.

If we see LINE_NOT_FOUND, the
More info on configuring VM acceleration on Linux:
https://developer.android.com/studio/run/emulator-acceleration#vm-linux
General information on acceleration: https://developer.android.com/studio/run/emulator-acceleration.

Permissions on /dev/kvm is currently (incorrect group and permissions):

$ ls -l /dev/kvm
crw------- 1 root root 10, 232 Jul  5 13:27 /dev/kvm

This should ideally be:

crw-rw---- 1 root kvm 10, 232 Jul  5 13:27 /dev/kvm

Manually changing it helps boot up the emulator. However, the settings are reverted on restart.

sudo chgrp kvm /dev/kvm
sudo chmod g+rw /dev/kvm

Looks like the correct permissions are part of udev defaults but this is not getting applied on WSL:
#4193 (comment) (#4193)

KERNEL=="kvm", GROUP="kvm", MODE="0660", OPTIONS+="static_node=kvm"

This is causing issues with React Native development on WSL where the manual step is required on every boot.
#6929

The issue is reproducible on Windows 10 21H1 builds as well.

Expected Behavior

Permissions on /dev/kvm should be as follows:

crw-rw---- 1 root kvm 10, 232 Jul  5 13:27 /dev/kvm

Actual Behavior

Current permissions on /dev/kvm:

crw------- 1 root root 10, 232 Jul  5 13:27 /dev/kvm

Diagnostic Logs

No response

@OneBlue
Copy link
Collaborator

OneBlue commented Jul 6, 2021

That's expected, WSL2 doesn't have udev.

You can use wsl.conf to change those permissions at boot time with something like this though:

# /etc/wsl.conf
[boot]
command = /bin/bash -c 'chown root:lvm /dev/kvm && chmod 660 /dev/kvm'

@OneBlue OneBlue closed this as completed Jul 6, 2021
@OneBlue
Copy link
Collaborator

OneBlue commented Jul 6, 2021

Release notes for boot.command: https://docs.microsoft.com/en-us/windows/wsl/release-notes#build-21286

@BreeceW
Copy link

BreeceW commented Dec 30, 2021

That's expected, WSL2 doesn't have udev.

You can use wsl.conf to change those permissions at boot time with something like this though:

# /etc/wsl.conf
[boot]
command = /bin/bash -c 'chown root:lvm /dev/kvm && chmod 660 /dev/kvm'

For anyone who comes across this, I wanted to add that this works if you change lvm to kvm, which I assume was a typo.

@gregaton
Copy link

gregaton commented Apr 4, 2022

If you still see the incorrect permissions error add your user to the kvm group and restart WSL.

sudo usermod -a -G kvm <username>

@felipemarques
Copy link

great ! works for me!

@Herbias
Copy link

Herbias commented Dec 11, 2022

That's expected, WSL2 doesn't have udev.

You can use wsl.conf to change those permissions at boot time with something like this though:

# /etc/wsl.conf
[boot]
command = /bin/bash -c 'chown root:lvm /dev/kvm && chmod 660 /dev/kvm'

Restart your WSL after. Works like a charm.

@proccedure-caze
Copy link

I cant find this folder, can anyone help me?

@smenard
Copy link

smenard commented Mar 23, 2023

That's expected, WSL2 doesn't have udev.
You can use wsl.conf to change those permissions at boot time with something like this though:

# /etc/wsl.conf
[boot]
command = /bin/bash -c 'chown root:lvm /dev/kvm && chmod 660 /dev/kvm'

Restart your WSL after. Works like a charm.

Doesn't work for me.

I Tried

# /etc/wsl.conf
[boot]
command = /bin/bash -c 'sudo chown USER:kvm /dev/kvm && sudo chmod 660 /dev/kvm'

but it didn t work . Does someone has a hint for me ?

@Biswa96
Copy link

Biswa96 commented Mar 23, 2023

@smenard
Copy link

smenard commented Mar 23, 2023

Are you using the WSL from Windows Store? https://apps.microsoft.com/store/detail/windows-subsystem-for-linux/9P9TQF7MRM4R?hl=en-us&gl=us

I think, is there a linux command that confirm that ?

@Biswa96
Copy link

Biswa96 commented Mar 23, 2023

Though not a Linux command, wsl.exe --version command from Windows would show some version details without any error or help message.

@smenard
Copy link

smenard commented Mar 24, 2023

Here are the corresponding informations :

wsl.exe --version
WSL version: 1.1.3.0
Kernel version: 5.15.90.1
WSLg version: 1.0.49
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19044.2604

@Biswa96
Copy link

Biswa96 commented Mar 24, 2023

This issue seem to be fixed in WSL from Windows Store if systemd is enabled.

  • Without systemd:
$ ls -l /dev/kvm
crw------- 1 root root 10, 232 Mar 1 00:00 /dev/kvm
  • With systemd:
$ ls -l /dev/kvm
crw-rw---- 1 root kvm 10, 232 Mar 1 00:00 /dev/kvm

So, you have to enabled systemd in wsl.conf file.

@Herbias
Copy link

Herbias commented Mar 26, 2023

It's pretty strange -- I did make it work by running the android virtual device on my machine before, but after I re-install my OS. I can't seem to make it work again.

Update

  • I was able to run a virtual device by running sudo /opt/android-studio/bin/studio.sh
  • I was able to run it. As @BreeceW mentioned, it was a typo.

@smenard
Copy link

smenard commented Mar 30, 2023

This issue seem to be fixed in WSL from Windows Store if systemd is enabled.

  • Without systemd:
$ ls -l /dev/kvm
crw------- 1 root root 10, 232 Mar 1 00:00 /dev/kvm
  • With systemd:
$ ls -l /dev/kvm
crw-rw---- 1 root kvm 10, 232 Mar 1 00:00 /dev/kvm

So, you have to enabled systemd in wsl.conf file.

Thanks it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants