NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.28k stars 14.26k forks source link

VirtualBox "Kernel driver not accessible" #76108

Open iterprise opened 4 years ago

iterprise commented 4 years ago

Describe the bug I have the same problem as here https://github.com/NixOS/nixpkgs/issues/75808 But I don't have virtualbox in my user environment

type VirtualBox VirtualBox /run/current-system/sw/bin/VirtualBox

To Reproduce Steps to reproduce the behavior:

  1. Install virtual box. My cfg is it attach.

  2. Try to run VirtualBox and start VM in non root user

if run VBox from root user it works fine.

configuration.txt

Expected behavior Start VM

Additional context type VirtualBox VirtualBox /run/current-system/sw/bin/VirtualBox

groups users wheel networkmanager libvirtd vboxusers kvm

id uid=1000(user) gid=100(users) группы=100(users),1(wheel),57(networkmanager),67(libvirtd),72(vboxusers),302(kvm)

ls -l /dev/vbox* crw-rw---- 1 root vboxusers 10, 58 дек 20 19:59 /dev/vboxdrv crw-rw-rw- 1 root root 10, 57 дек 20 19:59 /dev/vboxdrvu crw-rw---- 1 root vboxusers 10, 56 дек 20 19:59 /dev/vboxnetctl

/dev/vboxusb: итого 0 drwxr-x--- 2 root vboxusers 100 дек 20 19:59 002 drwxr-x--- 2 root vboxusers 60 дек 20 19:59 003

Metadata Please run nix run nixpkgs.nix-info -c nix-info -m and paste the result.

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: nixpkgs.virtualbox
# a list of nixos modules affected by the problem
module: virtualisation/virtualbox-host
iterprise commented 4 years ago

I found out an interesting thing VirtualBoxVM (not VirtualBox) works fine.

whereis VirtualBox VirtualBox: /nix/store/3a2v194b1izyvyrv827k3nd1ll2lrynf-system-path/bin/VirtualBox

whereis VirtualBoxVM VirtualBoxVM: /run/wrappers/wrappers.CdINDHDJKF/VirtualBoxVM.real /run/wrappers/wrappers.CdINDHDJKF/VirtualBoxVM

brodul commented 4 years ago

I have the same issue.

brodul commented 4 years ago

I upgraded the channel.

Removed the virtualbox.host.enable = true switched then added it back and switched. Started working. @iterprise try updating the channel and rebuild. :rocket:

matt-snider commented 4 years ago

I had this issue as well and was able to solve it. It seems that it was caused by having virtualbox under environment.systemPackages as well as virtualisation.virtualbox.host.enable = true. I removed it from systemPackages and it now it works.

stale[bot] commented 4 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

ghost commented 3 years ago

The solution @matt-snider described worked for me - simply remove it from "environment.systemPackages" and tada.wav

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

bratorange commented 3 years ago

The solution @matt-snider described worked for me - simply remove it from "environment.systemPackages" and tada.wav

OP posted that he had already taken this measure.

I found out an interesting thing VirtualBoxVM (not VirtualBox) works fine.

whereis VirtualBox VirtualBox: /nix/store/3a2v194b1izyvyrv827k3nd1ll2lrynf-system-path/bin/VirtualBox

whereis VirtualBoxVM VirtualBoxVM: /run/wrappers/wrappers.CdINDHDJKF/VirtualBoxVM.real /run/wrappers/wrappers.CdINDHDJKF/VirtualBoxVM

The same worked for me but, the gui wouldn't work. Could this get some attention again? For me atleast the issue still persists.

rardiol commented 2 years ago

Adding myself to the vboxusers group fixed the issue for me.

virtualisation.virtualbox.host.enable says

In order to pass USB devices from the host to the guests, the user needs to be in the vboxusers group.

I didn't touch the USB configurations but I still had to be in the group. Maybe that helps?

exarkun commented 2 years ago

OP posted that he had already taken this measure.

The OP wrote:

But I don't have virtualbox in my user environment

