Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Using Fedora 33 with Microsoft’s WSL2

#1
Using Fedora 33 with Microsoft’s WSL2

<div><p>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.</p>
<p> <span id="more-32138"></span> </p>
<h3>Prerequisites</h3>
<p>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 <a rel="noreferrer noopener nofollow" href="https://docs.microsoft.com/en-us/windows/wsl/install-win10" target="_blank">Microsoft documentation for instructions</a>, 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.</p>
<p>Next, you’re going to need some means of unpacking xz compressed files. You can do this with another WSL-based distribution, or use <a rel="noreferrer noopener nofollow" href="https://www.7-zip.org/download.html" target="_blank">7zip</a>.</p>
<h3>Download a Fedora 33 rootfs</h3>
<p>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 <a href="https://github.com/fedora-cloud/docker-brew-fedora/tree/33/x86_64">tar.xz file</a> 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-<em>datestamp</em>.tar. Once you have that, you’re ready to build the image.</p>
<h3>Composing the WSL Fedora build</h3>
<p>I prefer to use <em>c:\distros</em>, 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:</p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">wsl.exe --import Fedora-33 c:\distros\Fedora-33 $HOME\Downloads\fedora-33.tar</div></div> </pre>
<p>You will see Fedora-33 show up in wsl’s list</p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">PS C:\Users\jperrin&gt; wsl.exe -l -v<br />
&nbsp; NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STATE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VERSION<br />
&nbsp; Fedora-33 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopped &nbsp; &nbsp; &nbsp; &nbsp; 2</div></div> </pre>
<p>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 <em>useful</em> as a wsl distro. </p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">wsl -d Fedora-33</div></div> </pre>
<p>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. </p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">dnf update<br />
dnf install wget curl sudo ncurses dnf-plugins-core dnf-utils passwd findutils</div></div> </pre>
<p><em>wslutilites</em> uses <em>curl</em> and <em>wget</em> 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. </p>
<h3>Add your user</h3>
<p>Now it’s time to add your user, and set it as the default.</p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">useradd -G wheel yourusername<br />
passwd yourusername</div></div> </pre>
<p>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.</p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">wsl -d Fedora-33 -u yourusername<br />
$id -u<br />
1000<br />
$ sudo cat /etc/shadow</div></div> </pre>
<p>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:</p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq Fedora-33 &nbsp;| Set-ItemProperty -Name DefaultUid -Value 1000</div></div> </pre>
<p>Now you should be able to launch WSL again without specifying a user, and be yourself instead of root.</p>
<h3>Customize!</h3>
<p>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</p>
<pre class="wp-block-code"> <div class="codecolorer-container text default" style="overflow:auto;border:1px solid #9F9F9F;width:435px"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace">dnf copr enable trustywolf/wslu</div></div> </pre>
<p>Now you can go configure your terminal, setup a Python development environment, or however else you want to use Fedora 33. Enjoy!</p>
</div>


https://www.sickgaming.net/blog/2020/11/...ofts-wsl2/
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016