Windows Virtualization ====================== .. contents:: Table of Contents Windows Subsystem for Linux (WSL) --------------------------------- WSL 1 translated Linux system calls to Windows. This is essentially the opposite of the Wine project that is used to translate Windows system calls to Linux. Due to performance, stability, and compatibility concerns, WSL 1 is no longer used. WSL 2 is used by default. It creates a Hyper-V virtual machine instead. WSL is supported on Windows 10 and 11. Open a Command Prompt as the Administrator user. Run this command to view the list of Linux distributions that can be installed. :: C:\Windows\System32>wsl --list --online This is the list of officially supported Linux distributions: - Debian - Kali Linux - Oracle Linux - SUSE Linux Enterprise Server (SLES) - Ubuntu Select the operating system to install. By default, if no Linux distribution is provided to the command, Ubuntu will be installed. :: C:\Windows\System32>wsl --install -d Reboot to finish the installation. Then open a Command Prompt and run either ``bash`` or ``wsl`` to open a Linux terminal. [1] On Windows 11, there is a false-positive report from the control flow guard (CFG) protection that prevents WSL 2 from starting. Disable it to be able to use WSL 2. [2] - Windows Security (windowsdefender:) > App & browser control > Exploit protection settings > Control flow guard (CFG): Off by default Fedora ~~~~~~ There are no official images of Fedora for WSL. Automatic Set Up ^^^^^^^^^^^^^^^^ - Install and open the unofficial `Fedora WSL `__ image from the Microsoft Store. The source code can be found `here `__. [3] Manual Set Up ^^^^^^^^^^^^^ It is possible to use a container image for the root file system of Fedora and then import it into WSL 2. [4] Run a Fedora container and then save the root file system. :: C:\Users\ docker run --name fedora40 fedora:40 C:\Users\ docker export -o fedora-40-rootfs.tar fedora40 Import the root file system. :: C:\Users\> mkdir $HOME\wsl\fedora C:\Users\> wsl --import fedora $HOME\wsl\fedora $HOME\Downloads\fedora-40-rootfs.tar C:\Users\> wsl -d fedora Configure DNS resolvers. :: [root@ fedora]# echo -e "[network]\ngenerateResolvConf = false" > /etc/wsl.conf [root@ fedora]# exit C:\Users\> wsl -t fedora C:\Users\> wsl -d fedora [root@ fedora]# unlink /etc/resolv.conf [root@ fedora]# echo nameserver 1.1.1.1 > /etc/resolv.conf Upgrade Fedora. :: [root@ fedora]# dnf upgrade Install the minimum packages required for user accounts and WSL mounts to work. :: [root@ fedora]# dnf install cracklib-dicts passwd util-linux Configure a new user. :: [root@ fedora]# useradd -G wheel [root@ fedora]# passwd [root@ fedora]# printf "\n[user]\ndefault = \n" | sudo tee -a /etc/wsl.conf [root@ fedora]# exit C:\Users\> wsl -t fedora Verify that the new user works. :: C:\Users\> wsl -d fedora -u [@ fedora]$ whoami [@ fedora]$ sudo whoami root In PowerShell, configure the WSL distribution name and the user ID. :: C:\Users\> Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq fedora | Set-ItemProperty -Name DefaultUid -Value 1000 Fix permission issues related to user accounts. :: [@ fedora]$ sudo dnf reinstall shadow-utils Enable ping support. - Fedora: :: [@ fedora]$ sudo dnf install procps-ng iputils [@ fedora]$ sudo sysctl -w net.ipv4.ping_group_range="0 2000" - Windows: :: C:\Users\> echo [wsl2] >> .wslconfig C:\Users\> echo kernelCommandLine = sysctl.net.ipv4.ping_group_range=\"0 2000\" >> .wslconfig Enable manual pages for new package installations. :: [@ fedora]$ grep -v nodocs /etc/dnf/dnf.conf | sudo tee /etc/dnf/dnf.conf [@ fedora]$ sudo dnf install man man-pages Optionally re-install existing packages to install their manual pages. :: [@ fedora]$ for pkg in $(dnf repoquery --installed --qf "%{name}"); do sudo dnf reinstall -qy $pkg; done Optionally export the fully configured WSL file system. :: [@ fedora]$ sudo dnf clean all [@ fedora]$ exit C:\Users\> wsl --export fedora C:\Users\\Downloads\fedora-40-wsl.tar History ------- - `Latest `__ Bibliography ------------ 1. "Install Linux on Windows with WSL." Microsoft Learn Technical documentation. January 12, 2023. Accessed February 6, 2023. https://learn.microsoft.com/en-us/windows/wsl/install 2. "The operation could not be started because a required feature is not installed #4951." GitHub microsoft/WSL. May 23, 2022. Accessed February 6, 2023. https://github.com/microsoft/WSL/issues/4951 3. "How to install Fedora on WSL for Windows 10 and Windows 11." Windows Central. July 8, 2023. Accessed April 21, 2024. https://www.windowscentral.com/software-apps/how-to-install-fedora-on-wsl-for-windows-10-and-windows-11 4. "Install Fedora 37 or earlier on Windows Subsystem for Linux (WSL)." DEV Community Jonathan Bowman. October 29, 2022. Accessed April 21, 2024. https://dev.to/bowmanjd/install-fedora-on-windows-subsystem-for-linux-wsl-4b26