DEV Community

Cover image for Install Fedora 36 or earlier on Windows Subsystem for Linux (WSL)
Jonathan Bowman
Jonathan Bowman

Posted on • Updated on

Install Fedora 36 or earlier on Windows Subsystem for Linux (WSL)

Using Windows Subsystem for Linux (WSL), we have a choice of Linux distributions available in the Windows Store, such as Ubuntu, Kali, Debian, etc.

In addition to these, with WSL 2, installing custom distributions is fairly straightforward, even if they are not in the Windows Store:

  • find a rootfs for the distro
  • install with wsl --import in Windows Powershell or Command Prompt

Lately I rely on Fedora in WSL 2, and have been thoroughly pleased with that distribution. This article details the steps I use to get up and running with Fedora on WSL. By the way, if you prefer a nice out-of-box experience, take a look at the fine work by Whitewater Foundry with their Fedora Remix for WSL. But if you see "some assembly required" as an enticing invitation, read on.

Already have a previous version of Fedora on WSL 2, and just want to upgrade to the latest? I documented the steps involved in another article; feel free to take a look.

Prerequisite: WSL 2

Please note that these steps require WSL 2 (not version 1).

To run WSL 2, Windows version 1903 or higher is needed, with Build 18362 or higher. Most likely, you have a much later version than this already. To tell what version you are running, run winver in Powershell or CMD, or just type Win key and R (⊞-r) to open the Run dialog and then enter winver. Hopefully you will see something like "Version 21H2. OS Build 19044.1682". If on Windows 11, you needn't worry at all anyway, but the version should be something like "Version 21H2. OS Build 22000.469".

To check if you are running WSL 2, try this command:

wsl --set-default-version 2
Enter fullscreen mode Exit fullscreen mode

This will set the default version to WSL 2, or fail if you are still on the first version.

If it does neither and instead offers installation instructions, this may be your first time using WSL on this system.

Microsoft offers helpful installation instructions, including step-by-step instructions on how to upgrade to WSL 2.

In short, if you are comfortable installing another Linux distribution, running wsl --install will install the default latest Ubuntu, or you can pick from a list by using wsl -l -o then installing one with wsl --install -d Debian or, if not Debian, whichever distribution you would like.

If you are on an older version of Windows 10 or using WSL version 1, then the following Powershell command should get you to where you need (a reboot will likely be necessary).

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux,VirtualMachinePlatform -All
Enter fullscreen mode Exit fullscreen mode

Most likely, the wsl command will then instruct you to install a new kernel, so proceed to https://aka.ms/wsl2kernel and follow the instructions there.

Again, see Microsoft's instructions for a current and detailed version.

Obtain a rootfs image of Fedora

We first need a rootfs (the base filesystem for the Linux distro in question, in this case Fedora). There a few ways to get this.

Obtain rootfs from Fedora Container Base

The rootfs embedded in the Fedora Container Base project seems to work well, and is my preferred method, as it offers a lot of flexibility. I start with the most recent stable version of Fedora that auto-built successfully. If you want to be bleeding edge, you can download the latest Rawhide image that built successfully, but I am using the latest Fedora 36 for now. The "State" column indicates build success. Pick the latest with a green checkmark.

Find the right "xz" file for your platform (likely x86_64). Such as:

Unpack the Fedora-Container-Base-*.tar.xz file in your preferred manner. You might try 7-zip for this, extracting the .tar file, then extracting the contents of the .tar file. This, however, is not your rootfs. Further work is needed.

Once unpacked you will see a folder with a long hexadecimal name. Within that folder, there should be a layer.tar file. This is your rootfs. Copy the layer.tar file to a logical location, such as your Downloads folder. You may even want to rename it to something like fedora-33-rootfs.tar.

Alternative: download rootfs from docker-brew-fedora project

The docker-brew-fedora project imports "the official Fedora Docker Base Images built in Fedora Koji (Fedora's Build System) so that they may be submitted to the official-images repository for the Docker Hub."

To download, first pick your desired Fedora version from the active branches. For example, you might choose Fedora 36 and there find a file with a name like fedora-36-x86_64.tar.xz. Or use Fedora 35 and look for fedora-35-x86_64.tar.xz. Or go for Fedora 34 and locate fedora-34-x86_64.tar.xz. Download that file.

Unpack the fedora-3?-x86_64.tar.xz file in your preferred manner. You might try 7-zip for this, extracting the .tar file, then, if desired, renaming it to something like fedora-36-rootfs.tar.

Another rootfs alternative: use docker or podman and export

While this requires an extra tool, if you already have docker or podman available, then you can pull the Fedora image of your choosing and export the rootfs. In the following, if you have a Linux distro with podman available, you can substitute podman in place of docker.

docker run --name fedora36 fedora:36
docker export -o fedora-36-rootfs.tar fedora36
Enter fullscreen mode Exit fullscreen mode

First we create the container, name it "fedora36", then export the rootfs as "fedora-36-rootfs.tar". Afterward, you can certainly docker rm fedora36 to clean up.

You may be interested in my articles for configuring podman on WSL, or setting up Docker on WSL.

Make a folder for your WSL distro.

Once we have the rootfs, we can prepare to import it.

I like to use wsl in my home directory, so in this case I create that folder and a fedora folder within it. In Powershell, that's:

mkdir $HOME\wsl\fedora
Enter fullscreen mode Exit fullscreen mode

Install a new WSL Fedora distro

In Powershell, assuming you want to name the distro "fedora" and the folder is \$HOME\wsl\fedora and the rootfs is in Downloads, named "fedora-36-rootfs.tar":

wsl --import fedora $HOME\wsl\fedora $HOME\Downloads\fedora-36-rootfs.tar
Enter fullscreen mode Exit fullscreen mode

View installed distros

If this is the only WSL distro you now have, executing wsl -l should look something like this:

PS C:\Users\me> wsl -l
Windows Subsystem for Linux Distributions:
fedora (Default)
Enter fullscreen mode Exit fullscreen mode

Launch Fedora as root

