Search notes:

Installing a WSL Distribution on an external harddisk

Some notes about installing a Windows Subsystem for Linux distribution on an external harddisk. I've found most of the interesting pieces in this helpful SuperUser answer.
First, I had to make sure that Hyper-V was enabled (prevent message Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.).
In order to also prevent One or several parent features are disabled so current feature can not be enabled., I use the -all option in the following command:
enable-windowsOptionalFeature -featureName microsoft-hyper-v -online -all
It should be noted that after enabling Hyper-V, I was unable to start Oracle VirtualBox anymore.
Making sure I am running wsl version 2:
wsl --set-default-version 2
Specify the directory to which the .appx file should be downloaded and the directory (on the external harddsik) where the distribution is to be installed:
$downloadDir = $env:temp
$destDir     = 'd:/wsl/debian'
I want to install Debian. A list of available download links is here.
$appxUrl = 'https://aka.ms/wsl-debian-gnulinux'

$progressPreference = 'silentlyContinue'
invoke-webRequest $appxUrl -outFile $downloadDir/linux.appx -useBasicParsing
Uncompress the downloaded appx file (which is a zip file in disguise):
cd $downloadDir
mv ./linux.appx ./linux.zip
expand-archive ./linux.zip
The extracted files contain «nested» appx's. Running a x64 system (as opposed to an ARM system), I extract the corresponding appx:
cd linux
mv DistroLauncher-Appx_1.12.2.0_x64.appx x64.zip
expand-archive x64.zip
The extracted files are moved to the hardddisk:
cd x64
$null = mkdir $destDir
mv *  $destDir
I am finally able to install the distribution:
cd $destDir
./debian

Configuring the installation

After installing the distribution, I had to add the following two lines to /etc/wsl.conf so that the command wsl.exe opens a shell as rene rather than root:
[user]
default=rene

Index