AWS

How to run Amazon Linux 2023 (AL2023) locally on WSL?

· 7 min read
How to run Amazon Linux 2023 (AL2023) locally on WSL?
Amazon Linux 2023 (AL2023) - Linux for Cloud

Amazon Linux 2023 (AL2023) is the next generation of Amazon Linux for developing and running cloud applications in high-performance and security enhanced execution environment. This rpm-based Linux distribution is optimized for Amazon EC2.

Amazon Linux 2023 is not available in the Microsoft Store. Therefore, installation of the AL2023 Linux distro for Windows Subsystem for Linux is not straightforward. In this post, we'll see how to install and run AL2023 on WSL2.

Prerequisite:

  • Windows Subsystem for Linux (WSL2)
  • Docker - either in host machine or guest WSL2 Linux distro.

If WSL is not installed, please refer following article

How to Install Windows Subsystem for Linux (WSL2) on Windows 11?
Steps to install Windows Subsystem for Linux (WSL2) on Windows 10 works for Windows 11 too. But Microsoft made it super simple in Windows 11. Just one command that takes minutes to install a Linux distribution (Ubuntu by default). If you are curious about other 3 different options that I

Also, if you don't have docker installed, please refer the below post for detailed installation steps.

Install Docker Engine and Docker Compose on Windows Subsystem for Linux (WSL 2)
If you already have Docker Desktop installed or want to use docker on both Windows and WSL2, then Docker Desktop is better choice. But I personally prefer to install and run the “most-loved Tool” docker inside Windows Subsystem for Linux (WSL 2). This keeps the development environment isolated and…

Export Amazon Linux 2023 as tar

Start the docker service.

abhijit@AwsJunkie:~$ sudo service docker start
 * Starting Docker: docker                      [ OK ]

Pull the latest (Amazon Linux 2023) container image of Amazon Linux from dockerhub.

abhijit@AwsJunkie:~$ sudo docker pull amazonlinux
Using default tag: latest
latest: Pulling from library/amazonlinux
ee5c3b4d09bc: Pull complete
Digest: sha256:1293fb4fa103ea81a8769d7b0aa000072884b0750c0a28563fd9838fea784245
Status: Downloaded newer image for amazonlinux:latest
docker.io/library/amazonlinux:latest

To verify, run the container locally once.

abhijit@AwsJunkie:~$ sudo docker run -it amazonlinux /bin/bash
bash-5.2# date
Fri Apr 14 22:09:27 UTC 2023

Copy the CONTAINER ID (e.g. 62a6ebe6c039) of the amazonlinux IMAGE.

abhijit@AwsJunkie:~$ sudo docker container ls -a | grep amazonlinux
62a6ebe6c039   amazonlinux   "/bin/bash"   4 minutes ago   Exited (127) 29 seconds ago             adoring_tu

Use the CONTAINER ID to export the amazonlinux container's filesystem as a tar file (e.g. al2023.tar).

abhijit@AwsJunkie:~$ sudo docker export 62a6ebe6c039 > /mnt/c/backup/wsl/al2023.tar
Amazon Linux 2023 tar

Import Amazon Linux 2023 tar as new Distro into WSL

Open Windows Command Prompt. And import the exported tar file (e.g. al2023.tar) as new Linux distribution into WSL using wsl --import <Distro> <InstallLocation> <FileName> [Options]

C:\Users\abhijit>wsl --import AmazonLinux2023 C:\installed\env c:\backup\wsl\al2023.tar
Import Amazon Linux 2023 into WSL2

Refer below article for more details on how to take backup and restore Linux Distro on WSL.

How to Backup and Restore Linux Distro on WSL (Windows Subsystem for Linux)?
Nobody can deny the importance of backup & restore process for any environment. Specially, when multi-steps are involved in setup and configuration and we keep modifying the environment with time. Basically, if anything goes wrong for any reason, we don’t want to end up wasting time by setting up th…

Verify

Run wsl -l -v in Windows Command Prompt to list all the installed WSL Linux distributions. We'll see AmazonLinux2023 as one of the distro.

C:\Users\abhijit>wsl -l -v
  NAME               STATE           VERSION
* Ubuntu-22.04       Running         2
  AmazonLinux2023    Stopped         2

Run  wsl -d AmazonLinux2023 to start Amazon Linux 2023.

C:\Users\abhijit>wsl -d AmazonLinux2023
[root@Laptop abhijit]#

Confirm OS name ( NAME="Amazon Linux"), OS version (VERSION="2023") and System release (system-release-2023.0.20230322-0.amzn2023.noarch).

[root@AwsJunkie abhijit]# 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-01"

[root@AwsJunkie abhijit]# rpm -q system-release
system-release-2023.0.20230322-0.amzn2023.noarch

(Optional) Upgrade, Install AWS Tools & Development Tools:

DNF (Dandified YUM) is the package management tool in Amazon Linux 2023 (AL2023). Usage is similar to the predecessor YUM.

Upgrade tolatest release version.

[root@AwsJunkie abhijit]# dnf upgrade --releasever=latest
Amazon Linux 2023 repository                                                         14 MB/s |  12 MB     00:00
Last metadata expiration check: 0:00:02 ago on Fri Apr 14 19:26:23 2023.
Dependencies resolved.
====================================================================================================================
 Package                         Architecture     Version                               Repository             Size
