Skip to content

Instantly share code, notes, and snippets.

@startergo
Last active October 25, 2025 19:50
Show Gist options
  • Select an option

  • Save startergo/4428c78ace77d229357b4a205f38a57a to your computer and use it in GitHub Desktop.

Select an option

Save startergo/4428c78ace77d229357b4a205f38a57a to your computer and use it in GitHub Desktop.

Revisions

  1. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -125,7 +125,7 @@ export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}
    - [How to use the Microsoft Linux kernel v6 on Windows Subsystem for Linux version 2 (WSL2)](https://learn.microsoft.com/en-us/community/content/wsl-user-msft-kernel-v6)

    ```
    git clone https://github.com/microsoft/WSL2-Linux-Kernel
    git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth=1
    cd WSL2-Linux-Kernel
    git checkout `uname -r`
    cat /proc/config.gz | gunzip > .config
  2. startergo revised this gist May 8, 2024. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -123,3 +123,14 @@ export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}
    - Enable [Web Console](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_virtualization/managing-virtual-machines-in-the-web-console_configuring-and-managing-virtualization#setting-up-the-rhel-web-console-to-manage-vms_managing-virtual-machines-in-the-web-console)

    - [How to use the Microsoft Linux kernel v6 on Windows Subsystem for Linux version 2 (WSL2)](https://learn.microsoft.com/en-us/community/content/wsl-user-msft-kernel-v6)

    ```
    git clone https://github.com/microsoft/WSL2-Linux-Kernel
    cd WSL2-Linux-Kernel
    git checkout `uname -r`
    cat /proc/config.gz | gunzip > .config
    make prepare modules_prepare
    make menuconfig
    make modules
    make modules_install
    ```
  3. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-util
    network-manager iptables-persistent linux-headers-generic \
    qemu uml-utilities virt-manager git \
    wget libguestfs-tools p7zip-full make dmg2img tesseract-ocr \
    tesseract-ocr-eng genisoimage vim net-tools screen firewalld -y
    tesseract-ocr-eng genisoimage vim net-tools screen firewalld libncurses-dev -y
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo adduser `id -un` libvirt
  4. startergo revised this gist May 8, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -121,3 +121,5 @@ fi
    export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
    ```
    - Enable [Web Console](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_virtualization/managing-virtual-machines-in-the-web-console_configuring-and-managing-virtualization#setting-up-the-rhel-web-console-to-manage-vms_managing-virtual-machines-in-the-web-console)

    - [How to use the Microsoft Linux kernel v6 on Windows Subsystem for Linux version 2 (WSL2)](https://learn.microsoft.com/en-us/community/content/wsl-user-msft-kernel-v6)
  5. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -120,3 +120,4 @@ fi
    ```
    export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
    ```
    - Enable [Web Console](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_virtualization/managing-virtual-machines-in-the-web-console_configuring-and-managing-virtualization#setting-up-the-rhel-web-console-to-manage-vms_managing-virtual-machines-in-the-web-console)
  6. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-util
    network-manager iptables-persistent linux-headers-generic \
    qemu uml-utilities virt-manager git \
    wget libguestfs-tools p7zip-full make dmg2img tesseract-ocr \
    tesseract-ocr-eng genisoimage vim net-tools screen -y
    tesseract-ocr-eng genisoimage vim net-tools screen firewalld -y
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo adduser `id -un` libvirt
  7. startergo revised this gist May 8, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -14,15 +14,15 @@ newgrp libvirt
    ```
    https://medium.com/codemonday/setup-virt-manager-qemu-libvert-and-kvm-on-ubuntu-20-04-fa448bdecde3

    - Change the default group of `/dev/kvm`:
    - To enable systemd:
    ```
    sudo nano /etc/wsl.conf
    ```
    In the file `/etc/wsl.conf` add these lines:

    ```
    [boot]
    command = /bin/bash -c 'chown -v root:kvm /dev/kvm && chmod 660 /dev/kvm'
    systemd=true
    ```

    - Enable nested virtualization. Create [.wslcongfig](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig).
  8. startergo revised this gist May 8, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,11 @@
    - In WSL2 run:
    ```
    sudo apt update
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker network-manager iptables-persistent linux-headers-generic
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker \
    network-manager iptables-persistent linux-headers-generic \
    qemu uml-utilities virt-manager git \
    wget libguestfs-tools p7zip-full make dmg2img tesseract-ocr \
    tesseract-ocr-eng genisoimage vim net-tools screen -y
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo adduser `id -un` libvirt
  9. startergo revised this gist May 8, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -111,4 +111,8 @@ if [ -n "$HEADERS_DIR" ]; then
    echo "Create symbolic link $WSL2_LINK => $HEADERS_DIR"
    ln -s "$HEADERS_DIR" "$WSL2_LINK"
    fi
    ```
    ```
    - [Install X410 (version3)](https://x410.dev/cookbook/wsl/using-x410-with-wsl2/). Start and configure. Run this in WSL2:
    ```
    export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
    ```
  10. startergo revised this gist May 8, 2024. 1 changed file with 41 additions and 0 deletions.
    41 changes: 41 additions & 0 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -70,4 +70,45 @@ export LIBGL_ALWAYS_INDIRECT=1
    - Unregister wsl `Pengwin`:
    ```
    wsl --unregister WLinux
    ```
    - Link Linux headers to WSL:
    ```
    #!/bin/bash
    set -e
    WSL2_VERSION=$(uname -r)
    echo "WSL2_VERSION = $WSL2_VERSION"
    WSL2_LINK="/lib/modules/$WSL2_VERSION"
    if [ -L "${WSL2_LINK}" ]; then
    if [ -e "${WSL2_LINK}" ]; then
    echo "Good link"
    exit 0
    else
    echo "Broken link"
    rm "${WSL2_LINK}"
    fi
    elif [ -e "${WSL2_LINK}" ]; then
    echo "Not a link"
    exit 1
    else
    echo "Missing"
    fi
    shopt -s nullglob
    for filename in /lib/modules/*; do
    echo "$filename"
    if [ -z "$HEADERS_DIR" ]; then
    HEADERS_DIR="$filename"
    else
    echo "HEADERS_DIR already set to $HEADERS_DIR, fail"
    exit 1
    fi
    done
    if [ -n "$HEADERS_DIR" ]; then
    echo "Create symbolic link $WSL2_LINK => $HEADERS_DIR"
    ln -s "$HEADERS_DIR" "$WSL2_LINK"
    fi
    ```
  11. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    - In WSL2 run:
    ```
    sudo apt update
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker network-manager iptables-persistent
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker network-manager iptables-persistent linux-headers-generic
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo adduser `id -un` libvirt
  12. startergo revised this gist May 8, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -67,7 +67,7 @@ dpkg: dependency problems prevent configuration of mdevctl:
    export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
    export LIBGL_ALWAYS_INDIRECT=1
    ```
    - Restore IPtables:
    - Unregister wsl `Pengwin`:
    ```
    iptables-restore < /etc/iptables/rules.v4
    wsl --unregister WLinux
    ```
  13. startergo revised this gist May 8, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    - In WSL2 run:
    ```
    sudo apt update
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker network-manager
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker network-manager iptables-persistent
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo adduser `id -un` libvirt
    @@ -67,3 +67,7 @@ dpkg: dependency problems prevent configuration of mdevctl:
    export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
    export LIBGL_ALWAYS_INDIRECT=1
    ```
    - Restore IPtables:
    ```
    iptables-restore < /etc/iptables/rules.v4
    ```
  14. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    - In WSL2 run:
    ```
    sudo apt update
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker network-manager
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo adduser `id -un` libvirt
  15. startergo revised this gist May 8, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -62,4 +62,8 @@ dpkg: dependency problems prevent configuration of mdevctl:
    ```
    - Install [Nvidia CUDA WSL drivers](https://docs.nvidia.com/cuda/wsl-user-guide/index.html)


    - If xfce4 is giving error run:
    ```
    export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
    export LIBGL_ALWAYS_INDIRECT=1
    ```
  16. startergo revised this gist May 8, 2024. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -54,11 +54,12 @@ dpkg: dependency problems prevent configuration of mdevctl:
    ```
    /sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link
    ```
    - Then, in WSL the primary fix seems to be to delete `libcuda.so` and `libcuda.so.1` from `C:\Windows\System32\lxss\lib` as an `Administrator` in Windows (not from `WSL`).Then, in` WSL`:
    ```
    sudo ln -sr /mnt/c/Windows/System32/lxss/lib/libcuda.so.1.1 /mnt/c/Windows/System32/lxss/lib/libcuda.so.1
    sudo ln -sr /mnt/c/Windows/System32/lxss/lib/libcuda.so.1.1 /mnt/c/Windows/System32/lxss/lib/libcuda.so
    ```
    - Or better yet install [Nvidia CUDA WSL drivers](https://docs.nvidia.com/cuda/wsl-user-guide/index.html)


    - Then, in WSL the primary fix seems to be to delete `libcuda.so` and `libcuda.so.1` from `C:\Windows\System32\lxss\lib` as an `Administrator` in Windows (not from `WSL`):
    ```
    cd C:\Windows\System32\lxss\lib && del libcuda.so && del libcuda.so.1 && mklink libcuda.so libcuda.so.1.1 && mklink libcuda.so.1 libcuda.so.1.1
    ```
    - Install [Nvidia CUDA WSL drivers](https://docs.nvidia.com/cuda/wsl-user-guide/index.html)


  17. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ sudo adduser `id -un` libvirt
    sudo adduser `id -un` kvm
    newgrp libvirt
    ```
    https://medium.com/codemonday/setup-virt-manager-qemu-libvert-and-kvm-on-ubuntu-20-04-fa448bdecde3

    - Change the default group of `/dev/kvm`:
    ```
  18. startergo revised this gist May 8, 2024. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,12 @@
    - In WSL2 run:
    ```
    sudo apt update
    sudo apt install qemu qemu-kvm bridge-utils cpu-checker
    sudo apt install qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo usermod -a -G kvm ${USER}
    sudo adduser `id -un` libvirt
    sudo adduser `id -un` kvm
    newgrp libvirt
    ```

    - Change the default group of `/dev/kvm`:
  19. startergo revised this gist May 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ dpkg: dependency problems prevent configuration of mdevctl:
    ```
    /sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link
    ```
    - TThen, in WSLhe primary fix seems to be to delete libcuda.so and libcuda.so.1 from C:\Windows\System32\lxss\lib as an Administrator in Windows (not from WSL).Then, in WSL:
    - Then, in WSL the primary fix seems to be to delete `libcuda.so` and `libcuda.so.1` from `C:\Windows\System32\lxss\lib` as an `Administrator` in Windows (not from `WSL`).Then, in` WSL`:
    ```
    sudo ln -sr /mnt/c/Windows/System32/lxss/lib/libcuda.so.1.1 /mnt/c/Windows/System32/lxss/lib/libcuda.so.1
    sudo ln -sr /mnt/c/Windows/System32/lxss/lib/libcuda.so.1.1 /mnt/c/Windows/System32/lxss/lib/libcuda.so
  20. startergo revised this gist May 8, 2024. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -47,3 +47,15 @@ dpkg: dependency problems prevent configuration of mdevctl:
    ```
    sudo mv /var/lib/dpkg/info/udev.postinst /var/lib/dpkg/info/udev.postinst.backup
    ```
    - If you get:
    ```
    /sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link
    ```
    - TThen, in WSLhe primary fix seems to be to delete libcuda.so and libcuda.so.1 from C:\Windows\System32\lxss\lib as an Administrator in Windows (not from WSL).Then, in WSL:
    ```
    sudo ln -sr /mnt/c/Windows/System32/lxss/lib/libcuda.so.1.1 /mnt/c/Windows/System32/lxss/lib/libcuda.so.1
    sudo ln -sr /mnt/c/Windows/System32/lxss/lib/libcuda.so.1.1 /mnt/c/Windows/System32/lxss/lib/libcuda.so
    ```
    - Or better yet install [Nvidia CUDA WSL drivers](https://docs.nvidia.com/cuda/wsl-user-guide/index.html)


  21. startergo revised this gist May 7, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ dpkg: dependency problems prevent configuration of mdevctl:
    Package udev is not configured yet.
    ```

    - It can be fixwd with:
    - It can be fixed with:
    ```
    sudo mv /var/lib/dpkg/info/udev.postinst /var/lib/dpkg/info/udev.postinst.backup
    ```
  22. startergo created this gist May 7, 2024.
    49 changes: 49 additions & 0 deletions KVM_in_WSL2.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    - In WSL2 run:
    ```
    sudo apt update
    sudo apt install qemu qemu-kvm bridge-utils cpu-checker
    sudo apt install virt-manager
    sudo addgroup kvm
    sudo usermod -a -G kvm ${USER}
    ```

    - Change the default group of `/dev/kvm`:
    ```
    sudo nano /etc/wsl.conf
    ```
    In the file `/etc/wsl.conf` add these lines:

    ```
    [boot]
    command = /bin/bash -c 'chown -v root:kvm /dev/kvm && chmod 660 /dev/kvm'
    ```

    - Enable nested virtualization. Create [.wslcongfig](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig).

    - Add this section to the `.wslconfig` file

    ```
    [wsl2]
    nestedVirtualization=true
    ```

    - Restart WSL:
    ```
    wsl.exe --shutdown
    ```

    - Got an error:
    ```
    Setting up udev (252.22-1~deb12u1) ...
    addgroup: The group `kvm' already exists and is not a system group. Exiting.
    dpkg: error processing package udev (--configure):
    installed udev package post-installation script subprocess returned error exit status 1
    dpkg: dependency problems prevent configuration of mdevctl:
    mdevctl depends on udev; however:
    Package udev is not configured yet.
    ```

    - It can be fixwd with:
    ```
    sudo mv /var/lib/dpkg/info/udev.postinst /var/lib/dpkg/info/udev.postinst.backup
    ```