相关文章推荐

Stack Exchange Network

Stack Exchange network consists of 182 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have WSL 1 installed on my Windows 10 machine in which Ubuntu 20.04 is installed. My CPU supports hardware virtualization. I followed instructions here to try to install KVM, but when I run "virsh list --all", I got

error: failed to connect to the hypervisor
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory

The output of kvm-ok is

INFO: /dev/kvm does not exist
HINT:   sudo modprobe kvm_intel
modprobe: FATAL: Module msr not found in directory /lib/modules/4.4.0-17134-Microsoft

So, is it because WSL 1 can't install KVM? kvm is ok only on WSL 2?

No. KVM is a Linux kernel feature, and WSL1 doesn't have a Linux kernel; it imitates a Linux kernel, somewhat like Wine imitating the Windows environment. You cannot actually load Linux .ko modules into it.

This may be possible in WSL2 – in theory – as WSL2 runs a real Linux kernel and does so through Hyper-V, which supports "nested virtualization" if the CPU is also compatible, meaning that the WSL2 VM could itself run more VMs inside. However, I don't know if the standard Microsoft-provided Linux kernel (words you never thought you'd hear) is compiled with KVM support, but at least they have instructions for compiling a custom kernel.

It might also be possible to somehow convince your libvirtd to run Qemu on Windows, as Qemu actually supports running VMs through the Windows Hypervisor Platform (which is the Windows equivalent of KVM), so you could run WSL2 and qemu.exe -accel whpx side-by-side without them conflicting.

(Of course, Qemu on Windows can also use the Intel HAXM hypervisor with -accel hax.)

(Perhaps WSL1 could implement the /dev/kvm API in terms of Windows Hypervisor Platform, but it doesn't do that, and I don't think it's going to receive any new features given that the focus in WSL2.)

I have to stick to WSL1 because I can't upgrade to newer version of Windows. But your reply inspired me: why not create a VM of newer Windows 10 and install WSL2 in it? There is an article: boxofcables.dev/accelerated-kvm-guests-on-wsl-2. It is on WSL2 but I tried it on WSL1 before asking this question. I compiled the kernel successfully but failed at copying bzImage because there is no such folder. I'll try it again in the WSL2 in guest Windows. Thank you for your answer that enlivens my life. – zzzhhh Dec 3, 2021 at 14:36 @Daniel B: This article made it (see its screenshot): boxofcables.dev/accelerated-kvm-guests-on-wsl-2 – zzzhhh Dec 3, 2021 at 14:39
 
推荐文章