通过微软的 WSL2 使用 Fedora 33
WSL
![](/data/attachment/album/202011/20/200339ytony7tyldbphhzp.jpg)


如果你像我一样，你可能会发现自己因为各种原因而运行 Windows，无论是因为工作还是游戏。当然，你可以在虚拟机或容器中运行 Fedora，但这些并不像 Windows 的 Linux 子系统（WSL）那样容易融合到普通的 Windows 体验中。通过 WSL 使用 Fedora 可以让你将这两种环境融合在一起，创造一个奇妙的开发环境。


### 先决条件


为了达成这一目标，你需要一些基本条件。你应该运行 Windows 10，并且已经安装了 WSL2。如果没有，请查看[微软文档说明](https://docs.microsoft.com/en-us/windows/wsl/install-win10)，完成后再回来这里。微软建议为了简单起见，将 WSL2 设置为发行版的默认设置。本指南假设你已经这样做了。


接下来，你将需要一些解压 xz 压缩文件的方法。你可以用另一个基于 WSL 的发行版来解压，或者使用 [7zip](https://www.7-zip.org/download.html)。


### 下载 Fedora 33 rootfs


由于 Fedora 并没有提供实际的 rootfs 存档，所以我们将借用一个用于生成 Dockerhub 容器镜像的存档。你需要从 fedora-cloud 的 GitHub 仓库下载该 [tar.xz 文件](https://github.com/fedora-cloud/docker-brew-fedora/tree/33/x86_64) 。一旦你有了这个 tar.xz 文件，解压它，但不要展开 tar 包。你会得到一个类似 `fedora-33-时间标签.tar` 的文件。有了这个文件，你就可以构建镜像了。


### 组合 WSL Fedora 的构建版本


我喜欢使用 `c:\distros` 目录，但你可以选择几乎任何你想要的位置。无论你选择什么目录，在你导入该构建版本之前，确保其顶层路径存在。现在打开一个 CMD 或 Powershell 提示符，因为是时候导入了：



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

```

你会看到 Fedora-33 显示在 WSL 的列表当中：



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

```

下面，你就可以开始在 WSL 中摆弄 Fedora 了，但我们还需要做一些事情来使它真正成为一个有用的 WSL 发行版。



```
wsl -d Fedora-33

```

这将以 root 用户的身份启动 Fedora 的 WSL 实例。下面，你将安装一些核心包并设置一个新的默认用户。你还需要配置 `sudo`，否则你将无法在以后需要安装其他东西时轻松提升权限。



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

```

`wslutilites` 使用 `curl` 和 `wget` 来实现与 VS Code 的集成，所以它们很有用。由于你需要使用 COPR 仓库，你需要增加 `dnf` 功能。


### 添加你的用户


现在是时候添加你的用户，并将其设置为默认用户。



```
useradd -G wheel 用户名
passwd 用户名

```

现在，你已经创建了你的用户名，并添加了密码，确保它们可以工作。退出 WSL 实例，并再次启动它，这次指定用户名。你还要测试 `sudo`，并检查你的 uid。



```
wsl -d Fedora-33 -u 用户名
$id -u
1000
$ sudo cat /etc/shadow

```

假设一切正常，你现在已经准备好在 Windows 中为你的 Fedora 环境设置默认用户。要做到这一点，请退出 WSL 实例并回到 Powershell 中。这个 Powershell 单行代码可以正确配置你的用户：



```
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

```

现在你应该可以再次启动 WSL，而不需要指定就可以成为自己的用户而不是 root。


### 自定义！


至此，你已经有了可以在 WSL 中运行的基本 Fedora 33 环境，但它还没有 Windows 集成的部分。如果你想要这个，有一个 COPR 仓库可以启用。如果你选择添加这部分，你就可以直接在 shell 里面运行 Windows 应用，也可以轻松地将你的 Linux 环境与 VS Code 集成。需要注意的是，COPR 并没有得到 Fedora 基础架构的官方支持。使用该软件包，风险自担。



```
dnf copr enable trustywolf/wslu

```

现在你可以去配置终端、设置一个 Python 开发环境，或者其它你想使用 Fedora 33 的方式。享受吧！




---


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


作者：[Jim Perrin](https://fedoramagazine.org/author/jperrin/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
If you’re 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 don’t 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 you’ll 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](https://docs.microsoft.com/en-us/windows/wsl/install-win10), and come back here when you’re finished. Microsoft recommends setting wsl2 as the distro default for simplicity. This guide assumes you’ve done that.

Next, you’re going to need some means of unpacking xz compressed files. You can do this with another WSL-based distribution, or use [7zip](https://www.7-zip.org/download.html).

### Download a Fedora 33 rootfs

Since Fedora doesn’t ship an actual rootfs archive, we’re going to abuse the one used to generate the container image for dockerhub. You will want to download the [tar.xz file](https://github.com/fedora-cloud/docker-brew-fedora/tree/33/x86_64) from the fedora-cloud GitHub repository. Once you have the tar.xz, uncompress it, but don’t unpack it. You want to end up with something like fedora-33-*datestamp*.tar. Once you have that, you’re 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 it’s 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 wsl’s 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 Fedora’s wsl instance as the root user. From here, you’re going to install a few core packages and set a new default user. You’re also going to need to configure sudo, otherwise you won’t 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 they’re useful to have around. Since you need to use a Copr repo for this, you want the added dnf functionality.

### Add your user

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

useradd -G wheel yourusername

passwd yourusername

Now that you’ve created your username and added a password, make sure they work. Exit the wsl instance, and launch it again, this time specifying the username. You’re 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, you’re 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, you’re done getting the basic Fedora 33 setup running in wsl, but it doesn’t have the Windows integration piece yet. If this is something you want, there’s a Copr repo to enable. If you choose to add this piece, you’ll 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!

## Max Borowsky

Unfortunately, no one has yet created the official Fedora’s app for Microsoft Store.

## Matthew Miller

Actually, someone did create it; it’s just that actually getting something into the app store requires acceptance of legal terms Fedora can’t agree to. We’re still working on finding alternate solutions.

## Daniel

Now the details on those issues and what work-arounds are considered would be an interesting article for the Magazine!

## Yannick

And if you create an Appx file that users can install by double clicking on it, is there still the isse of legal Terms ?

## Enric

I just activated WSL, went to the Microsoft Store and downloaded the app. It’s working. I was actually surprised while reading the article that there was so much work involved.

(I’m writing from a proper 100% Fedora 33 Dell laptop, BTW)

## Sheogorath

Mhm, while the article is hopefully helpful for people out there, I’m disappointed to see content marketing for Microsoft Windows on Fedora Magazine. But hey, we live in strange times.

## Jeffersonian

I go along this.

MS and Apple alike have made it difficult to dual boot, and it is no accident.

It did not take long for github after being acquired by MS to exhibit Linux issues…

Consequently Fedora Magazine, should restrain to advertise MS products, Apple too.

But documenting new attempts to preempt hardware platforms so Linux cannot be run there, should be documented, ideally with workarounds.

## Joe Pesco

I agree fully.

## Dave Cross

“It did not take long for github after being acquired by MS to exhibit Linux issues…”

Can you please explain what you mean by this?

## Dave Cross

Would it not be a bit easier to install the “Fedora Remix for WSL” product from the Windows store?

## Klein Kravis

Yeah, it costs $20 USD

## silhano

I was still hoping Fedora one day appears in official Microsoft store (same as Ubuntu, SUSE, Debian, …) special when RedHat(IBM) is partner with Microsoft in Azure. This is kind of sad, but thanks for the guide.

## Heliosstyx

Thank you for your easy to understand article. So everybody has the choice when and where he/she wants to use the different OS’s. This links different “fascinating worlds” seamlessly.

## ja.

It is not going to appear anytime soon – the reason why it is not there is legal. Microsoft wants indemnification agreement and the Fedora legal obviously declined.

For more info, see here: https://lists.fedoraproject.org/archives/list/legal@lists.fedoraproject.org/thread/JA4FEGORE53RXKOPRADODTBUCQN3XVJE/

## Rex Fury

Isn’t WSL essentially a Microsoft distro of Linux?

Isn’t this an appeal to the hoi polli of users?

## Matthew Miller

No, WSL is a system whereby packages from a Linux distribution are run in a container-like environment on Windows. It uses a Microsoft-provided version of the standard Linux kernel.

## billings

These instructions are for WSL2, which means Fedora is running in a Hyper-V VM, so not the container-like OS in WSL1.

## Will Kaiser

Excellent guide, thanks! Got this up and running in minutes and learned a bit more about how WSL works in the process (compared to just pulling in an app).

## Leon Gladston

Tensorflow and pytorch GPU setup for Machine learning is difficult in Fedora,so we are forced to take up debian packages like ubuntu.

## David Yaffe

When changing the password, I received the following error:

/usr/share/cracklib/pw_dict.pwd.gz: No such file or directory

BAD PASSWORD: The password fails the dictionary check – error loading dictionary

Retype new password:

passwd: all authentication tokens updated successfully.

running

solved the problem

## MartinP

There is a slightly easier way to set the default user, create a file called /etc/wsl.conf and set the user there:

[user]

default=username

WSL reads that file on start, there are other options that can be set such as mounts, check the official Microsoft doco for options.

## minkiu

If only this guide had been written earlier, this is so much better and easier than if you where to try to do it following Microsoft’s instructions, I was attempting it with CentOS, and like Fedora, the LiveISO has no rootfs, so my distro failed, didn’t even think of looking at the Docker image.

Thanks for this, this makes it so much saner and easy.

## Bayu Sanjaya

Ok, can we do vice versa?

I think we can copy windows core, or at least remove Windows bloatware(cortana, edge, etc). Then use KVM to run and expose the necessary apps only. For example steam.

We can do hardware (VGA or LAN) passthrough using kvm.

## docmoriarty

People use different operating systems the way they need it, this is called freedom of choice. The Edge is not bloatware, but essentially just another Chromium based browser, by the way, available not only for Windows, but also for Linux – please don’t use hate speech.

## Adam Chance

I’ve created a PowerShell script to create the WSL distribution automatically, it only requires that xz be available on the system path.

https://github.com/SocMinarch/fedora-wsl

Still need to write actual documentation but I’m getting there.

## Juergen

Will wait until there is a LSW Linux Subsystem for Windows

## Donald Sebastian Leung

That’s just Wine, no?

## Alan

WINE or the Codeweaver’s version called Crossover

## Barry

Did you miss out what to install from the copr?

dnf install wslu

## Jim Perrin

yeah. I thought I had that in there, but you’re right. I missed it. Thanks for adding the comment here for folks to find.

## Patrick

You know that for the customize part there is an official one by

## Jim Perrin

That one (at the time of writing this anyway) doesn’t support f33 yet.

## Silesh K Nair

https://github.com/yosukes-dev/FedoraWSL

## Jonathan D Bowman

Nice write-up. Very thoughtful to include wslu. Thanks!

## jenrry

hola y para cuando tendremos un sistema windows en fedora ,así como si fuera una aplicación como cualquier otra, hasta cuando gnu/linux sera usado como aplicación de una tienda, a caso no se quieren ustedes mismos? que pretende microsoft con estas jugadas? traer mas gente a su sistema las personas pueden decir, “bueno aqui lo tengo todo para voy a instalar linux”, si esto sigue así cada vez habrá menos personas que puedan usarlo, y los fabricantes de hardware podrán decir “para que hago driver de hardware que nadie usa” por eso es importante tomar buenas deciciones para que no afecten el futuro de Fedora y de todo gnu/linux en general.

## Don Pool

Hi,

Is there a way to create a shortcut, somo sort of launcher to avoid Opening Powershell and launching wsl?

## Jonathan D Bowman

Have you tried Windows Terminal? https://github.com/microsoft/terminal

## Carvel Baus

Does this work for Windows Arm laptops as well?

## Ranvir

Is there a way to find the image by navigating the Fedora GitHub account? Just to make this article more future proof.

For example when Fedora 34 comes out we need a sane way of finding its rootfs image.

## Joe Pesco

I’ll remain out of the legal debate and only frown at MS content on Fedora Magazine!!! My instinct is that the WSL is important to MS customers.

One note: To get preview 20262 I needed to change my insider ring to

dev from beta. Everything was smooth sailing after that!

Thanks for a good article!