I wonder if they really meant they don't have it in users.users.<name>.packages. This seems like a more reasonable interpretation of "user environment" than environment.systemPackages.

If they meant the former and they have the package in the latter then the fix described by others, removing it from environment.systemPackages, might help.

Independent of that, maybe virtualisation.virtualbox.host.enable should come along with an assertion that virtualbox isn't in environment.systemPackages? Maybe only when hardening is enabled.

fionera commented 2 years ago

I also had virtualbox in my environment.systemPackages and this issue. Removing it directly fixed the issue.

teto commented 2 years ago

In order to pass USB devices from the host to the guests, the user needs to be in the vboxusers group.

In my case, I had nothing in environment.systemPackages, but adding myself to the group vboxusers fixed it.

adamoudad commented 2 years ago

@teto I am interested to know the virtualbox version you have installed. Mine is 6.1.34. I have the following lines in my /etc/nixos/configuration.nix

  virtualisation.virtualbox.host.enable = true;
  users.extraGroups.vboxusers.members = [ "adam" ];

and vboxusers does appear when I run groups, but I still have the error message "Kernel driver not accessible" when running VirtualBox as the user adam. If I run sudo VirtualBox, everything works fine, so I believe this is a problem of access rights, but what is wrong with my configuration then?

teto commented 2 years ago

sry I stopped using virtualbox.

adamoudad commented 2 years ago

Well, I am not sure why, but it works now. Here are the relevant lines in my configuration.nix.

  virtualisation.virtualbox.host.enable = true;
  virtualisation.docker.enable = true;
  users.users.adam.extraGroups = [ "libvirtd" "networkmanager" "wheel" "audio" "docker" "vboxusers" ];

I tried using libvirt a bit, gave it up a bit, then I enabled docker, while leaving virtualbox enabled. The three of them should not be particularly related but I mention this here for the sake of completeness.

staticdev commented 1 year ago

I have a similar issue, I installed it with Debian instead of NixOS with nix-env -iA nixpkgs.virtualbox. When I try to do a vagrant up of a VM in VB I get:

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "d302cd36-e959-4e5b-8aeb-31fc75417d0e", "--type", "headless"]

Stderr: VBoxManage: error: VirtualBox kernel driver is not accessible, permission problem. If you have built VirtualBox yourself, make sure that you do not have the vboxdrv kernel module from a different build or installation loaded. Also, make sure the vboxdrv udev rule gives you the permission you need to access the device. (VERR_VM_DRIVER_NOT_ACCESSIBLE)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole
karkusviktor commented 8 months ago

For me "virtualisation.virtualbox.host.enableHardening = false;" fixed the issue.

I checked the process and ran from /etc/profiles/per-user/${USER}/bin/VirtualBox so I gave the option a try and it worked. Maybe #5283 is related?

AkechiShiro commented 4 months ago

Is this still needed on your side @karkusviktor ? On my side it looks fixed right now with hardening enabled (the default setting), it seems to work.

karkusviktor commented 3 months ago

Which channel do you use @AkechiShiro ? I'm using the latest stable one (24.05) and for me the issue still persists.

AkechiShiro commented 3 months ago

@karkusviktor I'm using the latest stable one too, not sure why the issue still persists for you.

Here is my nix-info -m output :

 - system: `"x86_64-linux"`
 - host os: `Linux 6.10.3, NixOS, 24.05 (Uakari), 24.05.3642.883180e6550c`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - channels(root): `"agenix, home-manager-24.05.tar.gz, nixos-24.05, nixos-unstable"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos
karkusviktor commented 3 months ago

For me it's:

nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.44, NixOS, 24.05 (Uakari), 24.05.3642.883180e6550c`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - channels(root): `"nixos-24.05"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
AkechiShiro commented 3 months ago

I believe I had the stable kernel when I tried and not the latest that I have right now enabled, will retry at some point and let you know if it still works using the latest kernel package that I have set right now in my configuration.

nixos-discourse commented 2 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/virtualbox-kernel-driver-is-not-accessible/46479/5