#Installing Ubuntu 24.04.x on WSL on Windows 11
#These two items are the minimum install:
1 2 3 |
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart |
#If you want bridged networking then you also have to install Hyper-V so you can create a bridged virtual switch.
1 |
dism.exe /online /enable-feature /all /featurename:Microsoft-Hyper-V |
#Reboot
Update WSL:
1 |
wsl --update |
#Other wsl.exe options include:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#Specify the Linux distribution to install. You can find available distributions by running wsl --list --online. --distribution #Install the Linux distribution but do not launch it automatically. --no-launch #Install from an online source rather than using the Microsoft Store. --web-download #When WSL is not installed options include: #Installs WSL using the Windows component instead of using the Microsoft Store. (WSL updates will be received via Windows updates, rather than pushed out as-available via the store). --inbox #Enables WSL 1 during the install of the Microsoft Store version of WSL by also enabling the "Windows Subsystem for Linux" optional component. --enable-wsl1 #Do not install a distribution when installing WSL. --no-distribution |
#Installing WSL with a Custom Tarball
When the Microsoft Store is disabled, you can manually install WSL by downloading a custom tarball. In my case, I have downloaded ubuntu-noble-wsl-amd64-wsl.rootfs.tar.gz
from the Ubuntu Cloud WSL Image page. This tarball contains the root filesystem for Ubuntu, which you can use to manually set up WSL without needing the Store.
#Download the WSL image you need from the link below:
https://cloud-images.ubuntu.com/wsl #Look for Noble folders
#Then run the command below from and elevated command prompt:
1 |
wsl --import Ubuntu24 Z:\WSL\Ubuntu24.04 c:\users\username\download\ubuntu-noble-wsl-amd64-wsl.rootfs.tar.gz --version 2 |
A few things to note:
-
-
- To use WSL without the Microsoft Store, for me, Developer Mode needed to be enabled on my Windows system. This had to be done through Microsoft Intune by duplicating and assigning a policy that allows Developer Mode. Please be sure that installing WSL is approved by your IT department before installing if you are on a computer that you use for work purposes.
- You will initially be logged in as root and this is not meant to be your primary user, at all. Many things only run as root and many more will not run as root. You do not want to leave this, as is, even in a non-production environment.
-
#This is the version that is current for me now but there are updates so keep reading.
1 |
Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.6.87.1-microsoft-standard-WSL2 x86_64) |
#Set WSL distribution’s virtual disk is set to be sparse:
#This will allow the virtual disk to automatically shrink when files are removed from the distribution
1 |
wsl --manage Ubuntu24 --set-sparse true |
#Another way to manually set a WSL installation to sparse
#Add sparseVhd=true
to the [wsl2]
section of your .wslconfig
file. The .wslconfig file doesn’t already exist most likely. It is located in windows in your home directory usually located at c:\users\username\.wslconfig
#It is not common for a windows file name to begin with a . but that is not a typo. . is the identifier for hidden files in Linux.
#Now manually imported Linux distributions do not automatically read .wslconfig files so you also need to download wsldl.exe and set that up to launch with as described later on in this post.
#To use the wsldl.exe
launcher with your imported WSL distribution and enable it to utilize the .wslconfig
file, follow these steps:
#Steps to Configure wsldl.exe
- Download
wsldl.exe
: Ensure you have the latest version ofwsldl.exe
from the official wsldl repository . - Prepare Your Directory:
- Create a folder where you want to store your distribution.
- Place the downloaded
wsldl.exe
in this folder and rename it to the desired name for your distribution (e.g.,MyDistro.exe
) .
- Add Your Root Filesystem:
- Place your exported root filesystem tar file (e.g.,
rootfs.tar.gz
) in the same directory aswsldl.exe
. Ensure that the tar file is named correctly asrootfs.tar.gz
.
- Place your exported root filesystem tar file (e.g.,
- Run the Launcher:
- Right-click on the renamed
wsldl.exe
(e.g.,MyDistro.exe
) and select “Run as administrator.” This step is crucial for proper registration and functionality .
- Right-click on the renamed
- Configure
.wslconfig
:- Create or edit a
.wslconfig
file in your Windows user directory (usually located atC:\Users\<YourUsername>\.wslconfig
). This file allows you to set various WSL configurations, such as memory limits and processor settings. - Example content for
.wslconfig
:text[wsl2]
memory=4GB
processors=2
- Create or edit a
- Launch Your Distribution:
- After running the launcher, you can access your distribution via the command line using its name (e.g.,
MyDistro
). This will allow it to recognize and utilize settings specified in.wslconfig
.
- After running the launcher, you can access your distribution via the command line using its name (e.g.,
#Your imported WSL distribution should now work with the wsldl.exe
launcher and respect the configurations set in your.wslconfig
file.
#Change the default user for a distribution using wsldl.exe
1 |
Ubuntu24.exe config --default-user username |
#Change the default user username for your distribution log-in. The user has to already exist inside the distribution in order to become the default user.
#For example: Ubuntu config --default-user johndoe
would change the default user for the WSL instance called “Ubuntu” to the “johndoe” user.
#Note:
#If you are having trouble figuring out the name of your distribution, use the command wsl -l
.
#Warning:
#This command will not work for imported distributions, because these distributions do not have an executable launcher. You can instead change the default user for imported distributions using the /etc/wsl.conf file. See the Automount options in the Advanced Settings Configuration doc.
#Update and configure Ubuntu 24.04.x LTS on Windows 11 WSL
#Run update for the first time to initialize apt
1 |
sudo apt update |
#Install the necessary packages that allow apt to use packages over HTTPS:
1 |
sudo apt install apt-transport-https ca-certificates curl software-properties-common |
1 |
sudo mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /etc/apt/apt.conf.d/20apt-esm-hook.conf.bak |
1 |
sudo nano /var/lib/ubuntu-advantage/apt-esm/etc/apt/sources.list.d/ubuntu-esm-apps.sources |
#Add a new primary user
1 |
adduser primaryuser |
#Enter a new password and provide any user information you wish to then add the new user to sudousers.
1 |
usermod -aG sudo primaryuser |
#Edit the /etc/wsl.conf file:
#Open the /etc/wsl.conf file in a text editor. You might need to create this file if it doesn’t exist:
1 |
nano /etc/wsl.conf |
#Add the Configuration for the Default User:
#Add the following lines to the file to set the default user:
1 2 |
[user] default=primaryuser |
#Enable bridged networking instead of NAT
#Create a new bridged virtual switch called WSL
1 |
New-VMSwitch -Name "WSL" -NetAdapterName "Ethernet" -AllowManagementOS $true |
#List configured virtual switches
1 |
Get-VMSwitch |
#Nexts steps to enable bridged networking and to disable IPv6 in WSL2
#Edit the .wslconfig File:
#Create or edit the .wslconfig file located in your user directory (typically C:\Users\<YourUsername>\.wslconfig).
#These settings tell WSL2 to disable IPv6 at the kernel level and to use the virtual switch called WSL. If you want IPv6 spport then simply omit that line from your .wslconfig
#Add the following lines to the file:
1 2 3 4 |
[wsl2] kernelCommandLine=ipv6.disable=1 networkingMode = bridged vmSwitch = WSL |
#After saving the changes, you need to shut down WSL for the changes to take effect. You can do this by running the following command in PowerShell or Command Prompt:
1 |
wsl --shutdown |
#Enable syncookies, disable responses for pings to the broadcast, enable ip spoof protection, disable ICMP redirects and disable source routing. You can do so by adding the following lines to /etc/sysctl.conf
1 |
net.ipv4.icmp_echo_ignore_broadcasts = 1 |
1 |
net.ipv4.conf.all.rp_filter = 1 |
1 |
net.ipv4.conf.all.accept_redirects = 0 |
1 |
net.ipv4.conf.all.accept_source_route = 0 |
#If you are using NAT rather than bridged networking
#You do not need to do this if you are using bridged mode and DHCP is automatically obtained from your primary DHCP server.
-
-
WSL NAT mode gives your Linux environment a private IP and makes all traffic appear to come from your host’s IP. This hides your WSL instance from direct access from the Internet, providing a layer of protection.
-
WSL bridged mode lets your Linux environment get its own IP on the network, like a separate computer. This means your WSL session is directly reachable from the Internet or other devices on the network, so it’s more important to secure it properly.
-
#This means NAT hides WSL behind your host’s IP, while bridged mode makes WSL act like its own device on the network.
#Set permanent DNS to an external DNS provider for NAT
#To prevent the /etc/resolv.conf
file from being automatically generated and overwritten by WSL via /etc/wsl.conf
1 |
sudo nano /etc/wsl.conf |
#Add:
1 2 |
[network] generateResolvConf = false |
#The /etc/resolv.conf
file is often a symlink to another file that gets automatically generated. To prevent it from being overwritten, you should remove the symlink and create a regular file:
#List contents of /etc/resolv.conf
1 |
cat /etc/resolv.conf |
#Default Settings in an automatically created resolv.conf
1 2 3 |
nameserver 127.0.0.53 options edns0 trust-ad search . |
#Get DNS Status
1 |
resolvectl status |
#Remove the existing symlink:
1 2 |
sudo rm /etc/resolv.conf |
#Create a new /etc/resolv.conf
file:
1 2 |
sudo touch /etc/resolv.conf |
#Edit the new file to add your preferred DNS servers. For example:
1 |
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf |
#Add additional DNS servers (note tee -a (for append))
1 |
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf |
#Install and configure zsh shell
#Install zsh (git is needed for the theme I use)
1 |
sudo apt install zsh git |
#Configure zsh as your default shell.
1 |
chsh -s $(which zsh) |
#Run zsh
1 |
zsh |
#Press 2 to create a default config file if prompted
#Configure zsh for root user. You do not need to do this step if you don’t use sudo -i like I do. Operating like that is not recommended but often I am in a non-production environment when I do so exit. This will not work if you were not prompted to create a default .zshrc file. You can run this later if you need to after installing oh.my.zsh.
1 2 3 4 5 6 |
sudo -i #sudo interactive mode {password] chsh -s $(which zsh) root #sets zsh as default shell for root cp /home/username/.zshrc /root/.zshrc #copy config from a normal user source ~/.zshrc #to load new config exit #when ready |
#Install oh.my.zsh
1 |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
#I use the Powerlevel10k theme. You can download it from here. This is a per use install and should be installed on a non-root user 1st then sudo -i if you want that too.
1 |
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k |
#Edit .zshrc configuration file
1 |
nano ~/.zshrc |
#Change to:
1 |
ZSH_THEME="powerlevel10k/powerlevel10k" |
#Source ~/.zshrc to change to powerlevel10k ohmyzsh theme.
1 |
source ~/.zshrc |
#Answer questions about your screen for customized terminal font support
#Output:
1 2 3 4 5 6 7 8 9 10 |
#Output: New config: ~/.p10k.zsh. Backup of ~/.zshrc: /tmp/.zshrc.DcpifTQyna. See ~/.zshrc changes: diff /tmp/.zshrc.DcpifTQyna ~/.zshrc File feature requests and bug reports at https://github.com/romkatv/powerlevel10k/issues |
#Create Mount Points in WSL
#Create directories in WSL where you want to mount the CD-ROM drives:
#Check This PC in Windows 11 if you are unsure which drive letter your optical drives uses.
#If your CD/DVD is at D:\ in Windows
1 |
sudo mkdir -p /mnt/d |
#If your CD/DVD is at E:\ in Windows
1 |
sudo mkdir -p /mnt/e |
#Mount the CD-ROM Drives Using drvfs
#If your CD/DVD is at D:\ in Windows
1 |
sudo mount -t drvfs D: /mnt/d |
#If your CD/DVD is at E:\ in Windows
1 |
sudo mount -t drvfs E: /mnt/e |