Create Your Custom WSL from Any Linux Distribution (Part - 2)

The Complete Tutorial to Install and Setup any Linux Distribution in WSL

Create Your Custom WSL from Any Linux Distribution (Part - 2)

In the previous part of this two part blog series, we discussed how to install and set up void linux in WSL. In this article we'll cover how to do the same for Arch Linux! Hell Yeah!!

In the former blog, we went through how to obtain the tar of the desired Distro using a docker container. Here we will see how to obtain the tar if we don't have access to a working docker container.

Summary of the Content Prior to Reading the Article

In this article, I'll guide you through installing Arch Linux on WSL without using Docker, instead opting for a VirtualBox VM to create the necessary tar file. We'll cover generating the tar archive, transferring it to your host machine, and importing it into WSL. Additionally, we'll discuss fixing the common automounting error post-installation. This method ensures you can enjoy Arch Linux on WSL, leveraging the flexibility of VM-based installation.


Installing Arch Linux in WSL

Unfortunately, the official docker image of archlinux is not usable now(I think so). Because I faced a lot of issues when inside the container running. The commands didn't ever execute and always getting a newline whenever pressed enter. Very weird. Whatever...

So docker is NOT going to get our job done. Instead we can use virtualbox to create a VM instance of Arch Linux. I am not going to give a complete archlinux installation tutorial here. That will be too much for this article. There are plenty of tutorials available in YouTube of archlinux installation on virtualbox. And if you are a REAL NERD Linux fanboy (like me!!!) you may want to install Arch "The Arch Way" (without archinstall script!).

Assuming You Have Already Done A Base Installation inside VBox

Getting the Tar File

Run this command(assuming you are the root user and currently in the /root directory), inside the virtual machine to generate the needed whole system archive -

tar -cpvzf archlinux.tar.gz --exclude=/proc --exclude=/sys --exclude=/root/archlinux.tar.gz --one-file-system /

Let me break down the command into understandable parts.

here the --one-file-system flag means -

meaning of the --one-file-system flag

We have excluded the /proc and /sys directories to make the tar file comparatively less bulky in size. It is safe because, they will be generated anyway while importing in WSL.

And finally you may already understand why we excluded the tar file itself.
Because if we did include the tar, there's a 99% probability that, 2 TERRIFYING things could happen!

  1. Self-Referencing File: The tar command would attempt to include the archlinux.tar.gz file in the archive. This can lead to recursive inclusion, where the tar process continually adds the same file over and over, causing an infinite loop of inclusion until disk space runs out or the process is forcibly terminated.

  2. Import Issues: Even If the tar command does manage to execute without crashing, when you attempt to import this archive on WSL, including the archlinux.tar.gz file can cause confusion. The import process (which involves extraction) might attempt to re-extract the tar file recursively, complicating the extraction process and potentially leading to errors like system overload or any kind of unexpected results.

It will take a certain amount of time to complete the making of the full system backup.

So now you have the tar file in your current directory. Check that with ls command.

Transferring the tar file

  • In order to get the tar file outside the VM. You have many options. The most preferable one would be to install an advanced DE(Desktop Environment) like, XFCE or GNOME and then install the the virtualbox guest additions.

  • After you have the guest additions installed, shutdown the VM and run it again. When guest additions are installed in the system, we can use the shared folders feature of virtualbox.

    • Quickly setup a shared folder and then transfer the tar into the host machine from the guest through the shared folder.

Hurray! Now you have the tar file in your host machine ready to be imported.

Importing it into WSL

Provide the appropriate directory for where the virtual hard disk image(vhdx) file will be created, in the command below. ( in place of E:\VMs\WSLs\Arch\ )

wsl --import Arch E:\VMs\WSLs\Arch\ .\archlinux.tar.gz

I keep all the custom WSL installations (vhdx files) inside this directory E:\VMs\WSLs\. This is the way I keep them organised.

If You Don't Want to Base Install Arch/Don't Want to Use A VM

So, yes! If this way (using a VM) is not preferable by you, but you still badly want to have Arch inside your WSL, I'm leaving the mega link of my Arch Linux tar file.

Decryption key - rOmmrAv8Hh-6oB5suJvaexkmxdF9-l1FbL0l3Rg9gv8 .

For reference you can also watch this YouTube Tutorial by AgileDevArt -

Post Installation

From the previous part, you already know how to create and set user accounts and passwords in a linux command line. So, no need to fill this section with the same Instructions. Knowledge is easily transferable among similar Operating Systems.

But, still there will be a problem that you will face which must be fixed!

Fixing the Automounting Error

When entering in your archlinux WSL with the command wsl -d Arch after a fresh install, it shall first print 'Processing fstab with mount -a failed.' in the console and then shall enter the bash shell of the arch distribution.

What is fstab?

/etc/fstab is the configuration file which contains the information about all available partitions and indicates how and where they are mounted.

What is the reason behind this problem?

From your base installation method (in the VM of course), you should know that the original base install in VirtualBox had some separate filesystem (partitions). Those partitions doesn't exist in WSL or now has a different filesystem UUID.

What to do now?

Comment out or delete all the uncommented lines in /etc/fstab because their corresponding filesystem partitions no longer exist in WSL.
After a full system reboot ( I mean reboot your windows machine ), the errors should disappear.

Read More at unix.stackexchange.com -


Final Thoughts

So at last you have the complete knowledge.

From now on you can have any linux distro you want inside WSL.

You just basically need a tar, which you can obtain using a container or VM. (depending on the situation)

If you found it useful, please consider to share this article with your other developer friends.

Feel free to connect with me on Twitter, LinkedIn, and GitHub.

Linux users are hackers! Happy Hacking! 🐱‍💻

Did you find this article valuable?

Support Debajyati's Blogs by becoming a sponsor. Any amount is appreciated!