wsl -d fedora
Enter fullscreen mode Exit fullscreen mode

Or, if Fedora is the default, simply wsl should result in a BASH prompt.

If you have multiple distros installed, and want Fedora to be set as the default, something like this should work:

wsl -s fedora
Enter fullscreen mode Exit fullscreen mode

Ensure DNS is functioning

DNS in WSL is interesting. By default, WSL will set the DNS server automatically, dynamically configuring /etc/resolv.conf. If your dns is resolving fine (does sudo dnf upgrade work for you?) then you can skip to the next section. It seems that it just works for most people.

For me, however, the dynamic /etc/resolv.conf has not worked consistently. I need to turn it off and configure resolv.conf manually.

Conveniently, WSL provides a means in /etc/wsl.conf to set some configuration settings specific to WSL.

In order for DNS to work, we will create our own resolv.conf, but first we create a new wsl.conf file and disable auto-generation of resolv.conf:

echo -e "[network]\ngenerateResolvConf = false" > /etc/wsl.conf
Enter fullscreen mode Exit fullscreen mode

Now exit WSL, then terminate it with

wsl -t fedora
Enter fullscreen mode Exit fullscreen mode

Then enter it again with

wsl -d fedora
Enter fullscreen mode Exit fullscreen mode

Now we can persist our custom DNS configuration. First, unlink /etc/resolv.conf. This covers cases in which /etc/resolv.conf is linked to systemd-resolved or resolvconf generated files. Then create a new /etc/resolv.conf with the nameserver(s) of your choice:

unlink /etc/resolv.conf
echo nameserver 1.1.1.1 > /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

Why not test network settings now with a system upgrade:

dnf upgrade
Enter fullscreen mode Exit fullscreen mode

If repositories are synced, you have success!

Missing the mount command?

If, at first entry to your new Fedora instance, you are greeted with An error occurred mounting one of your file systems, then that is a sign you are missing the util-linux package, which includes mount as well as other essential commands. Depending on the rootfs you installed, you may not receive any error, in which case you can proceed to the next section.

But if you do need mount, install util-linux (or, if you are going minimalist, just install util-linux-core).

dnf install -y util-linux
Enter fullscreen mode Exit fullscreen mode

Then exit, and terminate your fedora instance (this, in effect, causes a restart):

wsl -t fedora
Enter fullscreen mode Exit fullscreen mode

Launch Fedora as an unprivileged user

Just sayin': root should never be your default user. Let's create a normal user.

We are going to need passwd for this, and we might as well get the cracklib dicts for password checking, too. Install both, once you have launched Fedora:

dnf install -y passwd cracklib-dicts
Enter fullscreen mode Exit fullscreen mode

Now, create a new user; while we are at it, let's add them to the wheel group so the user can sudo (don't forget to replace "myusername" with something that makes sense for you):

useradd -G wheel myusername
Enter fullscreen mode Exit fullscreen mode

Then create a password for that user:

passwd myusername
Enter fullscreen mode Exit fullscreen mode

Now, exit WSL or launch a new Powershell window, then re-launch WSL with the new username:

wsl -d fedora -u myusername
Enter fullscreen mode Exit fullscreen mode

Success?

$ whoami
myusername
Enter fullscreen mode Exit fullscreen mode

Does sudo work?

sudo cat /etc/shadow
Enter fullscreen mode Exit fullscreen mode

If you see the list of users, including, toward the bottom, the one you recently added, then all is well!

Set the default user

It would be nice to enter your Fedora instance as the user you just created, rather than as root.

To enable this, assuming you have Windows build 18980 or later: simply add a user section to /etc/wsl.conf.

Something like this will work well if you do not already have that file, or a [user] section in it:

printf "\n[user]\ndefault = myusername\n" | sudo tee -a /etc/wsl.conf
Enter fullscreen mode Exit fullscreen mode

Then exit, and terminate your fedora instance, so that it starts fresh next time.

wsl -t fedora
Enter fullscreen mode Exit fullscreen mode

Launch WSL again, without specifying a user, and you should be that user, not root.

If that succeeded, then proceed to the next section.

But if on a version of Windows before build 18980, then you will instead need to edit the registry to set a default user.

In Fedora, the user you created likely has a user id of 1000, but you can check with id -u. Remember that number.

Back in Powershell you can set the default user by editing the Windows registry, changing "fedora" and "1000" to what you named your WSL distro and the user id, respectively:

Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq fedora  | Set-ItemProperty -Name DefaultUid -Value 1000
Enter fullscreen mode Exit fullscreen mode

Fine tuning

If you do container work, especially in userspace, you will likely want to reinstall shadow-utils, in order to fix sticky bits that weren't set properly in the rootfs:

sudo dnf reinstall -y shadow-utils
Enter fullscreen mode Exit fullscreen mode

If you like to ping servers to see if they are up, then these two steps may be necessary:

sudo dnf install -y procps-ng iputils
sudo sysctl -w net.ipv4.ping_group_range="0 2000"
Enter fullscreen mode Exit fullscreen mode

The second one allows group IDs all the through 2000 to be able to ping. You can check group IDs with getent group or see your primary group ID with id -g and make sure it is included in the range above.

You may also find other commands you are used to are missing from the sparse rootfs we installed. You may want to install iproute, findutils, ncurses, and others, like so:

sudo dnf -y install iproute findutils ncurses
Enter fullscreen mode Exit fullscreen mode

While the included vi is a useful text editor, you will likely want one that is either more robust or has a user interface that suits you. Good options include vim, micro, or nano. Pick one and install it with something like:

sudo dnf install -y micro
Enter fullscreen mode Exit fullscreen mode

From here, you can proceed to install packages, edit configurations, and customize your new distro to your heart's content!

A few good man pages

You want the docs? You can't handle the docs!

But if you can handle them, and can handle the extra storage space they will occupy, then you likely want man pages. Thanks to Martin Hinze for his good suggestions on how best to add man page functionality. This is an enhancement, rather than baked in, because we obtained a slimmed-down rootfs earlier.

