from Matthias Dillier

WSL with Rocky Linux 9

Linux

Use Linux and Windows in parallel

Although many users want to work with Linux, they also need to be able to work on a Windows computer for various reasons. There are different ways to use Windows and Rocky Linux - or another Linux distribution - on the same computer at the same time.

Dualboot

Rocky Linux can be installed from a bootable data carrier (DVD, USB stick, disc) with a Rocky Linux ISO file in a separate disc partition on a computer on which Windows is already installed.

When restarting the computer, you can then select whether Rocky Linux or Windows should be started.

Advantages

  • Full-fledged Linux
  • Low resource consumption for Linux

Disadvantages

  • No connection between Windows and Linux except via disc partitions that are attached by both systems.
  • Restarting the computer is necessary to change the operating system.

Virtual machine

A virtual machine with Rocky Linux (or another Linux variant) or with another Windows version offers an interesting opportunity to use a second or even several additional operating systems in virtual machines on a Windows computer.

VirtualBox is probably the best-known variant for running a virtual machine under Windows with open source software.

Another variant is, Hyper-V from Microsoft. Hyper-V is a manager for virtual machines under Windows. Hyper-V may need to be installed via "Settings → System → Optional features → More Windows features" or via +R 'appwiz.cpl' Return and select 'Activate and deactivate Windows features' first. The computer must then be restarted so that Hyper-V can be used.

Hyper-V is actually only available for Windows 10/11 Pro, but can apparently also be installed for the Home versions. Here the instructions from Netzwelt.

Once Hyper-V has been activated, the Hyper-V Manager virtual machines can be created with Linux and other systems. A VM with Ubuntu can then be created via 'Quick Create'.

For a virtual machine with Rocky Linux 9, the Minimum ISO file for Rocky Linux and then imported into the Hyper-V Manager to create a virtual machine. To do this, 'New → Virtual computer' must be selected in the Hyper-V Manager.

You can find various instructions for installing Rocky Linux in Hyper-V under Windows on YouTube.

Advantages

  • Easy testing of different operating systems on one computer.
  • Fully-fledged virtual computer with Linux.
  • Runs in parallel with Windows in a separate window.

Disadvantages

  • Requires quite a lot of resources for the virtual machine.
  • No direct data exchange, but data exchange between Windows and Linux is possible via scp, sftp or a shared mounted disc.

WSL (Windows subsystem for Linux)

I am referring here to WSL 2 (currently WSL version 2.1.5.0). WSL 2 can be installed from the Microsoft Store. It requires Windows 11 or a relatively new Windows 10 version. Check the requirements for WSL 2 here.

WSL 2

WSL 2 is faster than version 1 and offers some options that were not yet available with WSL 1. A comparison, including the remaining disadvantages of WSL 2 compared to WSL 1, can be found, for example, at this website from Microsoft.

WSL 2 uses a normal one, complete Linux kernel in a Hyper-V virtual machine and thus offers full compatibility of the system calls with a normal Linux installation. A Linux distribution runs under WSL 2 in an isolated container in a managed virtual machine. WSL 2 now also supports systemd and ipv6.

WSL 2 uses a Linux kernel optimised for WSLwhich is optimised in terms of size and performance. The kernel is kept up to date with the normal Windows updates.

WSL 2 is well integrated into Windows. Copy/paste between Windows and a Linux distribution in WSL 2 is supported. Windows file systems (drives) are automatically mounted in Linux and can be used from Linux. The drive C: is for example /mnt/c available.

Linux applications with a graphical user interface can be installed in WSL 2. They can then be started not only in WSL, but also via the Windows Start menu under the name of the Linux distribution installed in WSL.

Advantages

  • Fast boot time and relatively low resource consumption.
  • Fast Linux system.
  • Simultaneous use of Windows and Linux, as Linux simply runs in its own windows under Windows.
  • Kernel updates are made with the normal Windows updates.
  • Fully-fledged Linux distribution
  • Good integration of Windows and Linux (copy/paste, file system, etc.)
  • Programmes with graphical user interface supported and well integrated into Windows.
  • VSCode under Windows can be used with the Remote WSL Extension as a good and preformant development environment for projects in the Linux file system.

Disadvantages

  • There are still restrictions on the use of interfaces and external devices.
  • Reboot only from outside WLS.
  • Access to files between the Linux and Windows file systems is somewhat slow.

Installation of Rocky Linux in WSL

Installation of standard distributions for WSL

Microsoft provides a few Linux distributions for WSL that can be easily installed. The following command provides a list of available distributions.

wsl --list --online

Below you will find a list of valid distributions that can be installed.

Execute the installation using the command "wsl.exe --install ".

NAME FRIENDLY NAME

Ubuntu Ubuntu

Debian Debian GNU/Linux

kali-linux Kali Linux Rolling

Ubuntu-18.04 Ubuntu 18.04 LTS

