C4_W2_Lab_2: WSL2/Debian: VirtualBox: This system is currently not set up to build kernel modules

Hi.

I’m having trouble getting the VirtualBox driver to work.

I installed VirtualBox in WSL2/Debian according to Linux_Downloads – Oracle VM VirtualBox

sudo apt-get update
sudo apt-get install virtualbox-6.1

Everything went smoothly. But at the end the following message appeared:

This system is currently not set up to build kernel modules.
Please install the Linux kernel “header” files matching the current kernel for adding new hardware support to the system.

The current kernel is 5.15.90.1-microsoft-standard-WSL2

Where and how do I get the mentioned “header” files matching this kernel? And I guess I will need the kernel sources as well.

Any help is greatly appreciated.

OK, I found the headers and sources I guess:

Release linux-msft-wsl-5.15.90.1 · microsoft/WSL2-Linux-Kernel (github.com)

But how do I get them in the right place in Debian?

If I had a “proper” Debian installation with a kernel provided by the Debian distribution, I would use Debians package manager (aptitude). But how do I handle a .tar.gz file?

OK, I think I found a way to “install headers”:

  1. I downloaded the the Source code (tar.gz) file of the linux-msft-wsl-5.15.90.1 release from github Releases · microsoft/WSL2-Linux-Kernel (github.com)

  2. Then I put the .tar.gz file in my home directory of the Debian WSL2.

  3. I unpacked the .tar.gz file in the same directory

  4. In the resulting directory structure, there is a Folder Documentation/kbuild which contains a file headers_install.rst

  5. This file tells how to install headers. Basically it is simply running the following command while being in the “top level directory of the kernel source code”

sudo make headers_install INSTALL_HDR_PATH=/usr

So far, so good. But still: Running

sudo /sbin/vboxconfig

again yields an error message:

This system is currently not set up to build kernel modules.
Please install the Linux kernel “header” files matching the current kernel for adding new hardware support to the system.

I continue investigating…

Hello @Felix_Schneider try specifying the path to the header files explicitly like this

sudo make headers_install INSTALL_HDR_PATH=/usr/src/linux-headers-$(uname -r)

’ replace <kernel-version> with the actual version number of the kernel.’

You can also try to install the necessary packages to build kernel modules and headers:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential linux-headers-$(uname -r)

Hello @Isaak_Kamau,

thanks so much for your response. I really appreciate it.

Installing the headers under /usr/src is a good idea. But

$ sudo /sbin/vboxconfig
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system.

Where should I replace <kernel-version> with the actual version number of the kernel? What is the actual version number of the kernel?

$ uname -r 
5.15.90.1-microsoft-standard-WSL2
$ sudo apt-get install linux-headers-$(uname -r)
E: Unable to locate package linux-headers-5.15.90.1-microsoft-standard-WSL2
E: Couldn't find any package by glob 'linux-headers-5.15.90.1-microsoft-standard-WSL2'
E: Couldn't find any package by regex 'linux-headers-5.15.90.1-microsoft-standard-WSL2'

My /etc/apt/sources.list file reads:

deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://security.debian.org/debian-security bullseye-security main
deb http://ftp.debian.org/debian bullseye-backports main
deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian bullseye contrib

Hi @Felix_Schneider
I think the error might be because 5.15.90.1-microsoft-standard-WSL2 ) is a Microsoft-specific kernel, and the corresponding kernel header packages may not be available in the Debian repositories.
I found some more solutions here: linux kernel - WSL 2 does not have /lib/modules/ - Unix & Linux Stack Exchange

If also the above solution fails you can try to install the necessary kernel headers by manual approach by downloading and installing them from the Microsoft GitHub repository like this:

  1. Go to the Microsoft/WSL2-Linux-Kernel GitHub repository: GitHub - microsoft/WSL2-Linux-Kernel: The source for the Linux kernel used in Windows Subsystem for Linux 2 (WSL2).
  2. In the repository, navigate to the “Releases” section.
  3. Look for the release that matches your kernel version (5.15.90.1). Click on it to access the release page.
  4. On the release page, you’ll find the header files in a .deb package format. Download the appropriate package based on your architecture (e.g., linux-headers-5.15.90.1-wsl_5.15.90.1-wsl-1_amd64.deb for 64-bit architecture).
  5. Once the package is downloaded, open a terminal and navigate to the directory where the package is located.
  6. Install the downloaded package using the dpkg command. Replace <package-name> in the command with the actual package name you downloaded:
sudo dpkg -i <package-name>.deb
  1. After the installation completes, try running sudo /sbin/vboxconfig again to see if the error is resolved.

Let me know if there’s any progress after you have tried all the above methods.

Hi @Isaak_Kamau

thanks very much for the effort you put into helping me with this issue.
I will be busy this week and not able to try your suggestions. Please be patient until next week.
You will be hearing from me then…

In the meantime, I carefully read the instructions in the Lab text. There are some remarks about problems that windows users might encounter.

I decided to give up on trying to get virtual box to run in WSL, but on Windows itself, but there I encountered another problem: VirtualBox does not detect that hardware support for virtualization is activated in the BIOS of my Laptop. But Hyper-V does. This must be a problem between VirtualBox and my Hardware/BIOS.

After all, I think that getting a VM (VirtualBox) to run on another VM (WSL2) is quite some “advanced setup” and quite a challenge for me. This sound like “nested VMs” to me…

Anyway I will get back to your suggestions next week.

Hey, @Felix_Schneider
I have never tried nested virtualization, but if virtualization support is enabled in your laptop’s BIOS settings, then I think there could be some hypervisor conflicts (Try disabling Hyper-V temporarily may allow VirtualBox to detect virtualization support). Also, CPU compatibility is another factor of consideration according to this blog:

Hi @Isaak_Kamau
I still owe you feedback to your suggestion for compiling a module in a Microsoft kernel running in WSL.
Bad news is, I didn’t try :frowning: so I can’t confirm that my problem is solved.
The reason is that I have so many open projects that I have to prioritize tasks. And getting a virtual machine to run in another virtual machine unfortunately has not high priority.
Actually I was on the same track as you. The documentation that accompanies the kernel sources should have all what is needed. But I don’t want to dive that deep in the linux custom kernel compilation and installation issues.
I hope for your understanding.
Best wishes,
Felix