WSL: Red Hat Enterprise Linux 8
“I don’t doubt at all that virtualization is useful in some areas. What I doubt rather strongly is that it will ever have the kind of impact that the people involved in virtualization want it to have.” — Linus Torvalds per quotefancy.com
This article would not be possible without the contributions of Joshua Mitchell who is currently studying Computer Engineering at the Georgia Institute of Technology. Thanks Joshua!
Much of this document is inspired by WSL2+RHEL8: The Whale with the Red Hat :: ~/wsl.dev — Get your Linux On. To install Windows Subsystem for Linux on your machine, installation instructions can be found at https://learn.microsoft.com/en-us/windows/wsl/install
This tutorial uses Windows 10 Enterprise with Windows Subsystem for Linux (WSL) 2.0 running Ubuntu 22.04. This, in turn, can be used to create a WSL that can run Red Hat Enterprise Linux version 8, as will be shown.
Be sure you have a free Red Hat Developer account for accessing the RHEL8 image. Steps to do so are covered on this site: VirtualBox Red Hat Guest on Windows Host; scroll down to the RH Developer Subscription section. After one year you will need to renew your subscription. Instructions are here https://developers.redhat.com/articles/renew-your-red-hat-developer-program-subscription
Installing Red Hat in WSL
Before we begin installing Red Hat onto our system, we first want to add a directory to export our RHEL8 image. Navigate to your C:\ drive in File Explorer and create a new folder titled “wslsources.”
To begin the installation, open Windows Subsystem for Linux. Next, make sure you have Podman installed on WSL Ubuntu by typing the command below (note you can also use Docker (software) for this but our company likes Podman):
apt install podman -y
Now, enter the following two commands. The first command verifies your credentials to the Red Hat registry and will ask for your username and password, while the latter pulls the RHEL8 base image onto your device. Use your RHEL8 developer subscription credentials when logging in.
podman login registry.redhat.io
podman run --name rhel8 registry.redhat.io/rhel8/go-toolset
Next, input the following command to export your RHEL8 subsystem to the targeted file location. Note, this will NOT work in a Windows terminal, so be sure you are still in the WSL Ubuntu terminal.
podman export -o /mnt/c/wslsources/rhel8.tar.gz rhel8
This second command is optional, but it will verify that your file is in the correct location.
ll /mnt/c/wslsources/rhel8.tar.gz
/mnt/c allows WSL to access your Windows file directories, so if you check your Windows C folder, there should now be a wslsources folder with your rhel8.tar file inside!
Go ahead and close the Windows Subsystem for Linux Ubuntu terminal, as you will not be needing it for the rest of the installation.
Installing RHEL 8 into WSL
Move to Windows PowerShell. Here, we will create a wsldistros directory and import our downloaded container as a distro before launching it and lastly checking that the proper version is installed:
# Create a new directory for containing the WSL custom distros, or move into it if already created
mkdir c:\wsldistros
cd c:\wsldistros
# Import the container file as a WSL v2 distro
wsl --import rhel8 ./rhel8 c:\wslsources\rhel8.tar.gz
# Launch the new distro
wsl -d rhel8
# Check with version is installed
cat /etc/os-release
Now that we know Red Hat is properly imported, we can go ahead and register the application. First, enter the following command and once again enter your username and password as the prompts appear.
subscription-manager register
Next, enter the following four commands to setup our subscriptions for RHEL:
subscription-manager role --set="Red Hat Enterprise Linux WSL"
subscription-manager service-level --set="Self-Support"
subscription-manager usage --set="Development/Test"
subscription-manager attach
You should also be able to see your virtual system added at https://access.redhat.com/management and clicking on the “View all Systems” link!
If everything seems to be in order, go ahead and update RHEL:
dnf update
If you would like to exit your Red Hat image, you can use the two commands below. The first command will take you back to your WSL screen, while the second command terminates the Red Hat image while in WSL.
exit
wsl -–terminate rhel8
To access WSL on PowerShell at any point, simply reopen the terminal and type the following command:
wsl -d rhel8
Using RHEL 8
Adding a new user is very simple, and this tutorial assumes we will no longer be logged in as root. So, we will also have to enable sudo privileges to do All The Things. The first time you use sudo, as well as after enough time has passed after the last use, sudo will force you to enter your password before making system modifications, which may help you catch yourself from accidentally making an egregious mistake down the line. See the “Additional Notes” section near the end of this document for more information on how to change the sudo timeout value.
dnf install -y sudo
Now we can create a user by inputting the first line into the terminal, replacing <username> with your username. Then type the second line, again replacing <username> with your username. This will ask you to create a new password, which you will input into the terminal.
sudo useradd -m -s /bin/bash -G wheel <username>
passwd <username>
Note: Once we complete the next step, Red Hat should automatically launch with your user logged in. In case you log out of Red Hat before completing the next step, you can use this command in PowerShell to launch your image with the correct user logged in (once again replacing <username> with your username):
wsl -d rhel8 --user <username>
Next edit the wsl.conf file. The example below uses vi, but you can use your favorite text editor to accomplish the next steps. Once you’re ready, enter the following command to begin creating your config file:
sudo vi /etc/wsl.conf
Add the following information to the config file, once again replacing <username> at the bottom with your chosen username. Close the file once you are finished.
[automount]
enabled = true
mountfstab = true
root = /mnt/
options = metadata,uid=1000,gid=1000,umask=0022,fmask=11,case=off
[network]
generatehosts = true
generateresolvconf = true
hostname = rhel8
[interop]
enabled = true
appendwindowspath = true
[user]
default = <username>
You can use the cat command to check that the file was properly created:
cat /etc/wsl.conf
Go ahead and terminate and then relaunch the Red Hat distro with the following three commands. The ‘--terminate’ command is necessary here to ensure that Red Hat does not keep using the old wsl.conf file. After inputting these, you should be automatically logged in with your username.
exit
wsl -–terminate rhel8
wsl -d rhel8
Due to an oddity of Windows Subsystem for Linux that we couldn’t figure out how to get around, your path likely does not point to your user’s home folder when rhel8 launches, rather to your home directory from Windows’ point of view. Using this command, we can fix this and point your starting path to the proper directory -- note that you may want to back up your original $HOME/.bashrc file before doing this:
sed -i '$a\cd' $HOME/.bashrc
This uses Linux’s built-in stream editor (sed) command. Here's an explanation of each component:
sed: The command for stream editing.
-i: This option tells sed to edit the file in-place, meaning it will modify the file directly.
'$a\cd': $ represents the last line of the file, and a\ appends the text ‘cd’ after the specified line.
$HOME/.bashrc represents the name of the file you want to modify.
Go ahead and log out and back in. You should now see your user logged in to your home directory, which you can check by typing ‘pwd’ into the terminal. If so, congrats! Your RHEL8 distro has been successfully set up through WSL!
Installing Useful Packages
Now that we have a new user added to our WSL, we can add some tools to give it some functionality.
Some very useful tools to add are the Extra Packages for Enterprise Linux (EPEL), which provide you access to a wealth of other packages and can be installed with the following two commands:
sudo subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
This command installs the tools and libraries for your Red Hat image necessary for C++ development:
sudo dnf install libarchive-devel zlib-devel gcc-c++ cmake make vim clang clang-tools-extra
Optional Packages/Tools
Below are other packages and tools that some users may find to be useful on their distro.
Installing bash-completion enables a user to press tab midway through writing a command to allow the terminal to automatically finish writing the item, such as the name of a directory.
sudo dnf install bash-completion
Gitk is a neat tool that allows you to visualize the git history of your repository. It is written in Tcl-tk, a programming language that enables different applications to communicate with each other and facilitates GUI development. These commands will install and configure gitk:
sudo dnf install git gitk
git config --global user.name <username>
git config --global user.email <email>
Installing trash-cli allows a user to throw files in the ‘trash,’ similar to using the recycling bin on Windows or the trash bin on Mac.
sudo dnf install trash-cli
Additional Note
You can modify the sudo timeout value to change the amount of time it takes between using sudo before you need to enter your password again to run certain commands. The sudo timeout value can be customized by modifying the sudoers file, which is typically accessed using the visudo command. The sudoers file contains configuration directives that determine the behavior of sudo, including the timeout duration.
Open a terminal and run the following command to edit the sudoers file:
sudo visudo
Locate the line that begins with Defaults env_reset in the sudoers file. This line specifies the default settings for sudo. Append the timestamp timeout option followed by the desired timeout value, in minutes. For example, to set the timeout to 10 minutes, add the following line:
Defaults env_reset,timestamp_timeout=10
Save the changes and exit the editor.
After modifying the sudoers file, the new timeout value will take effect. Users will need to authenticate with their password the next time they use sudo, and the timeout will start counting from that moment.
Summary of commands
This installation guide has equipped you with a functioning Red Hat image operated through Windows Subsystem for Linux (WSL) and accessed with PowerShell. The registered image includes a variety of tools to address the needs of the user.
You can use these to commands to open and close Red Hat in PowerShell, respectively:
wsl -d rhel8
wsl -–terminate rhel8
If you would like to launch Red Hat with a specific user, such as if you have multiple users, this command will launch the image with the designated user:
wsl -d rhel8 --user <username>
Feedback
As always, do make a comment or write me an email if you have something to say about this post!
Credits
WSL2+RHEL8: The Whale with the Red Hat :: ~/wsl.dev — Get your Linux On
https://learn.microsoft.com/en-us/windows/wsl/install
Linux Stream Editor (sed) instructions as well as the visudo(8) instructions were generated with ChatGPT (openai.com)