Linux apps on Windows 10 and Chrome OS

Penguin Travel

GUI with Pitfalls

Microsoft promised native support for graphical Linux applications out of the box last year but had unfortunately only implemented this as a preview in the Insider program by the editorial deadline. Microsoft's technical approach of adding a second internal VM on top of the Linux VM to translate Wayland and X11 applications to RDP on Linux is interesting (Figure 1); however, at the time of writing, it was not yet known when this feature would find its way from the Insider program into a production build of Windows 10.

Figure 1: Microsoft is working on its own GUI solution that translates Wayland and X11 apps to RDP [3]. © devblogs.microsoft.com

Even without installing an Insider version, you do not have to do without a GUI until then. Compared with WSL1, however, other roads lead to Rome. Although the developers of Kali Linux already had a suitable script ready for the earlier edition, Win-KeX now makes the whole thing even easier [4]. The command

sudo apt install -y kali-win-kex

enables the system to display a complete desktop environment, as well as individual applications.

Other distributions are helped by an X server for Windows, such as the X410 app available from the Microsoft Store [5]. Although it is not free, it integrates very well into the system. If you launch X410 from the Start menu, the server initially only appears as an "X" in the taskbar system tray area, and you can set the mode from the icon's context menu. For Windowed Apps integration mode, X410 takes care of Windows management itself and waits for Linux applications to display in separate windows. A floating desktop displays a Linux desktop in a scalable window, and the full desktop takes up the entire screen area.

As a special feature, compared with its predecessor, a Linux instance in connection with WSL2 no longer uses the local loopback address 127.0.0.1 or the name localhost internally, but a dynamic IP address assigned by Windows for virtual computers.

Starting a graphical environment therefore requires additional steps. Enable the Allow Public Access option in the X410 context menu and allow a suitable exception in the Windows firewall if X410 asks you to do so. Now, continue to Linux, where you can install the Xfce window manager on Ubuntu:

sudo apt-get install -y xfce4 xfce4-terminal

The following shell command dynamically determines the IP address of the Linux instance at runtime and writes it to the DISPLAY environment variable:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

Next, start a desktop session with xfce4-session. The X client on Linux exports the graphical output to the dynamic IP address, and X410 – as the X server on Windows – displays it. You can reach your goal more quickly batching on Windows to complete all the necessary steps in one go:

start /B x410.exe /desktop
ubuntu.exe run "if [ -z \"$(pidof xfce4-session)\" ]; then export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0; xfce4-session; pkill '(gpg|ssh)-agent'; fi;"

The /desktop parameter loads a floating desktop, and /wm alternatively lets you start a single application, such as the Firefox browser, instead of a complete Xfce 4 session. Thus far, what I have described is especially useful if you want to use graphical Linux applications that are not available under Windows.

Linux as a Server, Windows as a Client

An equally useful scenario that fits in with many practical use cases is to run only a server back end on Linux without a GUI and the graphical tools on Windows. For example, you can install and start the Nginx web server on Ubuntu:

sudo apt-get install -y nginx
sudo service nginx start

In the Windows-to-Linux direction, access over localhost still works. Accordingly, on Windows, typing http://localhost in the browser takes you to the Nginx homepage, but you will notice that you cannot get the web server to start automatically in the conventional way. WSL does not use the systemd init system, even in version 2. Consequently, calling the systemctl command to manage systemd services will not work, so you need to open the shell configuration with nano ~/.bashrc and add the following lines at the end of the file:

# Start Nginx
sudo /etc/init.d/nginx start

Last but not least, use sudo visudo to make the web server start automatically without asking for a password. At the end of this configuration, enter:

# Start Nginx
%sudo ALL=NOPASSWD: /etc/init.d/nginx

The next time you start the Linux distribution, the web server will automatically start running. Following the same recipe, you can now add further services (e.g., PHP and MySQL) and expand your development environment on Linux. You can still edit web pages and scripts conveniently on Windows.

Filesystems Without Borders

WSL2 also allows bidirectional filesystem operations between Windows and Linux. As with its predecessor, you will automatically find all the drives available under Windows in the Linux environment with their respective drive letters in paths such as /mnt/c and /mnt/d. Conversely, you can access the Linux filesystem from Windows with network shares. In Windows Explorer, all installed distributions appear with their respective names within the \\wsl$ share and provide their root filesystems this way.

Therefore, you can use your familiar graphical tools on Windows in conjunction with server components under Linux to match the target platform. Microsoft's popular Visual Studio Code editor offers even more convenience and supports seamless integration with the Remote Development extension package and the Remote-WSL component it contains [6]. The code <filename> shell command on Linux opens the file in question directly in the editor on Windows. In return, the editor running on Windows installs extensions useful for development in the Linux environment. The two worlds thus work together in the best possible way (Figure 2).

Figure 2: Shell, GUI via X server, filesystem, or even Visual Studio code – Windows and Linux integrate in many ways.

If you want to back up a Linux environment configured to suit your needs and transfer it to another system, the wsl command-line tool will help with this, too. To back up an installation of Ubuntu, then restore the backup on the same or different system, enter:

wsl --export Ubuntu c:\temp\ubuntu.tar
wsl --import Ubuntu <target directory> c:\temp\ubuntu.tar

By default, the Linux distributions are located in the personal profile of the Windows user running the program in %userprofile%\AppData\Local\Packages. A freshly installed Ubuntu 20.04 LTS without extras occupies just over 1GB, and the backup file is similar in size. For server daemons and with a GUI, this can quickly become several gigabytes.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=