First, ensure the nodocs option is not set in /etc/dnf/dnf.conf. You may edit out the tsflags=nodocs line yourself, or use the following:

grep -v nodocs /etc/dnf/dnf.conf | sudo tee /etc/dnf/dnf.conf
Enter fullscreen mode Exit fullscreen mode

Then install man and man-pages:

sudo dnf install -y man man-pages
Enter fullscreen mode Exit fullscreen mode

This will ensure you get man pages on every future dnf install; however, to add them in retroactively, you will want to dnf reinstall any package for which you want man pages. For instance, man dnf will yield nothing now. But try it again after sudo dnf reinstall -y dnf and you should have good results.

To reinstall all installed packages, try the following:

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

Don't repeat yourself

Once you have a pristine base system the way you want it, why not export a tarball that you can import later. I mean, I am honored if you want to read this article again and follow it step by step. But if you want life to be a little easier, you might try the following.

First, clean up downloaded packages, etc. within Fedora:

sudo dnf clean all
Enter fullscreen mode Exit fullscreen mode

Then, exit WSL and export the whole installation to a tarball:

wsl --export fedora $HOME\Downloads\fedora-wsl.tar
Enter fullscreen mode Exit fullscreen mode

You may want a different folder than Downloads; specify the location you desire.

Depending on what packages you installed, it may be as small as a quarter GB. You could gzip it if you want the storage size to be even smaller. Next time you want to start fresh, you can do something like this:

mkdir $HOME\wsl\freshfedora
wsl --import freshfedora $HOME\wsl\freshfedora $HOME\Downloads\fedora-wsl.tar
Enter fullscreen mode Exit fullscreen mode

Keep upgrading

Even if you have a prerelease, there should be no need to reinstall. Just keep upgrading; the process is pretty seamless:

sudo dnf upgrade
Enter fullscreen mode Exit fullscreen mode

For instance, if you decided to use Fedora 37 (you adventurer, you!), upgrade as often as you like with the above command, and you will eventually (by November of 2022, presumably) be at release.

Interested in further tinkering with WSL 2?

Other articles I have written on WSL:

Discussion (82)

Collapse
umineiro profile image
UMineiro • Edited on

To be able to setup the locale within fedora you need systemd. To get around this you can use the following (substitute en, en_US with your locale strings):

dnf -y install glibc-common glibc-locale-source glibc-langpack-en
localedef --force -f UTF-8 -i en_US en_US.UTF-8
Enter fullscreen mode Exit fullscreen mode

Additionally, you may want to install your locale resources, sucha as:

dnf -y install langpacks-core-en_US langpacks-en_US man-pages-en_US
Enter fullscreen mode Exit fullscreen mode

And don´t forget to check and change if necessary /etc/locale.conf and /etc/locales.conf

Collapse
bowmanjd profile image
Jonathan Bowman Author

Thanks for these tips! OK if I incorporate them into the article?

Collapse
umineiro profile image
UMineiro

Sure. Go ahead! Notice that I've edited the tip to add a last step.

Collapse
trens profile image
baldarrding

i don't know if this is helpful but i was bored so i made a script to run through the steps quickly. its not that good i know, but i was bored. worked for me.

#!/bin/bash
##
## wsl --import <Distro> <InstallLocation> <FileName> [Options]
##
## wsl --import fedora o:\wsl\fedora o:\wsl\fedora.36.base.layer.tar --version 2
## 
echo ""
echo ""
echo "You need to be root right now to do this."
echo "You will need to enter a username then a nameserver."
echo "like this: bash fstrap.fedora.wsl.from.rootfs.sh '1.1.1.1'"
echo ""
echo ""

if ! [ "${EUID:-$(id -u)}" -eq 0 ]; then
   echo ""
   echo "I am not root!"
   echo ""
   exit 1
fi


# uname_ is the username you want your username to be
uname_=$1
# dnsip0_ and dnsip1_ are the nameservers you want to use
dnsip0_=$2
dnsip1_=$3
rtest_="root"

if [ "$uname_" == "$rtest_" ]; then
   echo ""
   echo "you need to add a new user!"
   echo ""
   exit
fi

echo ""

if [ -z "$dnsip0_" ]; then
   echo ""
   echo "remember to include at least one nameserver like this bash script.sh username 'nameserverIP' "
   echo ""
   exit
fi
echo ""

grep -v nodocs /etc/dnf/dnf.conf | tee /etc/dnf/dnf.conf

echo ""
echo ""

# tells wsl to not set nameserver automatically
echo -e "[network]\ngenerateResolvConf=false" > /etc/wsl.conf
echo -e "\n[user]\ndefault=$uname_" >> /etc/wsl.conf 

# sets first namserver
echo "nameserver $dnsip0_" > /etc/resolv.conf

# sets second nameserver if its there
if [ -n "$dnsip1_" ]; then
   echo "nameserver $dnsip1_" >> /etc/resolv.conf
fi

dnf update 
dnf install man-pages man-db -y
dnf install passwd cracklib-dicts shadow-utils procps-ng iputils util-linux iproute net-tools dnf-plugins-core dnf-utils findutils -y
dnf install util-linux-user zsh zsh-autosuggestions zsh-syntax-highlighting powerline-fonts gcc make cmake pkgconfig info man nano nbd nss-tools neofetch zip htop python3-pip wget curl sudo ncurses -y
sysctl -w net.ipv4.ping_group_range="0 2000"
dnf clean all

useradd -G wheel "$uname_"
passwd "$uname_"
Enter fullscreen mode Exit fullscreen mode
Collapse
bowmanjd profile image
Jonathan Bowman Author

Great automation!

Collapse
bobhenkel profile image
Bob Henkel • Edited on

Thank you Jonathan! This article is top notch, it helped me out so much!

I've been in a MacOS and Linux world for about 10 years now. Just made the switch to a Windows11 desktop as my daily driver thanks to wsl2. That integration has been fantastic and being able to use my distro of choice fedora makes it all the better. Thanks again! Bob

