Linux GUI
Applications on
Windows Subsystem
for Linux [WSL2]
Developers Perspective
Jim McKeeth
Chief Developer Advocate
Embarcadero Technologies
jim.mckeeth@embarcadero.com
@JimMcKeeth
Slides, links & replay: blogs.embarcadero.com/?p=130922
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Agenda
▪ Introduction to WSL
▪ Setup and configuration
▪ Different Linux Distributions
▪ Deploying and debugging
▪ Troubleshooting
▪ Advanced Options
▪ Q&A
Slides, links & replay: blogs.embarcadero.com/?p=130922
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Presenter: Jim McKeeth
● Chief Developer Advocate & Engineer for Embarcadero
● Long time software developer
○ Delphi, C/C++, Python, Java, JavaScript, Ruby, etc.
● Invented and patented pattern and swipe to unlock
○ e.g. US Patents # 8352745 & 6766456
● Built thought controlled drone with Google Glass and
wireless EEG headset
● Contributor to Internet of Things and Data Analytics Handbook
● Blogger, podcaster, conference speaker, webinar host, etc.
● Twitter, TikTok, YouTube, etc. @JimMcKeeth
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Windows Subsystem for Linux
● Introduced in Windows 10
○ Trivia: Replaces Windows Services for Unix from 2004
○ Also available on Windows 11 and Windows Server 2019
● Developed in collaboration with Canonical and others
● WSL2 improved performance with a real Linux kernel
○ Uses a subset of Hyper-V features
● Not as isolated or as much overhead as a VM
○ Performance rivals native Linux
● WSLg adds GUI support
○ Ships in Windows 11 or Windows 10 Insider 21364
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Addressing the
Elephant in
the Room…
&
LINUX
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
"a step
"The whole backward in the
anti-Microsoft thing was campaign for
sometimes funny as a freedom."
joke… I feel like, yes, https://tek.io/3ufuXWR
they have changed… So
I completely dismissed
all the anti-Microsoft
stuff."
https://zd.net/35x8YjE
Linus Torvalds Richard Stallman
Creator of Linux kernel Found of FSF & GNU
Img https://w.wiki/4n93 Img https://w.wiki/4n8x
“It’s not like Microsoft is
stealing our toys, it’s
more that we’re sharing
them with Microsoft in
order to give everyone
the best possible
experience.”
https://tek.io/3ufuXWR
Satya Nadella
Microsoft CEO
https://zd.net/3IQSst6
Mark Shuttleworth
Img https://w.wiki/4n9G Founder & CEO Canonical
Img https://w.wiki/4n9H
Copyright © 2022 by Embarcadero, an Idera company RAD STUDIO
Delphi 11
Benefits and Use Cases
● Ability to run unmodified ELF64 Linux binaries, expand toolkit and capabilities
● Flexibility of combining Windows and Linux tool chain on one computer
● Less overhead than a traditional virtual machine means better performance
● Local build environment with containers, etc.
● Testing server applications from Windows without additional infrastructure
● No need to mess with dual boot or 3rd party VM installation
● Invoke Linux binaries from Windows and Windows executables from Linux
● Runs as you need it, less management
● Memory and drive space are dynamically shared
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
WSL Installation Guide
● Enable "Windows Subsystem for Linux" optional feature (via Admin PowerShell or Windows Features)
○ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
● Install Linux Distro of Choice
○ Windows Store or manually via script
● Launch Linux Distro to initialize it, provide password, etc.
● You can also build a custom distro
● Launch WSL 4 ways
○ Icon on start menu
○ [distro], for example ubuntu
○ wsl.exe or bash.exe
○ wsl [command] or bash -c [command]
https://docs.microsoft.com/en-us/windows/wsl/install
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Available Distributions
● Ubuntu, Kali, & Pengwin are in the
Debian family (using .deb pkgs - apt)
○ Kali is focused on security
○ Pengwin is designed around WSL
● SUSE and Fedora are in the RPM family
with Red Hat
● Alpine is an independent, lightweight,
security-oriented, Linux distribution
● Some distros include multiple versions
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Managing WSL Distros
● List distributions
○ wsl --list --all or wsl --list --running
● Set default distribution
○ wsl --setdefault <DistributionName> or wsl -s <DistributionName>
● Run a specific distro
○ wsl --distribution <DistributionName>
● Run as specified user
○ wsl --user <Username> (or use the specific distro name)
● Unregister and uninstall a distribution
○ wsl --unregister <DistributionName>
● Shutdown all WSL instances
○ wsl --shutdown
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
First Run
▪ On first run you are usually
prompted for a username and
password
▪ openSUSE uses YaST2 for a
nice ASCII GUI
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Connecting from the IDE
● Tools -> Options -> Deployment ->
Connection Profile Manager
● The IP address and ports are shared with
the host
● So you connect to 127.0.0.1
● Can only use each port number once
(even if you have multiple distros setup)
● So use different port numbers for
multiple instances if you want to run
them simultaneously
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Linux User Password Reset
1. Note your username
2. From Windows terminal get the distro name
➢ wsl -l
3. From Windows terminal switch default-user to root
➢ ubuntu config --default-user root
4. Launch the WSL distro (you will be logged in as root)
➢ ubuntu
5. Change the user’s password
➢ passwd username
6. Change the default user back
➢ ubuntu config --default-user username
7. Launch the WSL distro again
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Accessing Files Between Systems
● Access Windows from Linux
○ cd /mnt/c/
● Open WSL in current Windows directory
○ wsl
○ wsl -d ubuntu
○ ubuntu
● Access Linux from Windows
○ \\wsl.localhost
● Open current Linux path from Windows
○ explorer.exe .
○ cmd.exe
○ powershell.exe
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Demonstration
Copyright © 2022 by Embarcadero, an Idera company RAD STUDIO
Delphi 11
Windows Subsystem for Linux resources
● Command Line Blog (includes WSL) http://aka.ms/cliblog
● Learn WSL http://aka.ms/learnwsl
● WSL Docs http://aka.ms/wsldocs
● Connect USB to WSL https://aka.ms/wsl-usbip
● WSL: Run Linux GUI Apps youtu.be/kC3eWRPzeWw
● Deep Dive in WSL2 youtu.be/lwhMThePdIo
● Windows Dev Tool Updates: WSL, Terminal, Package Manager, and more youtu.be/m5tt9mDRPSw
Slides, links & replay: blogs.embarcadero.com/?p=130922
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
More WSL Resources
● Advanced WSL Launcher / Installer (Simplify making your own WSL distro)
○ https://github.com/yuk7/wsldl
● Other prebuilt distros based on WSLDL
○ https://wsldl-pg.github.io/docs/Using-wsldl/#distros
● Collection of WSL Utilities
○ https://github.com/wslutilities/wslu
● A GUI WSL2 instance manager
○ https://github.com/bostrot/wsl2-distro-manager
● Awesome list for WSL
○ https://github.com/sirredbeard/Awesome-WSL
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
FMXLinux Resources
● DocWiki: Linux Application Development
○ docwiki.embarcadero.com/RADStudio/en/Linux_Application_Development
● DocWiki: Installing the Platform Assistant on Linux
○ docwiki.embarcadero.com/RADStudio/en/Installing_the_Platform_Assistant_on_Linux
● DocWiki: FireMonkey for Linux
○ docwiki.embarcadero.com/RADStudio/en/FireMonkey_for_Linux
● Script to automate setup on Ubuntu
○ embt.co/Ubuntu4Delphi22
● Script to automate setup on Redhat
○ embt.co/RedHat4Delphi22
Slides, links & replay: blogs.embarcadero.com/?p=130922
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Setting up CentOS (Redhat based) embt.co/RedHat4Delphi22
● Install Docker in Ubuntu docs.docker.com/engine/install/ubuntu/
● Follow steps docs.microsoft.com/en-us/windows/wsl/use-custom-distro
● Base OS
○ Make folder on Windows C:\WSL\CentOS ● By Redhat &
Community
○ From Ubuntu
Fedora ● Feature focus
● Free
■ sudo service docker start
■ sudo docker run -t dokken/centos-stream-9 bash ls /
■ dockerContainerID=$(sudo docker container ls -a | grep -i
dokken/centos-stream-9 | awk '{print $1}')
■ sudo docker export $dockerContainerID > /mnt/c/WSL/CentOS/centos.tar
■ sudo docker rm $dockerContainerID
● By Redhat
○ From PowerShell Redhat ●
●
Supported
Stable focus
● Commercial
■ cd C:\WSL\CentOS\
■ wsl --import CentOS C:\WSL\CentOS\ .\centos.tar
○ From CentOS
■ yum update -y && yum install passwd sudo -y
■ myUsername=jim
■ adduser -G wheel $myUsername
■ echo -e "[user]\ndefault=$myUsername" >> /etc/wsl.conf ● By community
■ passwd $myUsername CentOS ●
●
No support
Free
○ From PowerShell
■ wsl --terminate CentOS
Copyright © 2022 by Embarcadero, an Idera company Delphi 11
Q&A
Linux GUI
Applications on
Jim McKeeth
Windows Subsystem Chief Developer Advocate
for Linux [WSL2]
Embarcadero Technologies
jim.mckeeth@embarcadero.com
@JimMcKeeth
Slides, links & replay: blogs.embarcadero.com/?p=130922
Copyright © 2022 by Embarcadero, an Idera company RAD STUDIO
Delphi 11
Copyright © 2022 by Embarcadero, an Idera company Delphi 11