Ubuntu-20.04 Ubuntu 20.04 LTS

Ubuntu-22.04 Ubuntu 22.04 LTS

Ubuntu-24.04 Ubuntu 24.04 LTS

OracleLinux_7_9 Oracle Linux 7.9

OracleLinux_8_7 Oracle Linux 8.7

OracleLinux_9_1 Oracle Linux 9.1

openSUSE Leap 15.5 openSUSE Leap 15.5

SUSE Linux Enterprise Server 15 SP4 SUSE Linux Enterprise Server 15 SP4

SUSE Linux Enterprise 15 SP5 SUSE Linux Enterprise 15 SP5

With the command wsl --install Ubuntu is installed in WLS. With the parameter -d another of the distributions listed above can be installed, e.g. OpenSuse 15.5 with the command wls --install -d openSUSE-Leap-15.5.

Installation of Rocky Linux

Distributions other than those provided by Microsoft, especially Rocky Linux, can also be installed and used in WSL without any problems.

With new WSL 2 versions, it is no longer necessary to already have a Linux distribution installed in WSL and Docker Desktop, as is still the case in most instructions.

Only the following steps are necessary:

  1. Download tar.xz or tar file with the root file system of the Linux distribution
  2. Create a directory to store the Linux files
  3. Import tar file into WSL
  4. Start WSL with the distribution
  5. Perform Linux update
  6. Restart WSL

You can then install any other software you want to use and configure Linux as required, e.g. you can now set up users.

For RockyLinux, the following steps and commands must be carried out for installation in WSL:

  1. tar.xz file here download
  2. Create directory, e.g:
    mkdir C:\data\tools\wsl\wslDistroStorage\rockylinux
  3. wsl --import rockylinux C:\data\tools\wsl\wslDistroStorage\rockyLinux Path_to_downloaded_file\Rocky-9-Container-Base.latest.x86_64.tar.xz
    The distribution can then be displayed with the following command (together with any distributions already installed):
    wsl -l -v
    NAME STATE VERSION
    rockylinux Stopped 2
  4. wsl -d rockylinux
  5. dnf update
  6. In WSL:
    exit or logout
    In a Windows command window:
    wsl -shutdown
    wsl -d rockylinux

Rocky Linux can be set as the default distribution with the command that can be entered in the PowerShell or a command window:

wsl --setdefault rockylinux

Use of systemd

In newer versions of WSL 2, the installed Linux distributions systemd can be used.

ATTENTION, systemd must be installed first if it is not already installed! For Rocky Linux, you can use the following command to see whether systemd is already installed.

sudo dnf info systemd

If systemd is not yet installed, it must first be installed with the command

sudo dnf install systemd

In order for systemd to be used after the next restart of the WSL, an entry must be made in the file /etc/wsl.conf in the file system of Rocky Linux. This can be done as root user with the following command:

tee -a /etc/wsl.conf > /dev/null <<EOT
[boat]
systemd=true
EOT

WSL must then be restarted. The following command can be used in WSL to check whether systemd is running:

sudo systemctl list-unit-files --type=service

If the configuration for systemd in /etc/wsl.conf has been made, but systemd is not yet installed, you will get the following error message when you try to restart WSL:

wsl -d rockylinux
Serious error (resp. catastrophic failure)
Error code: Wsl/Service/CreateInstance/E_UNEXPECTED

This problem is then almost impossible to solve. It is possible to mount the file system of the affected Linux distribution from another distribution installed in WSL and remove the entry for systemd in the configuration file. However, this is somewhat cumbersome and often the simpler option is to delete the distribution and reinstall it.

Windows Terminal and WSL Terminal

When working on the command line in WSL, it is best to use WSL Terminal. You can find WLS Terminal (wsltty) on GitHub.

If you start WSL Terminal, WSL is also started immediately.

Alternatively, you can also use Windows Terminal, which is provided by the Microsoft Store can be downloaded.

Windows Terminal is more practical than cmd.exe. For example, you can use it to open several shells in different tabs.

Conclusion

WSL version 2 is powerful, fast and well integrated into Windows. It supports systemd and GUI applications and provides a practically fully-fledged Linux that is almost as fast as a directly installed Linux.

If you need Windows and Linux together and if direct access to the hardware from Linux is not important, WSL is a good choice. WSL can also be used to easily access Windows file systems. A Linux distribution can be installed quickly and easily in WSL and it is possible to install and use different distributions at the same time. This is particularly useful for tests with different Linux versions.

The Swissmakers engineering team will be happy to help you with any questions you may have about Rocky Linux. Learn more here more about Rocky Linux and our service.

Photo of author

Matthias Dillier

mathematician, computer scientist and saxophonist with many years of experience in in various areas of computer science. He is currently particularly involved in monitoring, problem analyses, log evaluations, graphics and the automation and the automation of operating processes.

Hinterlassen Sie einen Kommentar

20 − eleven =

en_GB