Fedora 38 Setup - Part IV - WSL

Fedora 38 Setup - Part IV - WSL

From time to time, I need to use a windows laptop to run a native program there. Nowadays, Windows allows us to have a Linux kernel running as a subsystem. There are plently of examples on how to install Ubuntu, as its available in the Windows Store. However as discussed previously, I like much better Fedora.

In this post I document how to setup Fedora 38 in WSL. The setup is based on information from Install WSL | Microsoft Learn and from Install Fedora 37 or earlier on Windows Subsystem for Linux (WSL) - DEV Community.

Installing Fedora 38 Container Based Build

  1. Ensure that Virtual Maschine is enabled in the BIOS and in Windows. For the first step follow the computer manufacturer. Then follow the steps in Install WSL | Microsoft Learn.

  2. Ensure WSL2 is running in Windows:

    wsl --set-default-version 2
    

    If errors arise, consult google or youtube to find how to setup WSL 2 in windows. Just search for How to setup WSL2. As an alternative you can read Install WSL | Microsoft Learn.

  3. Download the latestest Fedora Container Base build from Koji Fedora eg. Fedora-Container-Base-38-20230619.0. Be sure that the State has a green check mark and not a yellow X or red -. As this mean that the build was either canlleded or failed. Download the Fedora-Container-Base-38-20230619.0.x86_64.tar.xz file and extract it, eg. WinRar. The content from the folder with the HEX name should containt the layer.tar file. This is the required file to install Fedora.

  4. Create a folder where Fedora will be installed. eg: C:\Users\User\AppData\Local\WSL2\Fedora38

  5. Import the Fedora distribution into WSL. In this example, I am naming it Fedora38

    wsl --import Fedora38 C:\Users\User\AppData\Local\WSL2 C:\Users\User\Downloads\layer.tar
    
  6. Now review the installed distros:

    wsl -l -v
      NAME        STATE           VERSION
    * Ubuntu      Stopped         2
      Fedora38    Stopped         2
    

    In this case Ubuntu is also installed. the -v parameter checks for the version. Ensure it is 2. Remembered that it was setup like that in Step number 2.

  7. Setup the Fedora38 as the default distribution:

    wsl -s Fedora38
    
  8. To lunch it now just type

    wsl
    
  9. If you want to run other installed distro, eg. Ubuntu run:

    wsl -d Ubuntu
    

    Review the list of installed distros to find the correct name, see point 6.

  10. In widnows I use Oh My Posh with Windows Terminal, there you can open a Terminal with Fedora, Powershell, Ubuntu, etc.

  11. If you want to find which other distros can be installed from terminal run:

    wsl --list --online
    

Aferter install setup

There are additional steps to completelly setup Fedora in wsl. These are not required from distros on the online list.

  1. When running Fedora the first time, it will run as root. Be carefull on what you do.

  2. Update the distro

    dnf update
    

    If you cannot update the distro, there are issues resolving the DNS. See the Ensure DNS is functioning in the post Install Fedora 37 or earlier on Windows Subsystem for Linux (WSL) - DEV Community

  3. Install basic system utilities

    dnf install util-linux
    

    Exit the distro

    exit
    

    and therminate it in PowerShell:

    wsl -t Fedora38
    

    restart Fedora38

  4. It is not recomended to run root as default. Create a user with sudo previledges.

    dnf install passwd
    useradd -G wheel newuser
    passwd newuser
    

    Exit and reboot Fedora distro as in step 3.

  5. Lunch Fedora38 with the newuser

    wsl -u newuser
    
  6. If the seupt worked properly you should now see:

    [newuser@computername WindowsUser]$
    

    instead of

    [root@computername WindowsUser]$
    

    check for the sudo previledges:

    sudo cat /etc/shadow
    

    You should get the information regarding the users, it should include the newuser information.

  7. Setup the user as default login.

    printf "\n[user]\ndefault = newuser\n" | sudo tee -a /etc/wsl.conf
    

    This code adds the new user to the wsl.conf file

  8. Restart Fedora38 as in step 3. And you are done.

Additional Steps

The Fedora Container Base build has just the basic information lets install neofetch to find the current information

sudo dnf install neofetch
neofetch


             .',;::::;,'.                newuser@WINDOWS-COMPUTER-NAME
        .';:cccccccccccc:;,.            ---------------------
      .;cccccccccccccccccccccc;.         OS: Fedora Linux 38 (Container     
    .:cccccccccccccccccccccccccc:.       Kernel: 5.15.90.1-microsoft-st   
  .;ccccccccccccc;.:dddl:.;ccccccc;.     Uptime: 8 mins
 .:ccccccccccccc;OWMKOOXMWd;ccccccc:.    Packages: 417 (rpm)
.:ccccccccccccc;KMMc;cc;xMMc:ccccccc:.   Shell: bash 5.2.15
,cccccccccccccc;MMM.;cc;;WW::cccccccc,   Terminal: Windows Terminal
:cccccccccccccc;MMM.;cccccccccccccccc:   CPU: Intel i7-5500U (4) @ 2.39
:ccccccc;oxOOOo;MMM0OOk.;cccccccccccc:   Memory: 302MiB / 3868MiB
cccccc:0MMKxdd:;MMMkddc.;cccccccccccc;
ccccc:XM0';cccc;MMM.;cccccccccccccccc'
ccccc;MMo;ccccc;MMW.;ccccccccccccccc;
ccccc;0MNc.ccc.xMMd:ccccccccccccccc;
cccccc;dNMWXXXWM0::cccccccccccccc:,
cccccccc;.:odl:.;cccccccccccccc:,.
:cccccccccccccccccccccccccccc:'.
.:cccccccccccccccccccccc:;,..
  '::cccccccccccccc::;,.

There a re only 417 installed packages.

Install fedora documentation.

grep -v nodocs /etc/dnf/dnf.conf | sudo tee /etc/dnf/dnf.conf
sudo dnf install -y man man-pages

These ensure that the manual pages are installed. It requires to reinstall all packages.

for pkg in $(dnf repoquery --installed --qf "%{name}"); do sudo dnf reinstall -qy $pkg; done

Clean the installation

sudo dnf clean all

ZSH

Follow the steps in Fedora 38 Setup - KDE - Server Version | An Intersection of Engineering, Agriculture, Data Science and Innovation to setup ZSH

The following packages and steps are required.

dnf install util-linux-user
chsh -s $(which zsh)

Save the distribution

We can backup the distribution. It allows to save the distro current state. This is achived by running in PowerShell the following commands:

mkdir BackupWSL
cd .\BackupWSL
wsl --export Fedora38 20230626_Fedora38_WSL.tar 

The command takes several minutes. Be patient.