WSL feature allows running an actual Linux distribution inside Windows. Ubuntu was the first distro that could be installed this way. Soon, SUSE, Kali Linux and some other Linux distributions joined the WSL bandwagon.
However, Arch Linux is not officially available on WSL, but if you make some efforts, you can use it via WSL.
In this article, I show a method to set up Arch Linux WSL system under WSL 2.
There are some prerequisites.
- A WSL Linux distribution (Ubuntu, recommended) is installed.
- You should be running WSL version 2.
Here, I'll be using the Arch Linux Bootstrap Tar file to set up the WSL system.
Step 1: Setting the Arch Linux Import File
First, head over to the Arch Linux website and go to the download page. From the download page, select an appropriate mirror.
Inside that, you can find several Arch Linux files. Right-click on the x86_64 bootstrap tar file and select copy link.
Now, open an existing WSL distribution (let's say you are running an Ubuntu WSL system) from the start menu or from the terminal:
wsl ~ -d <distribution_name>
Inside the distro, use the wget
command to download the Arch Linux Tar file.
wget <copied link to the tar file>
This will download the tar file to the home directory of the current user. Once download completed, use ls
command to list the contents and get the name of the downloaded file.
ls
Extract the tar file using the tar
command:
sudo tar -zxvf <downloaded file name>
Thereafter, enter into the extracted folder using the cd
command:
cd <name of the extracted folder>
Here, in my case, it is:
cd root.x86_64
Inside the directory, spot the file on etc/pacman.d/mirrorlist
. This file holds the list of mirrors. Initially, all the entries are commented. You need to uncomment some mirrors from the list.
While uncommenting, you can choose those in your country and near your country.
Since you are inside another WSL distro, use nano editor to edit the file.
sudo nano etc/pacman.d/mirrorlist
After uncommenting some mirrors, save the file using CTRL+O and then exit the editor using CTRL+X.
Now, compress the whole root folder back to the tar.gz file. For this, you should be inside the root.x86_64
directory and run the command:
sudo tar -czvf root.tar.gz *
This will create a compressed file containing the contents of the folder, including the changes you have made to the mirrors file. If you list the contents, you can spot the tar file.
What you need to do is, move this file to a location where it is easily accessible via a Windows terminal. For this, you can use the mv
command. On the current folder, that is, where you have created the tar file, run:
sudo mv root.tar.gz <name of the Windows folder>
Windows directories are available inside the WSL distribution, and you can access them from /mnt
. So, for me, I have created a location to save the tar file on my drive, and I will use the command:
sudo mv root.tar.gz /mnt/d/WSL_Exports/
This will save the tar file to a folder called WSL_Exports
on my D: Drive.
You now have the Arch Linux import file.
Step 2: Import Arch Linux
Once you have the tar file ready, you can close the current WSL distribution by running on a Windows terminal.
wsl --terminate <distribution_name>
Now, open a terminal in Windows as administrator.
Run the following command to import the Arch Linux distribution.
wsl --import ArchLinux <Location to where imported> <Location of the tar file>
The installation location can be any convenient place, that you can easily distinguish for later accessibility. So, I may use the command:
wsl --import ArchLinux D:\WSL_Imports\ D:\WSL_Exports\root.tar.gz
This will import the distribution. You may need to wait for some time to finish the importing process.
Step 3: Set up Arch Linux
Once the import is completed, you can list the installed WSL distributions to verify Arch Linux is listed among them.
wsl -l -v
Log in to Arch Linux system using the command:
wsl -d ArchLinux
wsl -l -v
command.Once inside the system, enter the command:
cd
To take you away from the mounted Windows directory. Here, you can see that, you have been logged in as the root user, but nothing is set up, including the root password.
So we will be taking care of those things in the next step.
Initialize keyring and update system
First, initialize the Arch Linux keyring:
pacman-key --init
pacman-key --populate archlinux
pacman-key --refresh-keys
pacman -Sy archlinux-keyring
Thereafter, run a system update using:
pacman -Syu
Now, it's time to install the base and other essential packages. You can use the pacman
command for the purpose.
pacman -Syu base base-devel git nano wget reflector rsync
You can update the mirror list using reflector. For this, first back up the existing mirror list, in case anything goes weird.
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
Now, get the good mirror list with reflector and save it to mirrorlist. Below, I have added two mirror countries, US and Canada, using repeated -c
option.
reflector -c us -c ca -f 12 -l 10 -n 12 --save /etc/pacman.d/mirrorlist
You can change the country from US to your own country. Get a list of reflector countries and codes using the command:
reflector --list-countries
Setting up locale
The language, numbering, date, and currency formats for your system depends on this setting.
The file /etc/locale.gen contains all the local settings and system language in a commented format. Open the file using:
nano /etc/locate.gen
I have used en_US.UTF-8
(English United States). Uncomment that particular line. Now, save the file (CTRL + O) and exit the editor (CTRL + X).
Generate the locale config in the /etc directory file using the below commands one by one:
locale-gen
echo LANG=en_US.UTF-8 > /etc/locale.conf
export LANG=en_US.UTF-8
Root user password and normal user creation
Since you currently haven't a root password set up, do that by using the passwd
command:
passwd
Type and retype the password to make the change effect.
It is not recommended to log in as the root all the time. It can be catastrophic for your system, as there are chances for accidental changes taking effect immediately. So, you need a regular user, who can run administrative commands when needed.
In Arch Linux, you can use the useradd
command, to create a new user. Let's create a new user called βteamβ.
useradd -m team
Here, the -m
option will automatically create a home directory for the user at /home/
.
Set a password for the user βteamβ, using:
passwd team
Type and retype password to confirm the change.
Once the user is created, add that user to the wheel
group so that he can run the sudo
command to access some administrative privileges.
usermod -aG wheel team
But at this point, the wheel group cannot run all the commands. For this, you need to allow the members of the wheel group to run any commands.
We will edit the sudoers
file for this.
EDITOR=nano visudo
The above command will open the visudo in nano editor. Locate the line %wheel ALL=(ALL) ALL
and uncomment it.
Save the document using CTRL + O and exit using CTRL + X.
At this point, you can just terminate the system using the command:
wsl.exe --terminate ArchLinux
And then reopen it from a Windows terminal.
wsl ~ -d ArchLinux -u team
Here, we are directly logging in as the normal user (team), that was created in the previous step. The ~
option will land you straight in the home directory of the user.
Or, you can create a file inside the Arch Linux system by running the following command:
sudo nano /etc/wsl.conf
Inside this file, add the line:
[user]
default = team
This will set the user βteamβ as the default one. You will no longer be logging in as the root.
Now, save the file and exit. Terminate the system using the command:
wsl.exe --terminate ArchLinux
Now, you can restart the system by:
wsl ~ -d ArchLinux
Wrapping Up
As you can see, this is certainly not the easiest way to get on with WSL. Use it only if you really want Arch Linux for some reasons or you want to test your technical capabilities.
By the way, if you are new to WSL, do check out our WSL series.
Enjoy :)