Add Manjaro into WSL 2
Tags: wsl, linux, windows
Published: 2024-06-03 14:19:33

---
canonical_url:
---

I like Manjaro Linux. Too bad it is my second system, as I still need Windows software every day, which might or not work on a Linux distribution.

For this I wanted to use it in WSL, and found this nice YouTube video: [Arch Linux on Windows Subsystem for Linux (WSL) - YouTube](https://www.youtube.com/watch?v=h0Wg_aknGdc).

Based on the steps from the video I made my decision to use it as a base. The only preparation for this was to find out which docker image to use. Everything else is the same. I guess other distributions will work similarly if there is a docker image.

## Requirements

- Windows 10/11 with WSL 2 support
- docker cli
  - Docker Desktop or
  - Rancher Desktop with Container Engine: `dockerd (moby)` within the settings
- Windows Terminal
- Windows PowerShell Core (recommended)
- Ubuntu (or any other available distribution from the Windows Store) on WSL installed

## Step by step

This guide will not go much into details, as it should bring you fast to an up and running system.

At the end there will be a condensed version, too. Use it when you understand the topics well.

## Preparations

Make sure about the requirements, and your Linux distribution can run docker within.

## Login into WSL

Open Windows Terminal, go into your WSL distribution and run following steps:

- Pull image from docker hub: `docker pull manjarolinux/base`
- Create a Manjaro Linux container: `docker create -i manjarolinux/base bash`
- Copy the first eight or ten characters from the output. Example: `83398c22...`
- Run the container: `docker container start 83398c22`
- Run interactive shell with it: `docker exec -it 83398c22 /bin/bash`

## Within the Linux distribution

You have run the bash shell and it should now show information by running: `whoami`. It will show your logged in user is `root`.

### Initialize `pacman` keys

There might be an optional step, but I recommend it for Arch Linux distributions. This one is for Manjaro:

```shell
pacman-key --refresh-keys
pacman-key --populate archlinux manjaro
```

This can take time.

For more information see:

- [[HowTo] Solve Keyring Related Issues in Manjaro - Contributions / Tutorials - Manjaro Linux Forum](https://forum.manjaro.org/t/howto-solve-keyring-related-issues-in-manjaro/96949)
- [Pacman troubleshooting - Manjaro#Errors_about_Keys](https://wiki.manjaro.org/index.php/Pacman_troubleshooting#Errors_about_Keys)

## Add user and admin rights

Add a user within the `wheel` group and change its password:

```shell
useradd -m -G wheel cyrdam
passwd crydam
```

Why `wheel` group? The wheel group will get `sudo` privileges in the next steps.

Next, the packages need to be up to date, and applications installed for user accounts:

```shell
pacman -Syu
pacman -Syu sudo vim
```

This will install `sudo` and `vim`. You can choose any other shell editor if you like, this will go with the following.

Now we can add `sudo` privileges to the `wheel` group by running:

```shell
EDITOR=vim visudo
```

And remove the hash character on the following line:

`# %wheel ALL=(ALL) ALL`

should look like

`%wheel ALL=(ALL) ALL`

Save and close `vim` by typing: `:wq`

Exit the docker container with the command:

```shell
exit
```

## Export the docker image

Create a directory on your hard drive from within the Linux distribution and go there. Then create a sub-folder for the `.vhdx` image file. You can choose whatever folder you like, but I recommend not to use a directory within the user directory.

Example:

```shell
cd /mnt/c/dev/wsl/
mkdir manjarolinux
```

The directory `manjarolinux` is there to store the `.vhdx` file and will be empty at this moment. Stay in the current folder and run this docker command:

```shell
docker export 83398c22 > /mnt/c/dev/wsl/manjarolinux.tar
```

It will take seconds to write the container into the file given by the path.

The container ID needs to be the same as at the beginning. You can get it by looking into the container list with: `docker container ls`.

Now exit your Linux distribution:

```shell
exit
```

## Import the image into WSL

From the Windows Terminal you go to the created directory and check if everything looks fine:

```shell
cd C:\dev\wsl\
ls
```

There you see the `.tar` file and the empty directory `manjarolinux`.

It is time to import the image into WSL:

```shell
wsl --import Manjaro ./manjarolinux manjarolinux.tar
```

Explanation of the parts:

- `wsl --import`: command to import a distribution
- `Manjaro`: Name of the distribution in WSL (and Windows Terminal drop-down menu)
- `./manjarolinux`: where to store the `.vhdx` image file
- `manjarolinux.tar`: file to import

Restart Windows Terminal.

## Update Windows Terminal settings

In Windows Terminal open the drop-down menu and run `Manjaro` from there. It will run the user as `root`. Nobody wants that. Add a little start command to change it each time we run the Terminal Window.

Go to the Windows Terminal settings and open the file version of the settings by clicking on the gear icon on the bottom left side of the window. Your editor for the file should open. Search for `Manjaro`. Add `commandline` into the settings:

```json
{
	...
	"name": "Manjaro",
	...
	"commandline": "wsl.exe -u cyrdam -d Manjaro"
}
```

You could also do it over GUI for the `Manjaro` profile.

Close the editor for the file, restart Windows Terminal and open `Manjaro` again. Check the user with `whoami`. It should show you your defined user (in my case cyrdam).

## Optional step (aka signature)

To have a pleasant view and proof of running Manjaro within WLS you can install `archey3` and present the output of your system, showing you also the kernel version from Microsoft. Run following commands:

```shell
sudo pacman -Syu archey3
archey3
```

See running Manjaro Linux in WSL on Windows.

My output:

```
$ archey3

               +                OS: Arch Linux x86_64
               #                Hostname: name of the machine
              ###               Kernel Release: 5.15.79.1-microsoft-standard-WSL2
             #####              Uptime: 1:13
             ######             WM: None
            ; #####;            DE: None
           +##.#####            Packages: 151
          +##########           RAM: 1436 MB / 15856 MB
         #############;         Processor Type: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
        ###############+        $EDITOR: None
       #######   #######        Root: 798M / 1007G (0%) (ext4)
     .######;     ;###;`".
    .#######;     ;#####.
    #########.   .########`
   ######'           '######
  ;####                 ####;
  ##'                     '##
 #'                         `#
```

## Improvement thoughts

To make this less time taking it would be possible to automate this entire process by a script with input capabilities. That means we would also run commands within the terminal and containers directly.

I do not know how this could work, but here is a summary of all steps.

### Within Linux distribution

Run Windows Terminal with your Linux distribution, then start with the commands.

```shell
# Download image and create container
docker pull manjarolinux/base
docker create -i manjarolinux/base bash
# Copy the first eight characters of the output (example: 83398c22)
# Run the container
docker container start 83398c22
# Login into the container with the bash shell
docker exec -it 83398c22 /bin/bash
```

## Within docker container

```shell
# Update pacman keys (can take a while)
pacman-key --refresh-keys
pacman-key --populate archlinux manjaro
# Add user
useradd -m -G wheel cyrdam
passwd crydam
# Update packages, install sudo and editor
pacman -Syu
pacman -Syu sudo vim
# Add user group to sudo user
EDITOR=vim visudo
# Edit the line: '# %wheel ALL=(ALL) ALL' > '%wheel ALL=(ALL) ALL'
# Exit vim
:wq
# Exit docker container
exit
```

### Back in Linux distribution

```shell
# Create the folder first if not available then go to
cd /mnt/c/dev/wsl/
mkdir manjarolinux
# Use the ID from before or search for it with: `docker container ls`
docker export 83398c22 > /mnt/c/dev/wsl/manjarolinux.tar
# Exit the Linux distribution
exit
```

### Within Windows PowerShell

```shell
cd C:\dev\wsl\
# Check directory content for .tar file and empty folder
ls
# Import image
wsl --import Manjaro ./manjarolinux manjarolinux.tar
```

### Within Windows Terminal settings

```shell
# Update settings for 'Manjaro' profile by adding following line
"commandline": "wsl.exe -u cyrdam -d Manjaro"
# Restart terminal
# Open 'Manjaro' and check user is not root
whoami
```

### Within Manjaro

```shell
sudo pacman -Syu archey3
archey3
```

## Summary

If someone knows how to make this automated:

- adding the image name (dynamic)
- adding the distribution name for WSL (dynamic)
- running all commands without issues or destroying anything

then please share your knowledge. Is there a better solution?

Currently, I can export my Manjaro Linux and share it on other machines if necessary:

```shell
wsl --export <distributionsname> <TAR-file>
wsl --import <distributionsname> <directory path to vhdx file> <TAR-file>
```

But be careful: you will also copy every file within the distribution, that also means project files that might not be for sharing because of legal reasons.