PS, finding out about Micro editor is a cherry to top things off!

Collapse
haosmos profile image
haosmos • Edited on

Thank you for the detailed instruction!

I have installed fedora and the distribution is running. But for some reason, the standard commands are not available:

[haosmos@Haosmos-PC haosmos]$ cd ~/
[haosmos@Haosmos-PC ~]$ nano .bashrc
-bash: nano: command not found
[haosmos@Haosmos-PC ~]$ find find .bashrc
-bash: find: command not found
[haosmos@Haosmos-PC ~]$ clear
-bash: clear: command not found

When trying to download and install any program or utility, the same error is always displayed:

The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: Error downloading packages:
Curl error (6): Couldn't resolve host name for https://mirrors.fedoraproject.org/metalink?repo=fedora-33&arch=x86_64 [Could not resolve host: mirrors.fedoraproject.org].

How do I fix these problems?

Collapse
bowmanjd profile image
Jonathan Bowman Author

@haosmos , you were right and I was wrong!

Apparently, Fedora 33 uses systemd-resolvd, and when we upgrade packages with dnf upgrade something was overwriting /etc/resolv.conf with a link to /run/systemd/resolve/stub-resolv.conf which didn't actually exist.

So, I updated the instructions to include a workaround for Fedora 33. Please let me know if it works!

I also added a tip at the end to install findutils and ncurses. Let me know if you think other basic packages should be included. Thanks!

Collapse
bowmanjd profile image
Jonathan Bowman Author • Edited on

I am curious: what does your /etc/resolv.conf look like?

Here is mine:

nameserver 1.1.1.1
nameserver 8.8.8.8
Collapse
haosmos profile image
haosmos • Edited on

cat: /etc/resolv.conf: No such file or directory
[haosmos@Haosmos-PC ~]$

But file resolf.conf exist:

cloud.mail.ru/public/5BVW/2zYiramvC

Thread Thread
bowmanjd profile image
Jonathan Bowman Author • Edited on

OK. That could be the issue. Judging by your screenshot, you may want to first rm /etc/resolv.conf

Then can you follow the "Ensure DNS is functioning" part of the article and make sure that two files have been edited appropriately: /etc/resolv.conf and /etc/wsl.conf. Then restart your machine? I am very curious if that works for you or not.

Thread Thread
haosmos profile image
haosmos • Edited on

After many attempts (a lot of re-installations and reboots of the computer) I finally installed fedora in wsl and set it up)).

Everything seems to be working. I was able to install everything I needed (my goal was to configure the right working environment for web development).

I don't know what the problem was — why I had to start over many times, but wsl (fedora) worked in a strange way: the standard commands didn't work ("cat", "clear", "nano", etc.), or it was impossible to download and install programs and utilities (Curl error (6): Couldn't resolve host name for mirrors.fedoraproject.org/metalink... [Could not resolve host: mirrors.fedoraproject.org].).

Eventually, I set up fedora according to your tutorial, except that I didn't execute the commands:

echo -e "[network]\ngenerateResolvConf = false" > /etc/wsl.conf

and

echo nameserver 1.1.1.1 > /etc/resolv.conf

Now I have this content of the resolv.conf file:

cat /etc/resolv.conf

// This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
// [network]
// generateResolvConf = false
nameserver 172.29.16.1

In my well-working wsl 2 ubuntu-20.04 the content of the resolv.conf file is exactly the same.

I don't know if this will be a problem in the future (what I didn't specify in the resolv.conf: nameserver 1.1.1 according to your instructions) but so far everything seems to be working fine.

Tell me, please, what do I need to specify in the resolv.conf: nameserver 1.1.1.1 file for?

Maybe I should add it to my resolv.conf file?

Or if everything works as expected I don't have to add or change anything in my resolv.conf file?

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

Thank you for your feedback! I have updated the DNS section to include more specific instructions for removal of the offending link in Fedora 33, and also prefaced that with acknowledgement of the default automatically-configured resolv.conf provided by WSL. I hope this helps!

Collapse
operation420_net profile image
operation420_net • Edited on

Did you try dnf clean packages as suggested?

[root@operation420.net ~]$ dnf clean all && dnf update

PS I dunno nano, VIM is the hardcore editor/IDE!!!

Collapse
scottbeamer profile image
Scott Beamer

Vim is ovekill for simple text editing tasks.

Collapse
operation420_net profile image
operation420_net

Did you try dnf clean packages as suggested?

[root@operation420.net ~]$ dnf clean all && dnf update

PS I dunno nano, VIM is the hardcore editor/IDE!!!

Collapse
naruaika profile image
Naufan Rusyda Faikar • Edited on

I don't know why when I installed Fedora this way, I'm able to write into Windows NTFS (C:/) although it's so slow. But when I installed Ubuntu from the Microsoft Store, I couldn't. Can you give me some insight? Thanks in advance. I found this article very helpful!

Collapse
Sloan, the sloth mascot
Comment deleted
Collapse
naruaika profile image
Naufan Rusyda Faikar • Edited on

Sorry if I am bothering you. I have no idea why. But after running wsl -t ubuntu then wsl -d ubuntu, now it works. The only thing is it's so slow. Should I move my project folder into WSL ext4 hard disk image file? Or should I just format my D:/ to ext4? What is your advice? Thanks.

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

So, especially in WSL 2, Windows disk performance is very, very poor. Try doing your work in the Linux filesystem (in your home directory, for instance) instead. Is that faster?

Thread Thread
naruaika profile image
Naufan Rusyda Faikar

Yes, indeed, it is much faster.

Collapse
naruaika profile image
Naufan Rusyda Faikar

Sorry, but I couldn't find wsl.conf anywhere. Where should it be?

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

My apologies; I wasn't thinking and gave you wrong advice about the [interop] section. That doesn't have anything to do with mounting Windows drives from WSL.

Collapse
miqui profile image
Miguel Quintero

i run: wsl -d Fedora-33

..but get no default shell.. did i miss something?

Collapse
bowmanjd profile image
Jonathan Bowman Author

