Linux Format

Linux inside Windows

Run Linux apps on Microsoft’s OS in Windows Subsystem for Linux 2.

-

The origins of WSL (Windows Subsystem for Linux) lies in Microsoft’s Project Astoria, a tool originally designed to port Android apps to Windows 10 Mobile. The project was killed in 2016 but the code formed the basis of WSL, which was released in beta later in the same year. Unlike third-party apps like Cygwin, WSL’s initial aim was native Linux compatibil­ity through serving Unix programs as custom isolated ‘pico processes’.

In May 2019, Microsoft announced the release of WSL2, a huge improvemen­t over its predecesso­r, given it uses virtualisa­tion to run Linux kernels inside a lightweigh­t virtual machine. This not only improves performanc­e but adds full system call compatibil­ity.

Both WSL2 and compatible Linux distros can easily be installed via the command line or Microsoft Store.

WSL’s ‘so what?’ moment

While WSL2 is certainly a much more efficient way of implementi­ng Linux in Windows, it still needs to pass the ‘so what?’ test. In other words, why shouldn’t Linux developers and other interested parties just keep on running full distros of Linux in a dedicated virtual machine using software like VMWare or VirtualBox?

The fact, for instance, that WSL2 now has GPU support and can even run GUI Linux apps is hardly enough reason to switch, as most VM software can do the same. As far as developers are concerned though, there’s every reason to take WSL2 for a spin. Not only is the setup incredibly simple but you can easily create and switch between distros with just a few keystrokes.

Files can be stored in isolated Linux filesystem­s, and updates can be carried out automatica­lly across every installed distro. Command-line tools such as Bash, Vim and so on are supported out of the box and you can install more via the distro’s own package manager.

Crucially, using WSL2 gives you the ability to invoke Windows applicatio­ns via the shell. Installed Linux apps

are also listed in the Windows Start Menu, so can easily be launched there or via the command line.

Start your subsystems!

If you’re now convinced it’s worth taking WSL2 for a spin, first make sure that your copy of Windows is up to date by typing updates into the search bar and choosing Windows Update. If you’re using Windows 190, you need to be running version 21H1, 21H2, or 22H2 in order to use WSL2.

WSL2 also uses Hyper-V. This requires 64-bit hardware virtualisa­tion support which you must enable in your BIOS. Check with your motherboar­d manufactur­er if you’re unsure how to do this.

Once this is done, save and close any open files. Command-line lovers can run cmd.exe or open Windows PowerShell to begin installati­on with:

$ wsl – install

If the installer hangs (as it did for us), or you’re more a fan of the GUI, you can also search for WSL2 in the Microsoft Store and hit Get to begin setup.

Once the install is complete, you need to check that Virtual Platforms are enabled. In the Windows search bar, find and select Turn Windows Features On Or Off. From here you can check the box marked Virtual Machine Platform.

By default, WSL2 installs Ubuntu but you can install another distro if you wish. If you used the Microsoft Store to search for WSL2, you can see all available distros listed and install them by clicking Get.

Still, the best way to view currently available distros is via the command line: c.

Install your chosen distro using:

$ wsl --install -d

For example:

$ wsl --install -d

For this tutorial, we’re using Ubuntu 22.04 LTS. If you want to install a distro that isn’t available for download, WSL2 also supports importing other distros via a tar file. Follow the steps on Microsoft’s Support site to do this (https://learn.microsoft.com/en-us/ windows/wsl/use-custom-distro).

Once install is complete, restart your PC. After logging back in to the desktop, open the Start Menu to view a shortcut to your Linux distro of choice. If you click to launch, your distro opens in PowerShell. You’re prompted to set a username and password.

Next, make sure your OS is fully up to date with:

$ sudo apt-get update

$ sudo apt-get upgrade If you’re using PowerShell, you can also check for kernel updates with: $ wsl --update

Installing and running programs now works in the same way as any terminal utility in Linux. For instance, try installing popular Tetris clone Bastet with:

$ sudo apt-get install bastet

Introducin­g GUI apps

Installing terminal utilities and games is all well and good, but frankly you can achieve much the same thing by logging into a remote Linux server via SSH.

The real fun lies in the fact that Windows now supports both X11 and Wayland Linux GUI applicatio­ns. This means you can launch Linux apps from the Start Menu, pin them to the Windows taskbar, switch between them and Windows apps using tabs, and even use copy and paste.

To get started, you need to install a driver to use a virtual GPU (vGPU) that supports hardwareac­celerated OpenGL rendering. You can find links to drivers for popular graphics cards at: https://learn. microsoft.com/en-us/windows/wsl/tutorials/gui-apps.

You also need to have at least Windows 10 Build 19044+ or Windows 11 installed to use this feature.

Once you have downloaded and installed the necessary GPU installers, open PowerShell and then update it with:

$ wsl --update

Next, you need to restart WSL2 for this update to take effect by running:

$ wsl --shutdown

Use the Start Menu to launch your chosen distro again, then update the OS itself again with:

$ sudo apt-get update

You can now install a GUI app, such as the

Rhythmbox music player, for example, which is usually only available for Linux:

$ sudo apt-get install rhythmbox

Once the install is complete, you can launch the app in question by searching via the Windows Start Menu. If you did choose Rhythmbox or any app from which you need to access local files, this is a good time to learn how they’re managed in WSL2.

Windows files can be accessed from within your Linux distributi­on from /mnt/. For instance, we pointed Rhythmbox towards our music folder at /mnt/c/Users/ nate1/Music.

You can equally use the Windows File Explorer to browse your Linux directorie­s. Simply use cd to navigate to your chosen parent folder via the command line and then run explorer.exe.

 ?? ?? WSL2 can be installed via cmd.exe or the Microsoft Store. You can also use the store to install more Linux distros.
WSL2 can be installed via cmd.exe or the Microsoft Store. You can also use the store to install more Linux distros.
 ?? ??
 ?? ?? Linux apps can access Windows files and folders via /mnt. Here, Rhythmbox is playing an MP3 file in the Windows Music folder.
Linux apps can access Windows files and folders via /mnt. Here, Rhythmbox is playing an MP3 file in the Windows Music folder.
 ?? ?? Once your chosen distro is installed, you can immediatel­y download and run any terminal program available via the OS’s package manager.
Once your chosen distro is installed, you can immediatel­y download and run any terminal program available via the OS’s package manager.
 ?? ??

Newspapers in English

Newspapers from Australia