3. Windows Subsystem for Linux
As long as you do not need deterministic real-time behavior, you may use WSL2 (Windows Subsystem for Linux version 2) for development purposes of your Real-time Linux applications. Physical hardware access is also rather limited when using WSL2.
3.1. Setting Up WSL2 and Ubuntu 24.04 on Windows 10
This guide provides step-by-step instructions on how to enable Windows Subsystem for Linux (WSL2) and install Ubuntu 24.04 on a Windows 10 system.
3.1.1. Prerequisites
A system running Windows 10, version 1903 or higher.
Internet connection to download the necessary files from Microsoft Store.
3.1.2. Step 1: Enable Windows Subsystem for Linux (WSL)
Open PowerShell as Administrator: Right-click on the Start button and select Windows PowerShell (Admin).
Enable WSL: In the PowerShell window, run the following command to enable WSL:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Enable Virtual Machine Platform: WSL2 requires the Virtual Machine Platform feature. Run the following command to enable it:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Restart Your Computer: After enabling both features, restart your machine to apply the changes.
3.1.3. Step 2: Set WSL2 as the Default Version
Open PowerShell as Administrator.
Set WSL2 as the Default Version: Run the following command to set WSL2 as the default version for any future Linux distributions:
wsl --set-default-version 2
3.1.4. Step 3: Install Ubuntu 24.04
Open Microsoft Store: Open the Microsoft Store from the Start menu.
Search for Ubuntu: Search for Ubuntu 24.04 in the Microsoft Store.
Install Ubuntu 24.04: Click the Install button to download and install Ubuntu 24.04.
3.1.5. Step 4: Initialize Ubuntu 24.04
Launch Ubuntu: Open Ubuntu 24.04 from the Start menu or by typing “Ubuntu” in the search bar.
Set Up Ubuntu: On the first launch, follow the on-screen instructions to create a new user and set a password.
Update Packages: After the setup, it is recommended to update the package list and upgrade any outdated packages:
sudo apt update sudo apt upgrade -y
3.1.6. Optional: Check WSL Version
You can verify the installed WSL distributions and their versions, or set a specific version for a distribution.
List installed WSL distributions and versions:
wsl -l -v
Set WSL version for a specific distribution:
wsl --set-version <distro_name> 2 Replace ``<distro_name>`` with the name of the installed distribution (e.g., ``Ubuntu-24.04``).
After following these steps, you should have WSL2 and Ubuntu 24.04 installed and running on your Windows 10 machine.
3.2. Enabling SSH on Ubuntu 24.04 in WSL2
This guide will walk you through enabling and configuring SSH on an Ubuntu 24.04 distribution running in WSL2 on Windows 10.
3.2.1. Step 1: Install the OpenSSH Server
Open your Ubuntu terminal in WSL2.
Install the OpenSSH server by running the following commands:
sudo apt update sudo apt install openssh-server -y
3.2.2. Step 2: Start and Enable the SSH Service
Start the SSH service by running:
sudo service ssh start
Check the SSH service status to ensure it is running:
sudo service ssh status
(Optional) Enable SSH service on startup. While WSL2 doesn’t start services automatically by default, you can enable SSH to start automatically if needed:
sudo systemctl enable ssh
3.2.3. Step 3: Configure SSH (Optional)
Edit the SSH configuration file located at:
sudo nano /etc/ssh/sshd_config
Modify the settings as needed, such as changing the default port or enabling/disabling root login.
After making any changes, restart the SSH service to apply them:
sudo service ssh restart
3.2.4. Step 4: Find the WSL2 IP Address
WSL2 uses dynamic IP addresses that change with each session. To connect via SSH, you need the current IP address of your WSL2 instance.
Find the WSL2 IP address by running:
ip addr show eth0 | grep inet
The command will output something like
inet 172.30.32.1/20. The IP address before the slash (e.g.,172.30.32.1) is the address you will use to connect via SSH.
3.2.5. Step 5: Connect via SSH from Windows
From the Windows host, you can use an SSH client, such as PowerShell or PuTTY.
Connect to your WSL2 instance from a PowerShell terminal by running:
ssh username@<wsl_ip_address>
Replace
usernamewith your Ubuntu username and<wsl_ip_address>with the IP address you retrieved in Step 4.
3.2.6. Step 6: Enable Port Forwarding (Optional)
If you want to access the SSH server from outside WSL2 (e.g., from Windows or external devices), set up port forwarding:
Open PowerShell as Administrator and run the following command:
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=22 connectaddress=<wsl_ip_address>
Replace
<wsl_ip_address>with the IP address of your WSL2 instance.SSH into your WSL2 instance from the Windows host using:
ssh username@localhost -p 2222
Replace
usernamewith your Ubuntu username.
3.3. Setting Up Avahi Daemon for mDNS with a Fixed Hostname
This guide explains how to install avahi-daemon on Ubuntu in WSL2 and configure a fixed hostname for mDNS.
3.3.1. Step 1: Install Avahi Daemon
Open the Ubuntu terminal in WSL2.
Install `avahi-daemon` by running the following commands:
sudo apt update sudo apt install avahi-daemon -y sudo service avahi-daemon start
3.3.2. Step 2: Check the mDNS hostname
Check the mDNS hostname:
systemctl status avahi-daemon
The avahi daemon may have recognized a hostname conflict with Windows 10 and thus chose another name. This name typically ends with .local.
3.3.3. Step 3: Verify the New Hostname
Ping the new `.local` hostname to verify mDNS is working:
ping newhostname.local
3.4. Setting Up Remote Debugging
3.4.1. Step 1: Install gdbserver
Open the Ubuntu terminal in WSL2.
Install `gdbserver` by running the following commands:
sudo apt update sudo apt install gdbserver -y
3.4.2. Step 2: Configure Debugging Client (e.g. Visual Studio with VisualGDB)
Open the Debug Client, e.g. Visual Studio
Configure the SSH connection to use the IP address or the hostname of Ubuntu.