Interesting. Can you show us your entire wsl --import command?

Collapse
timfw profile image
TimFW

I think the problem may be he did not install windows virtual machine feature or install WSL 2. regardless if that is the issue there are likely many that do not have the update to WSL2 and think it would have been handled thru normal Windows Update System.

As you really have made such a detailed easy to follow how to article it might be best to update it.

  • First making sure their Win 10 build is above 18362.1049 or higher.

  • Update if not. Include installing the VM function feature which is easy as you just add it where you turn on "Windows sub system for Linux".

  • Restart System

  • Add the download link for "WSL2 Linux kernel update package for x64 machines" (link straight from microsoft website) wslstorestorage.blob.core.windows....

  • Have them run the update package downloaded in the previous step. (Double-click to run - you will be prompted for elevated permissions, select ‘yes’ to approve this installation.)

  • Restart System

  • Set WSL 2 as the default WSL version. Open Powershell and run " wsl --set-default-version 2 "

  • You can also reference this Microsoft Sites Documentation on how to upgrade
    docs.microsoft.com/en-us/windows/w...

You could just reference it and not list the steps or just list it for those that have issues from legacy systems updates.

Thread Thread
timfw profile image
TimFW

Ok I just did a fresh Win 10 install fully updated Windows Linux subsystems and Windows Virtual Machine Features added. Installed wsl 2 thru the linx update package I linked to. Set WSL 2 as default thru PS. Created the
"C:\Users\WSL\fedora" folder in the user profile root. Downloaded and renamed the fedora-32-rootfs.tar file. (I chose Fedora 32) Imported it. Ran it with "wsl -d fedora" But as Miguel Quintero posted it did not open a bash promote. Just had the same Powershell "PS C:\Users\Username> " prompt.

Next I checked to confirm it was running with "wsl -l --running" with output of:

"Windows Subsystem for Linux Distributions:
fedora (Default)"

