I was following a tutorial from "The Missing Semester" here (timestamp included in link). There was supposed to be an led
directory in /sys/class
. I am using WSL2 and I could not find any such directory. Does WSL hide some of the /sys/class
locations? And is there any way accessing those without having to dual boot my machine?
Well ... maybe, if your keyboard is USB, but it looks like even then it will take some effort. If it's a laptop with a keyboard that connects internally via a non-USB bus, then AFAIK, it's not possible.
There are two versions of WSL, and neither one will allow this "out of the box".
At a high-level, WSL1 "converts/translates" Linux syscalls into the Windows equivalent. It's kind of a "reverse WINE" in that sense. On the positive side, this does allow it to directly access some physical hardware, but typically only in limited ways.
For instance,
ip link
in WSL1 will show all network interfaces available to Windows, but you cannot bring them up or down or really have any other control over them.On WSL1, I do have a
/sys/class/backlight
(mentioned right before the timestamp in the video), but there's nobrightness
in there. And I do not have an/sys/class/backlight/led
on WSL1 either.In WSL1, Microsoft focused on the 85% of Linux syscalls that would allow developers to accomplish 99% of their normal activities. That just doesn't include some of the more "corner-case" things like setting the keyboard LEDs, unfortunately.
WSL2 does use a real Linux kernel with minor changes (contributed back upstream, AFAIK) to support the interop between Windows and Linux. You can find the repo here.
The challenge with doing this under WSL2 is that Ubuntu is essentially running as a container in a set of namespaces inside the WSL2 VM (that you don't have access to). Inside that VM, there's limited access to physical hardware, including of course your keyboard and its associated LEDs. Windows itself provides the keyboard input to Ubuntu through [ Console / Windows Terminal / WSLg / third-party X server / etc. ]. Ubuntu doesn't see a keyboard device or LEDs.
However, as @muru mentions via a link in the comments, WSL2 does have the ability to connect to USB devices through USB/IP. Essentially, you install usbipd-win in Windows, share the device there, and connect to it via
usbip
in Ubuntu. This is all fairly automated so that you can usually do it via a single command in Windows/PowerShell, which then sets up both ends of the connection for you.Unfortunately, even with this in place (I already have USB/IP configured), and my USB keyboard shared to Ubuntu, there's still no
/sys/class/led
.I believe this may be because the WSL2 kernel is not configured with
CONFIG_NEW_LEDS
.You can configure and compile your own WSL2 kernel using those sources, but I cannot tell you for sure that this will allow you to control the LEDs on your USB keyboard over USB/IP.
Also (important) side-note that, if you share the keyboard over USB/IP, you may lose access to it under Windows, which means you have no more ability to type. I didn't notice this at first, since I was connected via Remote Desktop to the system with my USB keyboard, but when I returned, I found myself "locked out" to some degree. Just make sure that you have the Windows on-screen-keyboard (enable "Touch keyboard" in the Taskbar settings) so that you have fallback input with which to subsequently detach the keyboard from USB/IP.