HOWTO: Install WSL2 and Move AlmaLinux 9 to Another Drive
HOWTO: Install WSL2 and Move AlmaLinux 9 to Another Drive
TL;DR A guide for myself. A product of my professional experience as a Linux system administrator, enhanced and articulated with the aid of AI tools to ensure comprehensive coverage and clarity for technical audiences.
This guide details the process of installing the Windows Subsystem for Linux version 2 (WSL2) on Windows 11 Pro and subsequently installing AlmaLinux 9 onto a non-default drive (D:), ensuring a secure and efficient setup.
Copies around the web
https://gist.github.com/linuxmalaysia/491098eea7160aa184e85c19d6b68acc
Phase 1: Installing WSL2 on Windows 11 Pro
Enable the Virtual Machine Platform and WSL Features
Open PowerShell as Administrator. This elevated privilege is necessary to modify system features.
Execute the following command to enable the core WSL functionality:
PowerShell
This command utilises the Deployment Image Servicing and Management tool (dism.exe) to enable the specified Windows feature.
Execute the subsequent command to enable the Virtual Machine Platform, which is essential for WSL2's virtualisation capabilities:
PowerShell
WSL2 runs within a lightweight virtual machine, necessitating this feature.
Restart the computer when prompted. This restart is crucial for the changes to take effect.
Set WSL 2 as the Default Version
Open PowerShell as Administrator.
Run the following command to configure WSL to use the more performant WSL2 architecture by default:
PowerShell
WSL2 offers significant performance improvements over WSL1 due to its full system call compatibility.
Install the AlmaLinux 9 WSL Distribution
Open a web browser and navigate to the AlmaLinux WSL page: https://wsl.almalinux.org/.
Download the AlmaLinux 9 .appx package. The file will likely be named AlmaLinuxOS-9_latest_x64.appx. Save it to a convenient location, such as the Downloads folder.
Open File Explorer and navigate to the directory where downloaded from the .appx file.
Double-click the AlmaLinuxOS-9_latest_x64.appx file. This will launch the App Installer.
Click on the "Install" button. Windows will proceed to install the AlmaLinux 9 WSL distribution.
Launch AlmaLinux 9 and Complete Initial Setup
Open PowerShell or Command Prompt.
List the installed WSL distributions to confirm AlmaLinux 9 is present:
PowerShell
Launch the AlmaLinux 9 distribution
PowerShell
This will prompt us to create a user account and set a password for the almalinux user. Choose a strong and unique password.
Phase 2: Moving AlmaLinux 9 to Drive D
By default, WSL distributions are installed on the C: drive. This phase will guide you through moving your AlmaLinux 9 installation to the D: drive, which can be beneficial for managing disk space or for organisational purposes.
Identify the Location of the ext4.vhdx file
Open File Explorer.
Navigate to the following path (ensure you have enabled viewing hidden items):
Replace <YourUsername> with your actual Windows username.
Look for a folder with a name that is related to AlmaLinux. It is highly likely to be named:
AlmaLinuxOSFoundation.AlmaLinux9_<some_unique_string>
For example, you might see a folder named:
The part after AlmaLinux9_ is a unique identifier for your installation.
Navigate into this AlmaLinux package folder, then into the LocalState subfolder.
Inside the LocalState folder, you should find the ext4.vhdx file (where VHDX stands for Virtual Hard Disk v2, the file format used by WSL2 to store the Linux file system). This is the virtual hard disk file containing your AlmaLinux 9 installation.
Create a Backup Folder (Optional but Recommended for Backup)
Open PowerShell as Administrator.
Create a folder on your D drive to store a copy of the original ext4.vhdx file as a backup. This also can be used as a template.
PowerShell
Copy the ext4.vhdx file to the Template Folder
Copy the ext4.vhdx file from its original location to the template folder on your D drive.
PowerShell
Replace <unique_string> with the actual unique part of your AlmaLinux package folder name.
Create the Permanent Installation Folder on Drive D
Create the folder where you want the AlmaLinux 9 distribution to reside permanently.
PowerShell
Shutdown AlmaLinux:
Ensure the AlmaLinux 9 WSL instance is completely shut down before proceeding.
PowerShell
Alternatively, shut down all WSL instances:
PowerShell
Unregister the Existing AlmaLinux Distribution:
Unregister the AlmaLinux distribution that was installed in the default location. This is necessary to import it from the new location.
PowerShell
Import the Distribution from the Moved ext4.vhdx:
Import the distribution using the wsl --import command, specifying the new location on the D drive.
PowerShell (one whole line)
Where:
AlmaLinux9: The name you want to give to the imported distribution.
D:\WSL\AlmaLinux9: The directory on your D drive where WSL will create the necessary files and metadata for the distribution.
D:\WSL\AlmaLinux9-Template\ext4.vhdx: The path to the copied ext4.vhdx file on your D drive.
Set the Default User (Optional):
Set the default user for the AlmaLinux 9 distribution (likely almalinux).
PowerShell
Launch and Verify:
Launch the newly imported AlmaLinux 9 distribution:
PowerShell
Verify that it is working correctly.
Security Considerations
While you have set a password for your AlmaLinux user, it is crucial to further secure your environment. It is highly recommended to enable and configure the firewall within AlmaLinux. You can typically do this by starting and enabling the firewalld service, you may need to install systemd:
PowerShell
Additionally, if you intend to expose any network services running within AlmaLinux to your Windows host or the network, you may need to configure appropriate rules in the Windows Firewall.
Performance Note: Please be aware that the performance of your AlmaLinux environment may be influenced by the read/write speed of your D drive. Solid State Drives (SSDs) generally offer better performance compared to traditional Hard Disk Drives (HDDs).
Congratulations! You have successfully installed WSL2 and moved your AlmaLinux 9 distribution to your D drive. Remember to keep your AlmaLinux system updated regularly using sudo dnf update and to stay vigilant about security best practices.
References
https://www.siberoloji.com/install-podman-almalinux/
https://learn.microsoft.com/en-us/windows/wsl/systemd
https://medium.com/@sharansh.sinha/wsl-2-installation-on-different-drive-3d9f0cc88850
The systemd is not enabled by default in WSL2. However, Microsoft has provided a way to enable it.
HOWTO: Enable systemd in AlmaLinux 9 WSL2 on Windows 11 Pro
This guide outlines the steps to enable the systemd init system within your AlmaLinux 9 WSL2 environment on Windows 11 Pro. This allows you to run applications and services that rely on systemd functionality.
Prerequisites
WSL2 Installed: You have already installed WSL2 on your Windows 11 Pro system.
AlmaLinux 9 Installed in WSL2: You have successfully installed AlmaLinux 9 as a WSL2 distribution.
Sufficient WSL Version: Ensure your WSL version is recent enough to support systemd. Open PowerShell and run:
PowerShell
wsl --version
The WSL kernel version should be 5.15 or higher. If not, update WSL:
PowerShell
wsl --update
Also, ensure your Windows installation is up to date.
Steps to Enable systemd
Access Your AlmaLinux 9 WSL Distribution:
Open PowerShell and launch your AlmaLinux 9 distribution:
PowerShell
wsl -d AlmaLinux9
(Replace AlmaLinux9 with the actual name of your distribution if you named it differently).
Edit the wsl.conf File
Inside your AlmaLinux 9 terminal, edit the wsl.conf file. If it doesn't exist, create it. This file configures settings for your WSL distributions.1
Bash
sudo nano /etc/wsl.conf
Add the systemd Boot Option:
Add the following lines to the wsl.conf file:
ini, TOML
[boot]
systemd=true
This tells WSL to initialise the distribution with systemd as the init process.
Save and Close wsl.conf
In nano, press Ctrl+X, then Y to confirm saving, and then Enter.
Completely Shutdown the WSL Instance
It's crucial to completely shut down the AlmaLinux 9 WSL instance for the configuration change to take effect. Closing the terminal window is not enough. Open PowerShell and run:
PowerShell
wsl --shutdown
Restart AlmaLinux 9:
Launch your AlmaLinux 9 distribution again:
PowerShell
wsl -d AlmaLinux9
Verify systemd is Running:
Once AlmaLinux 9 is running, verify that systemd is the init process:
Bash
ps -ef | grep systemd
You should see systemd with PID 1.
Important Considerations
Resource Usage: Enabling systemd will increase the resource consumption of your WSL2 instance.
Potential Compatibility Issues: While generally improving compatibility, there might be specific scenarios where enabling systemd introduces new issues.
WSL Updates: Keep your WSL installation updated as Microsoft continues to refine systemd support.
Now that systemd is enabled within your AlmaLinux 9 WSL2 environment, you should be able to install and run applications that depend on it.
For example, to install and run the httpd web server:
Bash
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
You should be able to access the web server on localhost from your Windows browser.
This HOWTO provides the steps to enable systemd within your AlmaLinux 9 WSL2 environment. Remember to monitor resource usage and be aware of potential compatibility nuances.