Thus that confirms wsl fedora was running. ( I actually tried all of this before activating Windows VM or thte WSL 2 Linus package update to emulate a user running your instructions but not knowing about the WSL 2 package or activation of Windows VM add on. When I checked for running instances the output was " no running linux distro" or something to that effect. But it did install etc.

So there is still something hinky going on as with everything done on a fresh install fully updated and all installs and upgrades down while WSL 2 claims its running there is no bash prompt to run inside fedora linux.

I wonder if with the last win update MS made it so you can only install distro roots thru the Store. After all to download the Fedora Remix they state is from upstream its $10. Nice they are monetizing for open source freeware. You had to know that was the entire reason they got into the Linux game in the first place. Pulling a google on opensource projects.

Thread Thread
timfw profile image
TimFW

I tried installing Ubuntu 18.04 LTS and it worked and bash opened without issue. So something is is different doing it thru this manual way.

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

Wow, thank you for testing this! I will seek to replicate, and adjust the article accordingly.

Thread Thread
bowmanjd profile image
Jonathan Bowman Author • Edited on

@timfw , I am unable to replicate this. I believe you, though. Indeed something strange must be going on.

Could you verify what rootfs version you downloaded, and what tool you used to unpack? Not sure that will be fruitful, but thought I would check. I suspect you are right that this has something to do with WSL configuration.

Also, curious what happens if you wsl -d fedora -- bash or similar?

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

@timfw , I have made some changes to the article as you suggested, giving a bit more detail about upgrading to WSL version 2 and also detailing multiple options for rootfs download. I don't think this resolves the issue you are identifying, unless perhaps a newer rootfs fixes it?

Thread Thread
timfw profile image
TimFW

I used the fedora 32 x64 you linked to here
this is the file name it downloaded Fedora-Container-Base-32-20201205.0.x86_64.tar.xz I used7zip to decompress it to a tar.

Something weird though. The first time I downloaded it the file ended with the .tar.xz. But now since I originally decompressed it everytime I download it comes as just .tar not .tar.xz in the download directory. I assume its because of 7zip already decompressing it to just a .tar. I hate programs deciding for me how to help grrr...

I insured wsl 2 was the default.

I renamed the decompressed .tar to fedora-32-rootfs.tar
I then created the folder mkdir C:\users\username\wsl\fedora

Next imported the .tar to \wsl\fedora with "wsl --import c:\user\username\download\unzip\fedora-32-rootfs.tar c:\user\username\wsl\fedora\"

I checked and confirmed it was installed in that directory.

Next ran "wsl -d fedora" and after a pause it just returns me to the next line standard prompt in PS. I tried running both as user and admin.

I run "wsl -l -running" and it shows fedora default is running.

I check inside ~\wsl\fedora in Win Explorer and it now shows a ext4 virtual drive

But thats it.

Now I went thru the Win Store and downloaded Ubuntu 18.04 LTS and thru whatever auto .msi it installs it with I get an immediate bash window .Windows installs the ubuntu1804.exe in C:\Users\Username\AppData\Local\Microsoft\WindowsApps directory

It also installed a entire user directory set for Ubuntu in C:\Users\Lenovo\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc

Thread Thread
timfw profile image
TimFW • Edited on

after a reboot

in PS going to ~\wsl\fedora here is the output of a dir cmd

These are c&p of the text in PS:


PS C:\Users\Lenovo\wsl\fedora> dir
Directory: C:\Users\Lenovo\wsl\fedora
Mode LastWriteTime Length Name


-a---- 12/7/2020 12:00 AM 246415360 ext4.vhdx
PS C:\Users\Lenovo\wsl\fedora>


Then a check to confirm no running distributions followed by the "wsl -d fedora" cmd and as you can see it just returns a standard PS Windows prompt.

These are c&p of the text in PS:

PS C:\Users\Lenovo> wsl -l --running
There are no running distributions.
PS C:\Users\Lenovo> wsl -d fedora
PS C:\Users\Lenovo>
PS C:\Users\Lenovo> wsl -l --running
Windows Subsystem for Linux Distributions:
fedora (Default)

PS C:\Users\Lenovo>

No bash window opened nothing

But if I wait about a minute and then rerun the wsl -l --running I get this


PS C:\Users\Lenovo> wsl -d fedora
PS C:\Users\Lenovo> wsl -l --running
Windows Subsystem for Linux Distributions:
fedora (Default)

PS C:\Users\Lenovo>

The Ubuntu thru the store works fine. In fact I just git gcc compiled and produced a binary for CryFS encryption program which is a updated and secured version EncFS.

I just do not get why Fedora installed manually does not work?? It even shows it as a virtually mounted drive.

Thread Thread
timfw profile image
TimFW • Edited on

Finally SUCCESS!!!!

I took your recommendation about it maybe an issue with the roofs downloaded. I downloaded the one form the docker link you provided.

I terminated and then unregistered the current not working fedora 32 from December 5,your link in here:

"Find the right "xz" file for your platform (likely x86_64). Such as this one for the December 5, 2020 build of Fedora 33. Or, if you were still wanting Fedora 32, this Fedora 32 build from December 5 should work."

Not sure if you updated that when you edited the article. The one from that link prior to it may be bad as its what did not work.

I followed the docker github link to github.com/fedora-cloud/docker-bre...
and it produced a successful install finally.
PS C:\Users\Lenovo>wsl -t fedora
PS C:\Users\Lenovo>wsl --unregister fedora
PS C:\Users\Lenovo>
PS C:\Users\Lenovo> wsl --import fedora c:\Users\Lenovo\wsl\fedora c:\Users\Lenovo\Downloads\fedora-33-rootfs.tar

PS C:\Users\Lenovo> wsl -l
Windows Subsystem for Linux Distributions:

Ubuntu-18.04 (Default)

fedora

PS C:\Users\Lenovo> wsl --set-default fedora
PS C:\Users\Lenovo> wsl -l --running
There are no running distributions.

PS C:\Users\Lenovo> wsl -l --verbose
NAME STATE VERSION

  • fedora Stopped 2

Ubuntu-18.04 Stopped 2

PS C:\Users\Lenovo> wsl -d fedora

[root@Lenovo-THINK Lenovo]#

Yes finally a bash prompt.

Thank you very much Jonathan for a well written set of instructions and improving it. Maybe check that current linked fedora 32 download I mentioned and see if it creates a working rootfs. If it works maybe something got corrupted during my download is all I can think of. I did download it twice though and tried both copies but anything is possible I guess. But no matter I have positive results now thanks to your suggestions.

BTW I am using this to see if Qubes OS Ver 4.0 series can be compiled and binary produced using the Windows linux subsystem. It works 100% on a real Fedora 32+ install with all necessary programs loaded. Want to see if it works here as its a rather complex tool and script system for the build environment.

Again thank you!

Cheers,

Tim

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

Excellent! I am glad it is working for you now. I hope your Qubes OS task goes well.

Collapse
brnvrn profile image
Bruno Vernay

I guess you could use Ansible to continue with the install.
Note that with WSL 2 you loose VirtualBox (unless you are on the very last Windows version)
Very good article anyway, I just finished the install. (Had to deactivate the local McAfee firewall in Windows for the network to work)

Collapse
bowmanjd profile image
Jonathan Bowman Author

Glad you found it helpful! Thank you.

Collapse
brnvrn profile image
Bruno Vernay

After a first update and rollback, you might want to add:
exclude=systemd*
in /etc/dnf/dnf.conf

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

Thoughtful. Can you say more about the "rollback" part? And what sort of problems you are encountering around package updates? Which packages, specifically?

I think I like the idea. But let's say, for instance, that I want to use systemd-analyze on occasion. (I know, not useful for a non-systemd WSL, but I do maintain other systems as well.) It would seem that I shouldn't exclude systemd updates, then.

In other words, if it is not breaking anything, I could still see some advantages to keeping systemd packages up to date. Thoughts?

Thread Thread
brnvrn profile image
Bruno Vernay

The update included dependencies and weak-dependencies and systemd got installed as well as systemd-networkd I guess which deleted resolv.conf ... instantly removing name resolution ... For sure systemd adds itself to /etc/dnf/protected.d/ it does not ease rolling back.
Maybe it is possible to exclude just systemd-networkd I did not try.

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

Just curious... systemd-networkd is still messing with resolv.conf even after an unlink /etc/resolv.conf then creating a new one?

Collapse
krrishdhaneja profile image
Krrish Dhaneja

Hey, @bowmanjd Thanks for your instructions, but as you know that wsl2 doesn't support systemd, how do I install SysVinit in Fedora, I found no docs on Google about this, Can you please help me!

Collapse
bowmanjd profile image
Jonathan Bowman Author

Good question. Are you sure you need systemd or sysvinit? What happens if you run sshd by itself? You may be pleasantly surprised.

Collapse
krrishdhaneja profile image
Krrish Dhaneja

I think You mean I can start sshd by itself, that's kind of interesting but what about rest of the services? I may need an init system for that? Ain't I?

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

What other services do you need to run?

Thread Thread
krrishdhaneja profile image
Krrish Dhaneja

Till now only sshd, and will be seeing your docker tutorial to start docker, and rest the future will tell! Btw isn't there any way to install systemd on wsl by using original linux kernel instead of wsl2's custom kernel? And isn't there any SysVinit package in Fedora's repository of packages or I have to add a ppa just as in Ubuntu??

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

I would recommend using Hyper-V or Virtualbox to run your own Linux VM, which will then have systemd or other init system. Yes, Fedora already has systemd, and you could find other distros if you prefer openrc or other init system. The issue isn't the installation of systemd, then (and, no, you wouldn't want to try to replace systemd with sysvinit on a systemd-based distro; instead, find a non-systemd distro). The issue is that WSL has its own init system that runs with PID 1. By the way, systemd has little to do with the kernel version installed.

The typical WSL hack I see is running genie. You may try that. But it adds another layer of complexity that is generally unneeded, if all you want is a way to launch long-running processes. Simply launch them. If you need other systemd features, other than services, then maybe you want to look into genie or a separate VM.

