Run Custom Linux Distro on WSL e.g arch Linux - CLI though


jimbo45

Well-known member
Pro User
VIP
Local time
10:40 PM
Posts
4,568
Location
Hafnarfjörður IS
OS
Windows XP,7,10,11 Linux Arch Linux
Hi folks
this is now easily do-able but you need a Linux VM / Host system to initiate the process.
What you basically have to do is to create a .TAR image of the distro you want and then import it into the wsl.

so

1) on Linux VM / Host install docker -- e.g sudo pacman -S docker
2) get the distro docker image e.g for archLinux : docker pull archlinux
3) start a container - this will be the base volume for the WSL2 system : docker run -it --name archlinux-wsl archlinux
4) from the running container set up base user stuff you want e.g in the case of arch Linux get docker image up to date
pacman -Syu
and add user on the docker image to the sudoers group.
pacman -Sy sudo vi
export EDITOR=/usr/bin/vi
visudo
# in the editor, uncomment the line "%wheel ALL=(ALL) NOPASSWD: ALL"
useradd -G wheel,users -m username (User needs to be in the sudoers group if you don't want to run as root)
passwd 123456789f
# enter the password for the container user
pwconv
chmod 0744 /etc/shadow /etc/gshadow (optional only do it if you get "access denied")
exit

now we make the tar file :
5) docker export --output archlinux-image-files.tar archlinux-wsl
6) on the WINDOWS host run :wsl --import archlinux (a directory on your computer that will store the distribution files) .\archlinux-image-files.tar
7) wsl -d archlinux to start archlinux in wsl

and have fun -- note this is only the CLI version -- might be possible to install GNOME,MATE,KDE or whatever - will try that later.

Cheers
jimbo
 

My Computer

System One

  • OS
    Windows XP,7,10,11 Linux Arch Linux
    Computer type
    PC/Desktop
    CPU
    2 X Intel i7
Funny you brought this up, I did the same thing today, but used CentOS instead as my distro of choice. I love WSL2, but I'm not a huge fan of Ubuntu. As a long term RedHat engineer, I prefer RHEL or CentOS as my distribution of choice.

Here is how i accomplished it. In my case, I have Windows 10 on my machine, and I have WSL2 enabled and I have docker desktop installed. These are tools that I use all of the time. I went to docker desktop, checked settings and enabled integration with WSL2, and made sure that my default Ubuntu could use that integration.

Great, so now I can launch my WSL2 based Ubuntu, and I can run docker commands within that Ubuntu instance (without having to actually install docker within that Linux VM...pretty cool, eh?)

Steps: (from within your WSL2 Ubuntu)
docker run -t centos bash ls / (this pulls down CentOS 8 from CentOS and leaves me with a previously running container)

docker ps -a (grab the container ID of the centOS image from the output

docker export containerID# >/mnt/c/temp/centos.tar (put in your containerID# from previous step, this will export CentOS to a .tar file

mkdir C:\wslstore (just creating a place on my C drive to store my WSL image...you can name this whatever you like)

mkdir C:\wslstore\CentOS (just creating a place in C:\wslstore to keep my CentOS image...you can name this whatever you like)

Now, from windows terminal on windows

wsl --import CentOS C:\wslstore\CentOS C:\temp\centos.tar (this will unpack the tar file and place it in C:\wslstore\CentOS and will create a WSL2 image named CentOS)

wsl -d CentOS (this will start up your CentOS WSL image........Enjoy)
 

My Computers

System One System Two

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Beelink SEI8
    CPU
    Intel Core i5-8279u
    Motherboard
    AZW SEI
    Memory
    32GB DDR4 2666Mhz
    Graphics Card(s)
    Intel Iris Plus 655
    Sound Card
    Intel SST
    Monitor(s) Displays
    Asus ProArt PA278QV
    Screen Resolution
    2560x1440
    Hard Drives
    512GB NVMe
    PSU
    NA
    Case
    NA
    Cooling
    NA
    Keyboard
    NA
    Mouse
    NA
    Internet Speed
    500/50
    Browser
    Edge
    Antivirus
    Defender
    Other Info
    Mini PC used for testing Windows 11.
  • Operating System
    Windows 10 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom
    CPU
    Ryzen 9 5900x
    Motherboard
    Asus Rog Strix X570-E Gaming
    Memory
    64GB DDR4-3600
    Graphics card(s)
    EVGA GeForce 3080 FT3 Ultra
    Sound Card
    Onboard
    Monitor(s) Displays
    ASUS TUF Gaming VG27AQ. ASUS ProArt Display PA278QV 27” WQHD
    Screen Resolution
    2560x1440
    Hard Drives
    2TB WD SN850 PCI-E Gen 4 NVMe
    2TB Sandisk Ultra 2.5" SATA SSD
    PSU
    Seasonic Focus 850
    Case
    Fractal Meshify S2 in White
    Cooling
    Dark Rock Pro CPU cooler, 3 x 140mm case fans
    Mouse
    Logitech G9 Laser Mouse
    Keyboard
    Corsiar K65 RGB Lux
    Internet Speed
    500/50
    Browser
    Chrome
    Antivirus
    Defender.
Funny you brought this up, I did the same thing today, but used CentOS instead as my distro of choice. I love WSL2, but I'm not a huge fan of Ubuntu. As a long term RedHat engineer, I prefer RHEL or CentOS as my distribution of choice.

Here is how i accomplished it. In my case, I have Windows 10 on my machine, and I have WSL2 enabled and I have docker desktop installed. These are tools that I use all of the time. I went to docker desktop, checked settings and enabled integration with WSL2, and made sure that my default Ubuntu could use that integration.

Great, so now I can launch my WSL2 based Ubuntu, and I can run docker commands within that Ubuntu instance (without having to actually install docker within that Linux VM...pretty cool, eh?)

Steps: (from within your WSL2 Ubuntu)
docker run -t centos bash ls / (this pulls down CentOS 8 from CentOS and leaves me with a previously running container)

docker ps -a (grab the container ID of the centOS image from the output

docker export containerID# >/mnt/c/temp/centos.tar (put in your containerID# from previous step, this will export CentOS to a .tar file

mkdir C:\wslstore (just creating a place on my C drive to store my WSL image...you can name this whatever you like)

mkdir C:\wslstore\CentOS (just creating a place in C:\wslstore to keep my CentOS image...you can name this whatever you like)

Now, from windows terminal on windows

wsl --import CentOS C:\wslstore\CentOS C:\temp\centos.tar (this will unpack the tar file and place it in C:\wslstore\CentOS and will create a WSL2 image named CentOS)

wsl -d CentOS (this will start up your CentOS WSL image........Enjoy)
Hi there
@pparks1

great stuff as well !!

I used to like CENTOS as a lean and mean reliable server -- my issue with CENTOS was that the kernel was always a bit behind and I've really enjoyed fiddling around with Arch Linux as it seems a decent reliable rolling release --haven't had any problems with it so far with updates etc etc.

Now "for the next trick" is to see if one can get some sort of "Workstation GUI" to run on the chosen distro. I can get some programs working but a full desktop would be interesting. I've plenty of RAM an the host machine , 2 ports for video out and some decent fast SSD's so not lacking resources.

I'm quite happy using the CLI -- my NAS servers all run in CLI mode, headless -- but this is a challenge.

Docker is great - thanks for leading me in that direction some time ago --ist time I've really got into it.

Cheers
jimbo
 

My Computer

System One

  • OS
    Windows XP,7,10,11 Linux Arch Linux
    Computer type
    PC/Desktop
    CPU
    2 X Intel i7

Latest Support Threads

Back
Top Bottom