====================================================================================================================
Upgrading:
 amazon-linux-repo-cdn           noarch           2023.0.20230329-0.amzn2023            amazonlinux            18 k
 system-release                  noarch           2023.0.20230329-0.amzn2023            amazonlinux            29 k

Transaction Summary
====================================================================================================================
Upgrade  2 Packages

Total download size: 46 k
Is this ok [y/N]: Y
Downloading Packages:
(1/2): amazon-linux-repo-cdn-2023.0.20230329-0.amzn2023.noarch.rpm                  113 kB/s |  18 kB     00:00
(2/2): system-release-2023.0.20230329-0.amzn2023.noarch.rpm                         114 kB/s |  29 kB     00:00
--------------------------------------------------------------------------------------------------------------------
Total                                                                                83 kB/s |  46 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1
  Upgrading        : system-release-2023.0.20230329-0.amzn2023.noarch                                           1/4
  Upgrading        : amazon-linux-repo-cdn-2023.0.20230329-0.amzn2023.noarch                                    2/4
  Cleanup          : amazon-linux-repo-cdn-2023.0.20230322-0.amzn2023.noarch                                    3/4
  Cleanup          : system-release-2023.0.20230322-0.amzn2023.noarch                                           4/4
  Running scriptlet: system-release-2023.0.20230322-0.amzn2023.noarch                                           4/4
  Verifying        : amazon-linux-repo-cdn-2023.0.20230329-0.amzn2023.noarch                                    1/4
  Verifying        : amazon-linux-repo-cdn-2023.0.20230322-0.amzn2023.noarch                                    2/4
  Verifying        : system-release-2023.0.20230329-0.amzn2023.noarch                                           3/4
  Verifying        : system-release-2023.0.20230322-0.amzn2023.noarch                                           4/4

Upgraded:
  amazon-linux-repo-cdn-2023.0.20230329-0.amzn2023.noarch      system-release-2023.0.20230329-0.amzn2023.noarch

Complete!

List all package groups.

[root@AwsJunkie abhijit]# dnf group list
Amazon Linux 2023 repository                                                         13 MB/s |  12 MB     00:00
Available Groups:
   AWS Tools
   Development Tools
   buildsys-build

Use dnf group info <group-name> to list all packages belong to a group.

For example,

[root@AwsJunkie abhijit]# dnf group info "Development Tools"
Last metadata expiration check: 0:10:12 ago on Fri Apr 14 19:30:25 2023.
Group: Development Tools
 Description: A basic development environment.
 Mandatory Packages:
   autoconf
   automake
   binutils
   bison
   flex
   gcc
   gcc-c++
   gettext
   libtool
   make
   patch
   pkgconfig
   rpm-build
   rpm-sign
   system-rpm-config
 Default Packages:
   byacc
   cscope
   ctags
   diffstat
   doxygen
   elfutils
   gcc-gfortran
   git
   indent
   intltool
   patchutils
   rcs
   subversion
   swig
   systemtap
 Optional Packages:
   ElectricFence
   ant
   babel
   bzr
   chrpath
   cmake
   cvs
   dejagnu
   expect
   gcc-gnat
   imake
   javapackages-tools
   libstdc++-docs
   mercurial
   mod_dav_svn
   nasm
   perltidy
   python-docs
   python2-rpm
   rpmdevtools
   rpmlint
   systemtap-sdt-devel
   systemtap-server

Use dnf install <package-name> to install a specific package.

[root@AwsJunkie abhijit]# dnf install git
Last metadata expiration check: 0:14:13 ago on Fri Apr 14 19:30:25 2023.
Dependencies resolved.
====================================================================================================================
 Package                        Architecture   Version                                    Repository           Size
====================================================================================================================
Installing:
 git                            x86_64         2.39.2-1.amzn2023.0.1                      amazonlinux          68 k
Installing dependencies:
 cracklib                       x86_64         2.9.6-27.amzn2023.0.2                      amazonlinux          82 k
 git-core                       x86_64         2.39.2-1.amzn2023.0.1                      amazonlinux         4.2 M
:
 perl-NDBM_File                 x86_64         1.15-477.amzn2023.0.3                      amazonlinux          23 k

Transaction Summary
====================================================================================================================
Install  87 Packages

Total download size: 23 M
Installed size: 91 M
Is this ok [y/N]: y
Downloading Packages:
(1/87): perl-Storable-3.21-458.amzn2023.0.2.x86_64.rpm                              647 kB/s |  96 kB     00:00
:
(87/87): perl-Symbol-1.08-477.amzn2023.0.3.noarch.rpm                               364 kB/s |  15 kB     00:00
--------------------------------------------------------------------------------------------------------------------
Total                                                                               9.5 MB/s |  23 MB     00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1
  Installing       : systemd-libs-252.4-1161.amzn2023.0.3.x86_64                                               1/87
:
  Verifying        : perl-constant-1.33-459.amzn2023.0.2.noarch                                               87/87

Installed:
  cracklib-2.9.6-27.amzn2023.0.2.x86_64                   git-2.39.2-1.amzn2023.0.1.x86_64
:
Complete!

You can use dnf group install <group-name> to install all packages belong to that group.

References