Does that make sense?

Thread Thread
krrishdhaneja profile image
Krrish Dhaneja

Thanks for suggestion and explanation, would be trying genie!!

Collapse
krrishdhaneja profile image
Krrish Dhaneja • Edited on

I don't get it, that's kind of a puzzle i think; @bowmanjd

Thread Thread
bowmanjd profile image
Jonathan Bowman Author
sudo dnf install openssh-server
sudo ssh-keygen -A
sudo /usr/sbin/sshd
Enter fullscreen mode Exit fullscreen mode

What do you think? Are the results satisfactory?

Collapse
operation420_net profile image
operation420_net

Please see my reply to Krrish Dhaneja

Collapse
operation420_net profile image
operation420_net

Krrish Dhaneja, I replied to your other comment with the instructions!!!

Collapse
operation420_net profile image
operation420_net

Please see my reply to Krrish Dhaneja

Collapse
martinhinze profile image
martin-hinze

I missed having man pages available with this container version of Fedora. Thus, I would like to share how I added man pages to my WSL Fedora system, in case this might be of use to someone else out there.

@bowmanjd : Feel free to include this in your article, if you like, or point out enhancements or how to do it better.

Basically, I told dnf to include man pages when installing packages and then reinstalled all packages already installed.

If you don't have a text editor installed, which you know how to use, run

sudo dnf install nano -y
Enter fullscreen mode Exit fullscreen mode

to install the easy-to-use editor GNU nano.

Delete the line tsflags=nodocs in the file /etc/dnf/dnf.conf with a text editor of your choice and save it, e.g.

sudo nano /etc/dnf/dnf.conf
Enter fullscreen mode Exit fullscreen mode

Update your system and install the man command:

sudo dnf update -y
sudo dnf install man man-pages -y
Enter fullscreen mode Exit fullscreen mode

In your home directory, create a text file reinstall-all-dnf-packages.sh containing the following script:

#!/bin/bash

installedPkgs=$(dnf list installed | tail -n +2 | cut -d ' ' -f 1)
for pkg in $installedPkgs; do
    dnf reinstall $pkg -q -y
done
Enter fullscreen mode Exit fullscreen mode

Make the script runable and run it:

chmod 755 reinstall-all-dnf-packages.sh
./reinstall-all-dnf-packages.sh
Enter fullscreen mode Exit fullscreen mode

Now all man pages should be available. Try, for example, man dnf. :-)

Collapse
bowmanjd profile image
Jonathan Bowman Author

Thanks, again, @martinhinze ! I have now included your good advice in the article. Much appreciated!

Collapse
martinhinze profile image
martin-hinze • Edited on

I tried to do a fresh install of Fedora 35 and unfortunately it doesn't work anymore.
After running
wsl --import Fedora [myInstallFolder] [myRootfs.tar]
I run
wsl -d Fedora
and get the following error message: An error occurred mounting one of your file systems. Please run 'dmesg' for more details.
wsl -l lists Fedora, so the import seemed to work.

Before, I put a fresh installation of Win 11 on my computer, don't know if that has something to do with this error.
WSL kernel version is 5.10.60.1.
Windows version is "Version 21H2 (Build 22000.376)"
PowerShell version is 7.2.1

Already had a look in WSL's Github, but TBH did not really understand if this is my issue.

Any help or suggestions would be greatly appreciated since I love Fedora. Otherwise, the ready-made Ubuntu WSL is working okay.

Collapse
bowmanjd profile image
Jonathan Bowman Author

Thank you for noting the problem. Curious: what was your method for obtaining myRootFs.tar?

Collapse
martinhinze profile image
martin-hinze

From the Fedora Container Base I download the newest distro package, in this moment this is release 20211231.0.
In the download folder of my Win 11 machine I receive the file Fedora-Container-Base-35-20211231.0.x86_64.tar.xz. In unzip it with 7-zip and obtain the file Fedora-Container-Base-35-20211231.0.x86_64.tar and rename it to something shorter like fedora-35-rootfs.tar.

I have no idea what might be wrong and even where to start looking for a solution.

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

Were you able to extract the layer.tar file and rename that? The Fedora-Container-Base-35-20211231.0.x86_64.tar file will not work as a rootfs without further extraction. Hope this helps...

Thread Thread
martinhinze profile image
martin-hinze

Thank you for your patience, I indeed failed to extract the layer.tar file, it is working fine now.
(Sorry for the late reply, I was offline for a few days.)

Collapse
ecoutinho profile image
Elio Coutinho

Thanks for the article, it was very easy to follow! It annoyed me having to execute 'cd' to go to the homedir on every new shell. Read elsewhere that you can start with 'wsl ~' to achieve that. Thought I should mention.

Collapse
bowmanjd profile image
Jonathan Bowman Author

Great tip. Thank you so much!

Collapse
operation420_net profile image
operation420_net

Thanks for the 'wsl ~' tip, I will have to try it.

Adding a "cd ~" or "cd /home/user" into /etc/bashrc might help...

Collapse
secends0001 profile image
Leeeee

thanks for the steps, now I have a fedora32 working on wsl2 .
however still looking to the systemd with fedora on wsl2.

so theoretically, we should also enable systemd by this smart guy's ubuntu way, github.com/DamionGans/ubuntu-wsl2-....

however no lucky till now, the worse is fedora won't go with sysinit/service.

Collapse
bowmanjd profile image
Jonathan Bowman Author • Edited on

Thank you so much for reading and responding! I am so glad it is working for you. I agree, it is sad about systemd.

You are right that systemd and WSL are not a great combination. But there is a chance you could function without systemd.

Could you identify what needs you have that require systemd? Might be fun to ponder...

Collapse
operation420_net profile image
operation420_net

I had the same issue but fixed it. Please see my reply to Krrish Dhaneja.

Collapse
mrpointer profile image
Timor Gruber

Do you happen to know how can I upgrade the distro to a newer image without losing all info (such as installed packages)?

Collapse
bowmanjd profile image
Jonathan Bowman Author • Edited on

