TranslateProject/sources/tech/20201111 Using Fedora 33 with Microsoft-s WSL2.md
DarkSun 5e665e94b9 选题[tech]: 20201111 Using Fedora 33 with Microsoft’s WSL2
sources/tech/20201111 Using Fedora 33 with Microsoft-s WSL2.md
2020-11-12 10:23:52 +08:00

5.6 KiB
Raw Blame History

Using Fedora 33 with Microsofts WSL2

Photo by Matthias Heil on Unsplash

If youre like me, you may find yourself running Windows for a variety of reasons from work to gaming. Sure you could run Fedora in a virtual machine or as a container, but those dont blend into a common windows experience as easily as the Windows Subsystem for Linux (WSL). Using Fedora via WSL will let you blend the two environments together for a fantastic development environment.

Prerequisites

There are a few basics youll need in order to make this all work. You should be running Windows 10, and have WSL2 installed already. If not, check out the Microsoft documentation for instructions, and come back here when youre finished. Microsoft recommends setting wsl2 as the distro default for simplicity. This guide assumes youve done that.

Next, youre going to need some means of unpacking xz compressed files. You can do this with another WSL-based distribution, or use 7zip.

Download a Fedora 33 rootfs

Since Fedora doesnt ship an actual rootfs archive, were going to abuse the one used to generate the container image for dockerhub. You will want to download the tar.xz file from the fedora-cloud GitHub repository. Once you have the tar.xz, uncompress it, but dont unpack it. You want to end up with something like fedora-33-datestamp.tar. Once you have that, youre ready to build the image.

Composing the WSL Fedora build

I prefer to use c:\distros, but you can choose nearly whatever location you want. Whatever you choose, make sure the top level path exists before you import the build. Now open a cmd or powershell prompt, because its time to import:


wsl.exe --import Fedora-33 c:\distros\Fedora-33 $HOME\Downloads\fedora-33.tar


You will see Fedora-33 show up in wsls list


PS C:\Users\jperrin> wsl.exe -l -v   NAME                   STATE           VERSION   Fedora-33                 Stopped         2


From here, you can start to play around with Fedora in wsl, but we have a few things we need to do to make it actually useful as a wsl distro.


wsl -d Fedora-33


This will launch Fedoras wsl instance as the root user. From here, youre going to install a few core packages and set a new default user. Youre also going to need to configure sudo, otherwise you wont be able to easily elevate privileges if you need to install something else later.


dnf update dnf install wget curl sudo ncurses dnf-plugins-core dnf-utils passwd findutils


wslutilites uses curl and wget for things like VS Code integration, so theyre useful to have around. Since you need to use a Copr repo for this, you want the added dnf functionality.

Add your user

Now its time to add your user, and set it as the default.


useradd -G wheel yourusername passwd yourusername


Now that youve created your username and added a password, make sure they work. Exit the wsl instance, and launch it again, this time specifying the username. Youre also going to test sudo, and check your uid.


wsl -d Fedora-33 -u yourusername $id -u 1000 $ sudo cat /etc/shadow


Assuming everything worked fine, youre now ready to set the default user for your Fedora setup in Windows. To do this, exit the wsl instance and get back into Powershell. This Powershell one-liner configures your user properly:


Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq Fedora-33  | Set-ItemProperty -Name DefaultUid -Value 1000


Now you should be able to launch WSL again without specifying a user, and be yourself instead of root.

Customize!

From here, youre done getting the basic Fedora 33 setup running in wsl, but it doesnt have the Windows integration piece yet. If this is something you want, theres a Copr repo to enable. If you choose to add this piece, youll be able to run Windows apps directly from inside your shell, as well as integrate your Linux environment easily with VS Code. Note that Copr is not officially supported by Fedora infrastructure. Use packages at your own risk


dnf copr enable trustywolf/wslu


Now you can go configure your terminal, setup a Python development environment, or however else you want to use Fedora 33. Enjoy!


via: https://fedoramagazine.org/wsl-fedora-33/

作者:Jim Perrin 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出