Amazon Linux 2023 on WSL2
This post is an update to Amazon Linux 2022 on WSL2 after container images of AL2023 were made available on the Amazon Linux CDN.
Like almost any Linux distribution that has a container image available, you can run Amazon Linux 2023 on the Windows Subsystem for Linux. This guide assumes you've installed and configured WSL2 and already have something like Debian running under it.
Download
AL2023 container images can be downloaded from: https://cdn.amazonlinux.com/al2023/os-images/latest/container/
WSL will be able to import the .tar.xz
file directly.
Import
From PowerShell or Command Line, import the image into WSL (you may want to choose a different InstallLocation
than I have here):
wsl --import AL2023 C:\WSL\AL2023 Downloads\al2023-container-<version>-x86_64.tar.xz
Assuming that succeeded you can log in (as root):
wsl --distribution AL2023
Processing fstab with mount -a failed.
[root@Lenovo-M90n andrew]# cat /etc/os-release
NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
SUPPORT_END="2028-03-15"
Install Missing Packages
Now even though we used the container
image and not container-minimal
, a lot of the things you'd find in an AL2023 AMI are missing. That's why Processing fstab with mount -a failed.
It's meant to be a container runtime image, not a user-interactive image, so this is normally fine.
dnf -y install util-linux passwd sudo
That will get you mount
, useradd
, passwd
and sudo
, which are all you need for the remaining steps. sudo
recommends system-default-editor
which will default to nano
. I'm old enough to prefer vim
, and if you add vim-default-editor
to the dnf install
command it will skip nano
.
You probably also want to know when updates are available with the new repository versions feature.
dnf -y install 'dnf-command(check-release-update)'
Configure
If you want an unprivileged user, you'll need to add one and set a password (the --groups wheel
option makes it so this user can use sudo
):
useradd \
--create-home \
--user-group --groups wheel \
--comment User \
user
passwd user
To configure WSL to use that user by default, you also need to create an /etc/wsl.conf
file with the following content:
[user]
default = user
Log out, terminate the VM, and start it again. This time you should be logged in as the user you created earlier:
wsl --terminate AL2023
# Wait 8 seconds?
wsl --distribution AL2023
To get it to show up under Windows Terminal you might need to stop WSL or reboot:
wsl --shutdown
I've also needed to delete the state.json
file from %LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\
to get the icon shortcuts for the Windows Terminal to update, but that's probably a bug.
Enjoy
If you've got WSLg installed you can even install a GUI application and run it from AL2023. Since it doesn't have many GUI applications, you could install and run one from Flathub:
sudo dnf -y install flatpak
flatpak install -y --user --from https://dl.flathub.org/repo/appstream/org.gnome.TwentyFortyEight.flatpakref
flatpak run --user org.gnome.TwentyFortyEight