Are you saying you have Fedora 32 and want to upgrade to Fedora 33? If so, this works for me:

sudo dnf upgrade --refresh
sudo dnf install dnf-plugin-system-upgrade
sudo dnf system-upgrade download --releasever=33
sudo dnf system-upgrade reboot
sudo dnf system-upgrade upgrade
(Close the terminal and restart; I even restarted wsl, but I am not sure that is necessary.)
sudo rpmdb --rebuilddb
sudo dnf upgrade --refresh
sudo dnf system-upgrade clean

What do you think? Does that work? Wouldn't hurt to do a backup first.

Collapse
mrpointer profile image
Timor Gruber

Not exactly what I meant, though it's nice to know that it actually works!
The scenario I'm asking about is having installed a specific build of Fedora, say the latest 33 available from their servers, how can I "install" a newer build that comes, say, a week after? It would require a new rootfs, which doesn't play well with WSL's capabilities at the moment, i.e. I'd have to install a new, separate distro for it to work

Thread Thread
bowmanjd profile image
Jonathan Bowman Author

Now that, friend, is a brilliant question. You don't want to just dnf upgrade? Am I hearing you right?

I honestly don't know a good answer yet. I don't know that wsl can import and merge tarballs. I suppose you could unpack a new tarball at the root of your filesystem, but that would scare me. Other thoughts?

Thread Thread
mrpointer profile image
Timor Gruber

Well, maybe I'm not familiar enough with how Fedora builds work - Are you saying that simply executing dnf upgrade will keep me up-to-date with the latest system changes occurring to Fedora?
I mean, I know that dnf manages all of the system's packages, but as I work with a non-stable version of Fedora (33), doesn't it mean that you should update your build once in a while? I'm yet to have experience with Fedora's beta releases :)

Thread Thread
bowmanjd profile image
Jonathan Bowman Author • Edited on

Oh, yes. dnf upgrade will serve you well! Further details here, including the instructions:

You shouldn't need to do anything to get the final public release, other than install package updates as they become available. You can use "sudo dnf update" or wait for desktop notification.

Thread Thread
mrpointer profile image
Timor Gruber

Awesome!!! Well, that truly makes a custom installed Fedora a great candidate for a productive WSL distro 😎

Thanks for your help!

Collapse
nlhnt profile image
Marcin Borawski

Hello,
fedora in wsl doesn't seem to be using systemd - sorry if that sounds like layman speaking I am not an expert in this domain.
I would like to get the services started, which packages should I install?
Using systemctl command shows the following warning/error:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Enter fullscreen mode Exit fullscreen mode
Collapse
mrpointer profile image
Timor Gruber • Edited on

There's a known issue with systemd in WSL2 - It's just not officially supported yet...

In the meanwhile, you can try genie - It's the best attempt to solve this at the moment

Collapse
bowmanjd profile image
Jonathan Bowman Author

You got it! That is one of the "hacks" I mentioned in the article. If you need it, it is there. I just don't think everyone needs it.

Not sure I would call it "a known issue" when it is a deliberate design choice about init system. But maybe I am wrong. In other words, nothing is broken. The init architecture is slightly different, though.

Collapse
operation420_net profile image
operation420_net • Edited on

I had the same issue but fixed it. Please see my reply to Krrish Dhaneja.

Collapse
jradxl profile image
John Radley

Thank you so much for writing this article.
Just followed it though for Fedora 35 with no problems,
except for the /etc/wsl.conf with adding [user] default string hasn't worked.
But I'm convinced WSL2 isn't going to lure me back from my beloved Ubuntu!

Collapse
scottbeamer profile image
Scott Beamer • Edited on

Right after dnf install -y passwd cracklib-dicts, I would strongly recommend:

dnf groupinstall "Minimal Install"

There were number of pretty standard-issue packages that weren't already installed in the container, that I was wanting right away ("find", "less" and "which" come to mind).

Collapse
krrishdhaneja profile image
Krrish Dhaneja • Edited on

how do I start a service(like ssh) if I can't use systemctl in wsl? And how do I install SysVinit?

Collapse
operation420_net profile image
operation420_net • Edited on

I got cron working in Fedora and Ubuntu on WSL.

Carlos at Whitewater Foundry was most helpful. Here is his reply to my email:

There is a solution that replaces systemctl by a python script that reads the service files and tries to start the services. We don’t distribute it with Fedora Remix because it has mixed results. For example, it works for cron and ssh but no for databases in general. Even in SSH, you need to do an extra step.

Follow these steps to start cron service in Fedora Remix. Works with WSL1 & WSL2:

wget raw.githubusercontent.com/gdraheim...

sudo cp /usr/bin/systemctl /usr/bin/systemctl.bak

sudo cp systemctl3.py /usr/bin/systemctl

sudo dnf install cronie cronie-anacron

crontab -e # Edit your crontab

sudo systemctl start crond

Be aware that each time that the package systemd is updated, you need to run the first three lines of the script.

Collapse
operation420_net profile image
operation420_net

Hope my reply helpz

Collapse
elanshudnow profile image
Elan Shudnow

Hi, thank you for the article. Why not just do the following:
docker pull fedora
docker export to export the fedora container
wsl import to import the fedora container into wsl

Collapse
bowmanjd profile image
Jonathan Bowman Author

That's a brilliant and elegant way to pull a rootfs. Would that have been able to pull snapshots and prereleases such as those offered by Fedora Container Base Project, though?

Thanks for this advice. I am going to experiment a bit, and likely incorporate it into the article.

Collapse
elanshudnow profile image
Elan Shudnow

Sorry, not too familiar with Fedora tbh. I mostly use CentOS. Just happened to stumble upon this article and figured I'd comment. Here's an article I was able to find that describes the process: medium.com/@hoxunn/wsl-docker-cust.... There's not a whole lot of information out there on this process and a bit of a pain to find.

Collapse
jlorenzo681 profile image
jlorenzop

Super useful, thanks Jonathan!

Collapse
operation420_net profile image
operation420_net • Edited on