3

I am currently struggling with v4l2loopback installation on WSL2.

Some context:

Recently, I have read about create a virtual video device in Linux and then mock its output from an image or video file.

This is quite important for testing or developing purposes, for example in order to attach a virtual webcam that reproduces a video file as a loop to the android emulator.

After some research I got to the conclusion I don't want to use desktop applications and it might be easy to run even in a CI or similar, therefore v4l2loopback looks nice, but I am currently a Windows user.

I enabled WSL2 on my machine, downloaded the repo, and tried to execute make command like in the repo description.

Building v4l2-loopback driver...
make -C /lib/modules/`uname -r`/build M=/home/angel/v4l2loopback modules
make[1]: *** /lib/modules/4.19.84-microsoft-standard/build: No such file or directory.  Stop.
make: *** [Makefile:43: v4l2loopback.ko] Error 2

I googled a little bit and i found that issue on GitHub where a similar output (for another tool) is mentioned. There, someone mentioned that WSL2 Kernel Config can be adjusted in order to add more modules ( maybe and hopefully one of them could make work v4l2-loopback or at least that I think).

I also googled in order to check out custom WSL builds but I am not really sure what I need to make it work or even if I am going in the right direction.

Is there something I 've missed in order to make v4l2loopback work?

In the case only a custom WSL2 build would work, how should I proceed?

Thanks in advance

Angel Fraga Parodi
  • 750
  • 10
  • 20
  • You will at least also need the kernel development headers. –  Aug 01 '20 at 21:16
  • Hi @Roadowl, thanks for answering, do you mean I should install something else in the WSL2 instance ? could you extend a little bit your answer? I m not familiar with Linux kernel stuff. – Angel Fraga Parodi Aug 01 '20 at 21:26
  • I am not familiar with WSL, but maybe this might be more enlightening to you: https://github.com/microsoft/WSL/issues/4128, https://learn.microsoft.com/en-us/windows/wsl/wsl2-kernel. –  Aug 01 '20 at 21:29
  • First you need to know the linux version you are running. On the cli, do `uname -a`. For that kernel-version, you need the kernel development headers. In you package manager, search for 'kernel development headers' (or 'kernel development'). Then try to build the v4lloopback module. –  Aug 01 '20 at 21:31
  • 1
    Ah -- it appears WSL doesn't have a linux kernel at all: see https://unix.stackexchange.com/questions/594470/wsl-2-does-not-have-lib-modules . So it's useless building the v4lloopback mod, since even if you'd be able to build it, there's nothing to load it on. Maybe an alternative for you might be running virtualbox on your windows machine, and load a real linux distro of your own choice in it. Then build the mod (after installing the kernel development headers). –  Aug 01 '20 at 21:43
  • Thus, you are on your way. Far more elegant, and far easier. Also will have you make an enormous and important climb on the 'getting familiar with Linux' ladder. I'd go for that. –  Aug 01 '20 at 21:44
  • @Roadowl wow thanks, I think I am currently understanding what is going on with WSL2 and its modules. Thanks again please feel free to summarize all your comments as one valid answer. – Angel Fraga Parodi Aug 01 '20 at 22:04
  • @AngelFragaParodi now that Roadowl has posted there answer, please *accept* it (so the question no longer shows up as "needs attention") – umläute Sep 21 '20 at 15:21

1 Answers1

3

I am not familiar with WSL...

-- Ah, it appears WSL doesn't have a linux kernel at all: see https://unix.stackexchange.com/questions/594470/wsl-2-does-not-have-lib-modules . So it's useless building the v4l2loopback mod; even if you'd be able to build it, there's nothing, no kernel, to load it!

Maybe an alternative for you might be running Virtualbox (it's free, and available for Windows) on your windows machine, and load a real Linux distro of your own choice in it. Then build the v4l2loop module, after installing the kernel development headers, and install the mod (after building, as root do insmod v4l2loop.ko) and play with it.

Thus, you are on your way. Far more elegant, and far easier. Also will have you make an enormous and important climb on the 'getting familiar with Linux' ladder, as well as maybe familiarize yourself with a virtual machine(?).

I'd definitely go for that.

  • Nice answer(+1) ! FWIW, another workaround I've used, less elegant though, was to stream the USB camera as if it's an IP camera, then open that stream from localhost on the WSL side. Not ideal, but could be ok for some basic tests. – George Profenza Nov 04 '21 at 13:42