Skip to content

DevelopersCommunity/archlinux-wsl

 
 

Repository files navigation

WSL Arch Linux Launcher

Introduction

This is an Arch Linux installer/launcher for the Windows Subsystem for Linux (WSL). This installer was built using the WSL Distro Launcher Reference Implementation.

Image

The image used by this installer is based on the Arch Linux docker base image available in the Arch Linux docker repository with the following changes:

The script used to make these changes is available in the scripts' directory.

Installation

The Arch Linux installer is packaged with the MSIX format, and is available in the releases page The package was signed with a self-signed certificate, you need to import it into one of your local machine certificate trusted store (for example, Trusted People) before executing the installer. Run the following PowerShell command to import it (you will need administrative privileges). The certificate is available in the scripts' directory. After installing the package, you can remove it from your store.

Import-Certificate `
    -FilePath .\DistroLauncher-Appx_TemporaryKey.crt `
    -CertStoreLocation cert:\LocalMachine\TrustedPeople

Besides creating the default user, the installation process also initializes the pacman mirror list and its key ring.

Post-installation

Customize the image

You can package your own custom image with the following steps. More details are available at https://docs.microsoft.com/windows/wsl/use-custom-distro#import-the-tar-file-into-wsl.

  1. Create a folder to store the distribution (for example, C:\wslDistroStorage\ArchLinux).

  2. Download one of the images available at https://gitlab.archlinux.org/archlinux/archlinux-docker/-/releases. Extract the tar file to any folder and run the following command to import it to WSL:

    wsl --import ArchLinux `
        C:\wslDistroStorage\ArchLinux `
        .\base-XXXXXXXX.X.XXXXX.tar
  3. Use the command wsl -d ArchLinux to run the newly imported Arch Linux distribution.

  4. Make any customization you want to your distro.

  5. When you are done with the customization, logout from WSL and run the following commands to export the image. You can install 7-zip by running winget install -e --id 7zip.7zip.

    wsl --terminate ArchLinux
    wsl --export ArchLinux .\install.tar
    & "$env:ProgramFiles\7-Zip\7z.exe" a .\install.tar.gz .\install.tar
    
    # Optionally remove this distro
    # wsl --unregister ArchLinux

Set up the development environment

If you don't have Visual Studio, you can download the free Community edition with winget:

winget install -e --id Microsoft.VisualStudio.2022.Community

# Run the following command with an elevated PowerShell session
# to install the required workloads to build this project
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\setup.exe" modify `
    --productId Microsoft.VisualStudio.Product.Community `
    --channelId VisualStudio.17.Release `
    --add Microsoft.VisualStudio.Workload.NativeDesktop `
    --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
    --add Microsoft.VisualStudio.Component.Windows10SDK.19041 `
    --add Microsoft.VisualStudio.Workload.Universal `
    --passive

Open the main solution DistroLauncher.sln with Visual Studio and generate a test certificate:

  1. In Visual Studio, open DistroLauncher-Appx/MyDistro.appxmanifest
  2. Select the Packaging tab
  3. Select "Choose Certificate"
  4. Click the "Create" button

Building the project

Create a sub-folder with name x64 in the root folder of this project and copy the customized image.tar.gz file to it.

PS C:\repos\archlinux-wsl> tree /F
Folder PATH listing
C:.
│   .gitignore
│   build.bat
│   DistroLauncher.sln
│   LICENSE
│   README.md
│
├───DistroLauncher
|   |   ...
|
├───DistroLauncher-Appx
│   │   ...
│
├───scripts
|   |   ...
│
└───x64
    │   install.tar.gz
    │   ...

Use the Windows Start menu to open the "Developer Command Prompt for Visual Studio", go to the root folder of this project and run .\build.bat rel.

Once you've completed the build, the packaged MSIX should be placed in the folder x64\Release\DistroLauncher-Appx and should have a name with the format DistroLauncher-Appx_1.1.XXXXX.0_x64.msix.

Before using the package, you need to import the certificate used to sign it. You can extract the certificate with Git Bash and OpenSSL:

openssl pkcs12 \
    -in path/to/DistroLauncher-Appx_TemporaryKey.pfx \
    -out path/to/DistroLauncher-Appx_TemporaryKey.crt \
    -nokeys \
    -passin pass:

After extracting the certificate, you can import it to a certificate store with the same command described in the installation section.

With the certificate installed, double-click the MSIX file to start your custom distro installation process.

Arch Linux trademark

The logos used in this launcher were taken from the Arch Linux logos and artwork page, and I believe their usage in this project fits the permitted use condition from their trademark policy.