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

Are there steps missing integrating usbip support in NixOS-WSL ? #111

Open
573 opened this issue Jun 23, 2022 Discussed in #110 · 10 comments
Open

Are there steps missing integrating usbip support in NixOS-WSL ? #111

573 opened this issue Jun 23, 2022 Discussed in #110 · 10 comments

Comments

@573
Copy link
Contributor

573 commented Jun 23, 2022

Discussed in #110

Originally posted by 573 June 23, 2022
It would be awesome to have usbip support in NixOS-WSL (see https://github.com/dorssel/usbipd-win/wiki/WSL-support).

I've only gotten so far to try the usbip command inside the VM and I'm still not clear how to get that. Loading kernel package in configuration.nix didn't seem to as we use the kernel provided by Microsoft.

Is it just a case of building our own version of the MS kernel (https://nixos.wiki/wiki/Linux_kernel) ?

When from Powershell (regular user, Windows side) running

& 'C:\Program Files\usbipd-win\usbipd.exe' wsl attach --busid 3-1

I'm just stuck in the

usbipd: error: WSL 'usbip' client not correctly installed. See https://github.com/dorssel/usbipd-win/wiki/WSL-support for the latest instructions.

What do you say ? Can we figure this out as a Step-By-Step list maybe just to complete the instructions (saying just "on other distros") over at https://github.com/dorssel/usbipd-win/wiki/WSL-support ?

@SuperSandro2000
Copy link
Member

Loading kernel package in configuration.nix didn't seem to as we use the kernel provided by Microsoft.

yes, that will not work.

Maybe https://nixos.wiki/wiki/Linux_kernel#Custom_configuration is a help but I am not sure if the kernel can be exported from NixOS and will work for Windows/WSL.

@KoviRobi
Copy link
Contributor

KoviRobi commented Jan 27, 2023

With the new WSL version from Windows store, I'm able to use usbip with the default NixOS system (because as far as I understand, NixOS isn't providing the kernel, that's provided by Microsoft?)

I do have to use

Admin PowerShell> usbipd.exe list
Admin PowerShell> usbipd.exe bind -b 7-2
root nixos shell# usbip list -r 10.0.0.1
root nixos shell# usbip attach -r 10.0.0.1 -b 7-2

but this might be because of my unusual networking (to work around Windows having the WSL2 interface as public, and my work laptop having firewalled all public interfaces without me being able to make an exception, I have a wireguard tunnel between Windows and WSL2, which I can change the Windows net compartment on. So 10.0.0.1 is the Windows IP for me.)

@SuperSandro2000
Copy link
Member

because as far as I understand, NixOS isn't providing the kernel, that's provided by Microsoft?

We are using the kernel from Microsoft and explicitly not building one ourselves.

@573 573 changed the title Are they steps missing integrating usbip support in NixOS-WSL ? Are there steps missing integrating usbip support in NixOS-WSL ? Jan 30, 2023
@alexvorobiev
Copy link

alexvorobiev commented Aug 20, 2023

I have services.udev.enable = true and I am getting this error:

PS C:\Users\alexa> usbipd wsl attach --busid 1-2
usbipd: info: Using default WSL distribution 'NixOS-1'; specify the '--distribution' option to select a different one.
usbipd: error: WSL kernel is not USBIP capable; update with 'wsl --update'.
PS C:\Users\alexa> wsl --update
Checking for updates.
The most recent version of Windows Subsystem for Linux is already installed.

@KoviRobi
Copy link
Contributor

I think from memory you might have to install WSL from the Microsoft store to get the most up to date version? It's complaining about the Microsoft kernel, not the NixOS kernel I believe

@alexvorobiev
Copy link

alexvorobiev commented Aug 21, 2023

I have the WSL from the store. I did some digging to see where the message is generated: https://github.com/dorssel/usbipd-win/blob/c86397770de86a1493e1ce1a7aef497e99ba8fc2/Usbipd/CommandHandlers.cs#L657. So the test it runs is here https://github.com/dorssel/usbipd-win/blob/c86397770de86a1493e1ce1a7aef497e99ba8fc2/Usbipd/CommandHandlers.cs#L647. When I tried to run this command from the admin powershell I got an error:

> wsl --distribution NixOS-1 --user root -- cat /sys/devices/platform/vhci_hcd.0/status
/run/current-system/sw/bin/bash: line 1: cat: command not found

But it runs fine if I specify the full path to cat:

 > wsl --distribution NixOS-1 --user root -- /run/current-system/sw/bin/cat /sys/devices/platform/vhci_hcd.0/status
hub port sta spd dev      sockfd local_busid
hs  0000 004 000 00000000 000000 0-0
hs  0001 004 000 00000000 000000 0-0
hs  0002 004 000 00000000 000000 0-0
hs  0003 004 000 00000000 000000 0-0
hs  0004 004 000 00000000 000000 0-0
hs  0005 004 000 00000000 000000 0-0
hs  0006 004 000 00000000 000000 0-0
hs  0007 004 000 00000000 000000 0-0
ss  0008 004 000 00000000 000000 0-0
ss  0009 004 000 00000000 000000 0-0
ss  0010 004 000 00000000 000000 0-0
ss  0011 004 000 00000000 000000 0-0
ss  0012 004 000 00000000 000000 0-0
ss  0013 004 000 00000000 000000 0-0
ss  0014 004 000 00000000 000000 0-0
ss  0015 004 000 00000000 000000 0-0

As a matter of fact only the commands under standard Linux paths (/bin, /usr/bin) work without specifying their paths with wsl -- all the other commands fail with the same error and need the full path. My default shell is zsh for all users including root. Could that be the reason?

@alexvorobiev
Copy link

alexvorobiev commented Aug 21, 2023

So after I symlinked cat and usbip to /usr/bin everything seems to be working:

sudo ln -s /run/current-system/sw/bin/cat /usr/bin
sudo ln -s /run/current-system/sw/bin/usbip /usr/bin

But I am puzzled why busid is 1-1 in Linux:

PS C:\Users\alexa> usbipd wsl attach --busid 1-2 --distribution NixOS-1
PS C:\Users\alexa> wsl --distribution NixOS-1 --user root -- cat /sys/devices/platform/vhci_hcd.0/status
hub port sta spd dev      sockfd local_busid
hs  0000 006 003 00010002 000003 1-1
hs  0001 004 000 00000000 000000 0-0
hs  0002 004 000 00000000 000000 0-0
hs  0003 004 000 00000000 000000 0-0
hs  0004 004 000 00000000 000000 0-0
hs  0005 004 000 00000000 000000 0-0
hs  0006 004 000 00000000 000000 0-0
hs  0007 004 000 00000000 000000 0-0
ss  0008 004 000 00000000 000000 0-0
ss  0009 004 000 00000000 000000 0-0
ss  0010 004 000 00000000 000000 0-0
ss  0011 004 000 00000000 000000 0-0
ss  0012 004 000 00000000 000000 0-0
ss  0013 004 000 00000000 000000 0-0
ss  0014 004 000 00000000 000000 0-0
ss  0015 004 000 00000000 000000 0-0
PS C:\Users\alexa>

Should those symlinks be part of the usbip install?

@stfnx
Copy link

stfnx commented Nov 10, 2023

I have the latest WSL version:

WSL-Version: 2.0.7.0
Kernelversion: 5.15.133.1-1
WSLg-Version: 1.0.59
MSRDC-Version: 1.2.4677
Direct3D-Version: 1.611.1-81528511
DXCore-Version: 10.0.25880.1000-230602-1350.main
Windows-Version: 10.0.19045.3570

And I've installed the latest usbipd 3.2.0 on the Windows host.

I've tried to attach a device from Windows using the following command:

> usbipd wsl attach --distribution NixOS --hardware-id 20a0:4109
usbipd: info: Device with hardware-id '20a0:4109' found at busid '4-4'.
usbipd: error: WSL 'usbip' client not correctly installed. See https://github.com/dorssel/usbipd-win/wiki/WSL-support for the latest instructions.

And running usbip to attach from within WSL doesn't work either, because usbip command isn't found on my NixOS WSL installation.

Which NixOS package am I supposed to install to get the usbip command?

edit: here I found the answer. its pkgs.linuxPackages.usbip

@nzbr
Copy link
Member

nzbr commented Nov 20, 2023

You should now (on the latest commit on main at least) be able to use usbip, by setting wsl.usbip.enable = true

@PixelyIon
Copy link

Just setting wsl.usbip.enable = true results in usbipd: error: WSL kernel is not USBIP capable; update with 'wsl --update'. when trying to attach a device. The symlinks from a prior comment need to be done too:

sudo ln -s /run/current-system/sw/bin/cat /usr/bin
sudo ln -s /run/current-system/sw/bin/usbip /usr/bin

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

7 participants