Skip to content

Instantly share code, notes, and snippets.

@oleksis
Last active March 21, 2024 18:12
Show Gist options
  • Save oleksis/01a351e8324ed9d399fe6d489be6e4dd to your computer and use it in GitHub Desktop.
Save oleksis/01a351e8324ed9d399fe6d489be6e4dd to your computer and use it in GitHub Desktop.
Fedora 38 on WSL2 using PowerShell

Fedora 38 x86_64 on WSL2 using PowerShell

Download and import the Fedora base container (Powershell)

$DownloadURL = "https://kojipkgs.fedoraproject.org//packages/Fedora-Container-Base/38/20230801.0/images/Fedora-Container-Base-38-20230801.0.x86_64.tar.xz"
$OutputFile = "$env:USERPROFILE\Downloads\Fedora-Container-Base-38-20230801.0.x86_64.tar.xz"
Invoke-WebRequest -Uri $DownloadURL -OutFile $OutputFile

# Extract the downloaded tarball and move the root file system to the appropriate location
# winget install --id 7zip.7zip
$7ZipExe = "C:\Program Files\7-Zip\7z.exe"  # Path to 7-Zip executable
$ExtractedDir = "$env:USERPROFILE\Downloads"
$DestinationDir = "$env:USERPROFILE\Downloads\fedora-38-rootfs.tar"
Start-Process -FilePath $7ZipExe -ArgumentList "x `"$OutputFile`" -o`"$ExtractedDir`"" -Wait
$OutputFile = "$env:USERPROFILE\Downloads\" + (Get-Item $OutputFile).BaseName
Start-Process -FilePath $7ZipExe -ArgumentList "x `"$OutputFile`" -o`"$ExtractedDir`"" -Wait
Move-Item "$ExtractedDir\415297cbcfb652866bb48ca29d094653ab67d437d48a0cd864d12daa991eea68\layer.tar" $DestinationDir

# Create a new WSL distribution for Fedora
$WSLDir = "$env:USERPROFILE\wsl\Fedora"
mkdir -p $WSLDir
$RootFSPath = "$env:USERPROFILE\Downloads\fedora-38-rootfs.tar"
wsl --import Fedora $WSLDir $RootFSPath

# The output will show the list of installed distributions, and you should see "Fedora" in the list.
wsl -l -v
  NAME                    STATE           VERSION
* docker-desktop-data     Stopped         2
  rancher-desktop         Stopped         2
  openSUSE-Leap-15.5      Stopped         2
  Ubuntu                  Running         2
  Debian                  Stopped         2
  docker-desktop          Stopped         2
  Fedora                  Stopped         2
  rancher-desktop-data    Stopped         2

# Start the Fedora WSL distribution
wsl -d Fedora

Using WSL2 with support for XZ format

Check or update WSL2 >= 0.61.4

# wsl --update --pre-release
➜ wsl --update
➜ wsl -v
Versión de WSL: 1.2.5.0
Versión de kernel: 5.15.90.1
Versión de WSLg: 1.0.51
Versión de MSRDC: 1.2.3770
Versión de Direct3D: 1.608.2-61064218
Versión DXCore: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Versión de Windows: 10.0.25915.1000

Download and import Fedora to WSL2

$DownloadRootFS = "https://github.com/fedora-cloud/docker-brew-fedora/raw/38/x86_64/fedora-38-x86_64.tar.xz"
$OutputFile = "$env:USERPROFILE\Downloads\fedora-38-x86_64.tar.xz"
Invoke-WebRequest -Uri $DownloadRootFS -OutFile $OutputFile

# Create a new WSL distribution for Fedora
$WSLDir = "$env:USERPROFILE\wsl\Fedora-38"
mkdir -p $WSLDir
wsl --import Fedora-38 $WSLDir $OutputFile

# The output will show the list of installed distributions, and you should see "Fedora" in the list.
wsl -l -v
  NAME                    STATE           VERSION
* docker-desktop-data     Stopped         2
  rancher-desktop         Stopped         2
  openSUSE-Leap-15.5      Stopped         2
  Ubuntu                  Running         2
  Debian                  Stopped         2
  docker-desktop          Stopped         2
  Fedora-38               Stopped         2
  rancher-desktop-data    Stopped         2

# Start the Fedora WSL distribution
wsl -d Fedora-38

Update and configure Fedora (Bash)

dnf update
dnf install wget curl sudo ncurses dnf-plugins-core dnf-utils passwd cracklib-dicts findutils
sudo useradd -G wheel <username>
sudo passwd <username>
exit

Restart WSL and log in with the newly created user

wsl -d Fedora-38 -u <username>
printf "\n[user]\ndefault = <username>\n" | sudo tee -a /etc/wsl.conf
exit
wsl -t Fedora-38
wsl -d Fedora-38

Please replace <username> with the desired username in the script before running it. Also, make sure to run PowerShell with administrator privileges as some commands may require elevated permissions.

Now you can access your Fedora 38 environment on WSL2 with the specified username.

[oleksis@HP450-2 Downloads]$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="38 (Container Image)"
ID=fedora
VERSION_ID=38
VERSION_CODENAME=""
PLATFORM_ID="platform:f38"
PRETTY_NAME="Fedora Linux 38 (Container Image)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:38"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f38/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=38
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=38
SUPPORT_END=2024-05-14
VARIANT="Container Image"
VARIANT_ID=container

One line

image

iwr -Uri https://github.com/fedora-cloud/docker-brew-fedora/raw/38/x86_64/fedora-38-x86_64.tar.xz -OutFile fedora-38-x86_64.tar.xz && wsl --import Fedora38 $env:USERPROFILE/wsl/Fedora38 fedora-38-x86_64.tar.xz

Fedora Remix

Using the side-loaded method may need to enable developer mode on your Windows system.

image

iwr -Uri https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL/releases/download/38.0.0/Fedora-Remix-for-WSL-SL_38.0.0.0_x64_arm64.msixbundle
Add-AppxPackage .\Fedora-Remix-for-WSL-SL_*.msixbundle
fedoraremix
[oleksis@HP450-2 ~]$ cat /etc/os-release
NAME="Fedora Remix for WSL"
VERSION="38"
ID=fedoraremixforwsl
ID_LIKE=fedora
VERSION_ID=38
PLATFORM_ID="platform:f38"
PRETTY_NAME="Fedora Remix for WSL"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:38"
HOME_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL"
SUPPORT_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL"
BUG_REPORT_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL/issues"
PRIVACY_POLICY_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL/blob/master/PRIVACY.md"
FEDORA_REMIX_VERSION=38.0.0

# fedoraremix.exe config --default-user oleksis

image

Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment