DEV Community

Discussion on: Install Fedora 37 or earlier on Windows Subsystem for Linux (WSL)

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

Great automation!