Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save linuxmalaysia/491098eea7160aa184e85c19d6b68acc to your computer and use it in GitHub Desktop.
Save linuxmalaysia/491098eea7160aa184e85c19d6b68acc to your computer and use it in GitHub Desktop.
Install WSL2 and Move AlmaLinux 9 to Another Drive

HOWTO: Install Almalinux 9 WSL2 and Move AlmaLinux 9 to Another Drive

TL;DR

A guide for myself—born from my professional experience as a Linux system administrator and enhanced with 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 installing AlmaLinux 9 onto a non-default drive (D:), ensuring a secure and efficient setup.


Phase 1: Installing WSL2 on Windows 11 Pro

Enable the Virtual Machine Platform and WSL Features

  1. Open PowerShell as Administrator.
  2. Enable WSL by running:
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all
  3. Enable the Virtual Machine Platform (required for WSL2):
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all
  4. Restart the computer when prompted.

Set WSL 2 as the Default Version

  1. Open PowerShell as Administrator.
  2. Set WSL2 as the default version:
    wsl --set-default-version 2

Install AlmaLinux 9 WSL Distribution

  1. Download the AlmaLinux 9 WSL package from AlmaLinux WSL.
  2. Locate and double-click the .appx file to launch the App Installer.
  3. Click Install to proceed.

Launch AlmaLinux 9 and Complete Initial Setup

  1. Open PowerShell or Command Prompt.
  2. Verify the installation:
    wsl -l -v
  3. Launch AlmaLinux 9:
    wsl -d AlmaLinux9
  4. Create a user account and set a strong password.
  5. You can check AlmaLinux 9 instance running or stopped
    wsl --list --verbose

Phase 2: Moving AlmaLinux 9 to Drive D

By default, WSL distributions are installed on the C: drive. This section guides you through moving AlmaLinux 9 to the D: drive for better disk management.

Identify the ext4.vhdx File Location

  1. Open File Explorer.
  2. Navigate to:
    C:\Users\<YourUsername>\AppData\Local\Packages
    
  3. Locate the folder named:
    AlmaLinuxOSFoundation.AlmaLinux9_<some_unique_string>
    
  4. Open the folder, then navigate to LocalState.
  5. Find ext4.vhdx, which contains your AlmaLinux 9 installation.

Create a Backup Folder (Optional)

  1. Open PowerShell as Administrator.
  2. Make sure you have Shutdown AlmaLinux 9.
  3. Create a backup directory:
    New-Item -ItemType Directory -Path "D:\WSL\AlmaLinux9-Template"
  4. Copy the ext4.vhdx file to the backup folder:
    Copy-Item "C:\Users\<YourUsername>\AppData\Local\Packages\AlmaLinuxOSFoundation.AlmaLinux9_<unique_string>\LocalState\ext4.vhdx" -Destination "D:\WSL\AlmaLinux9-Template\ext4.vhdx"

Move AlmaLinux 9 to Drive D

  1. Create the new installation folder:
    New-Item -ItemType Directory -Path "D:\WSL\AlmaLinux9"
  2. Shutdown AlmaLinux 9:
    wsl -t AlmaLinux9
    Or shut down all WSL instances:
    wsl --shutdown
  3. Unregister the existing AlmaLinux distribution:
    wsl --unregister AlmaLinux9
  4. Import the distribution from the new location:
    wsl --import AlmaLinux9 D:\WSL\AlmaLinux9 D:\WSL\AlmaLinux9-Template\ext4.vhdx

Set Default User (Optional)

Set the default user AlmaLinux 9:

wsl -d AlmaLinux9 -u almalinux

Launch and Verify

  1. Launch AlmaLinux 9:
    wsl -d AlmaLinux9
  2. Confirm it is functioning correctly.

Security Considerations

  • Enable the firewall inside AlmaLinux:
    wsl -d AlmaLinux9
    sudo systemctl start firewalld
    sudo systemctl enable firewalld
    sudo firewall-cmd --set-default-zone=public
  • Configure Windows Firewall rules if exposing network services.

Performance Note

The performance of AlmaLinux in WSL2 depends on the speed of the D drive. SSDs provide better performance than HDDs.


Conclusion

Congratulations! You have successfully installed WSL2 and moved AlmaLinux 9 to the D: drive. Remember to keep your system updated:

sudo dnf update -y

Stay vigilant with security best practices!

Harisfazillah Jamel LinuxMalaysia

20250401


References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment