Skip to content

Instantly share code, notes, and snippets.

@artman41
Last active August 31, 2024 01:11
Show Gist options
  • Save artman41/858450e2c29b239d8692213b684ada25 to your computer and use it in GitHub Desktop.
Save artman41/858450e2c29b239d8692213b684ada25 to your computer and use it in GitHub Desktop.
Instructions on how to install a custom distro in WSL2 (Windows SubSystem for Linux 2)

WSL install another distro

  1. Here are some default vars for the process
ISO_DIR=~/fedora;
ROOTFS_MOUNT_DIR=/mnt/contents

DISTRO_LOCATION=
  1. Install Ubuntu Bash

  2. Install 7zip in ubuntu

sudo apt-get install p7zip 
  1. Download the distro of your choice (i.e Fedora)

  2. Move the ISO to its own folder, i.e ~/fedora

  3. Navigate to the directory and Extract using 7Zip

mkdir $ISO_DIR; cd $ISO_DIR;
7z x Fedora-Cinnamon-Live-x86_64-31-1.9.iso

You should see the following files or similar

artman41@DESKTOP-TQGCI07:~/fedora$ ll | less
total 2139660
drwxr-xr-x  7 artman41 artman41       4096 Mar 31 16:04 ./
drwxr-xr-x 10 artman41 artman41       4096 Mar 31 16:03 ../
drwx------  3 artman41 artman41       4096 Oct 24 00:15 EFI/
-rwxr-xr-x  1 artman41 artman41 2203779072 Mar 31 16:03 Fedora-Cinnamon-Live-x86_64-31-1.9.iso*
drwx------  2 artman41 artman41       4096 Oct 24 00:15 LiveOS/
drwx------  2 artman41 artman41       4096 Mar 31 16:04 [BOOT]/
drwx------  3 artman41 artman41       4096 Oct 24 00:15 images/
drwx------  2 artman41 artman41       4096 Oct 24 00:15 isolinux/
  1. Navigate to LiveOS (or where the squashfs is) and 'unsquash' the squash.img:
cd LiveOS;
sudo unsquashfs -d squashfs squashfs.img
  1. Navigate to squashfs/LiveOS and mount the rootfs.img:
sudo mkdir $ROOTFS_MOUNT_DIR;
sudo mount -o loop squashfs/LiveOS/rootfs.img ROOTFS_MOUNT_DIR;
  1. Navigate to $ROOTFS_MOUNT_DIR and tar.gz the files:
cd $ROOTFS_MOUNT_DIR;
sudo tar -zcvf $ISO_DIR/distro.tar.gz .
  1. Navigate to $ISO_DIR and import the .tar.gz using wsl
cd $ISO_DIR
wsl.exe --import $DISTRO_NAME $DISTRO_LOCATION distro.tar.gz
  1. Open your distro and create a user
wsl.exe -d $DISTRO_NAME
useradd -m $USER

Logging in to your account by default

Note: Don't forget to add yourself to visudo or you'll be unable to perform super-user actions until you set the DefaultUser field in regedit to 0

  1. Get your uid
grep $USER /etc/passwd
# The return will be something like artman41:x:1000:1000:root:/root:/bin/bash
#  where the format is $USER:x:$USER_ID:$GROUP_ID:$GROUP:$HOME:$SHELL
  1. Install Windows Terminal and Open the JSON Settings
#in powershell
notepad.exe $env:LocalAppData\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\profiles.json
  1. Look for the profile with $DISTRO_NAME and note the GUID (referred to as $DISTRO_GUID in the guide)
  • copying the GUID to defaultProfile will make you load in to your custom distro by default using the windows terminal
  1. Open regedit and navigate to Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\$DISTRO_GUID

  2. Ensure the following values are set

Name Type Data
DefaultEnvironment REG_MULTI_SZ HOSTTYPE=x86_64
LANG=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
TERM=xterm-256color
DefaultUid REG_DWORD $USER_ID
  1. Restart your custom distro shell
@Gspxz
Copy link

Gspxz commented Mar 30, 2021

failed to setup loop device for squashfs/LiveOS/rootfs.img

@Gspxz
Copy link

Gspxz commented Apr 4, 2021

failed to setup loop device for squashfs/LiveOS/rootfs.img

It worked this time. I used sudo mount -o loop rootfs.img ROOTFS_MOUNT_DIR; instead of sudo mount -o loop squashfs/LiveOS/rootfs.img $ROOTFS_MOUNT_DIR;.

@ncjimene
Copy link

Any example on what sort of files does the tar finally have? or the rootfs.img? I want to confirm if my custom ISO has these files renamed or just don't exist

@JohannesM
Copy link

7z x squashfs.img
added since 9.18

@analysisgxh
Copy link

hi. I make my ISO from specific Ubuntu.Now I want to use it through WSL2.I follow your instruction ,but in 6 step,There no liveos and squashfs squashfs.img,Could you help me?

@analysisgxh
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment