Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active December 15, 2024 07:09
Show Gist options
  • Save xbalaji/fb3fdd0a200a71f626eb5644d9e0a52f to your computer and use it in GitHub Desktop.
Save xbalaji/fb3fdd0a200a71f626eb5644d9e0a52f to your computer and use it in GitHub Desktop.
wsl-notes.md
Reference:

Download images

  • open windows powershell in administrative mode
  • check online versions available: wsl -l -o
  • check installed versions: wsl -l -v
  • change directory to E:\BigFiles\Images\wsl-images
  • Remove-Item alias:curl
  • curl -kL -o ubuntu-22-04-wsl-rootfs-tar.gz "https://cloud-images.ubuntu.com/wsl/jammy/current/ubuntu-jammy-wsl-amd64-wsl.rootfs.tar.gz"
  • curl -kL -o ubuntu-22-10-wsl-rootfs-tar.gz "https://cloud-images.ubuntu.com/wsl/kinetic/current/ubuntu-kinetic-wsl-amd64-wsl.rootfs.tar.gz"
  • curl -kL -o ubuntu-23-10-wsl-rootfs-tar.gz "https://cloud-images.ubuntu.com/wsl/mantic/current/ubuntu-mantic-wsl-amd64-wsl.rootfs.tar.gz"
  • curl -kL -o ubuntu-24-04-wsl-rootfs-tar.gz "https://cloud-images.ubuntu.com/wsl/noble/current/ubuntu-noble-wsl-amd64-ubuntu24.04lts.rootfs.tar.gz"
  • wsl is installed at: %LOCALAPPDATA%\Packages${Org}-${OS}-${Random} in our case it is
    • mkdir "C:\Users\xbalaji\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.10_01"
    • mkdir "C:\Users\xbalaji\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu24.04"

Importing images

  • wsl --import ubuntu-kinetic-1 "C:\Users\xbalaji\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.10_01" .\ubuntu-22-10-wsl-rootfs-tar.gz
  • wsl --import ubuntu-noble-1 "C:\Users\xbalaji\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu24.04" .\ubuntu-24-04-wsl-rootfs-tar.gz

set the default image

  • wslconfig /l - list all the images installed in the system
  • wslconfig /s ubuntu-noble-1 - make the recently installed distribution as default

Terminate and Remove the existing image

  • wsl -l -v
  • wsl --terminate "Ubuntu-22.04"
  • wslconfig /u Ubuntu-22.04

Commands to mount remote machine directories in wsl

  • sudo mkdir -p /mnt/r /mnt/q
  • sudo apt -y install cifs-utils
  • sudo mount -t cifs -o user=$REMOTEUSER,pass=$REMOTEPASS //192.168.1.4/xbalaji /mnt/r
  • sudo mount -t cifs -o user=$REMOTEUSER,pass=$REMOTEPASS //192.168.1.20/xbalaji-home /mnt/q

Commands to mount mac machine directories in wsl, important to give read write permission for the user

  • In the MAC
    • login to the mac, open finder, set the folder to share or do the following in the terminal
    • sudo sharing -a "$HOME/xbalaji-dev" -S xbalaji-dev
    • sudo chmod -R 755 "$HOME/xbalaji-dev"
    • sudo chown -R $USER:staff "$HOME/xbalaji-dev"
    • sudo sharing -r xbalaji-dev <-- to remove the share, use the key from the list command below
    • sudo sharing -l -f json <-- to list the shares
  • In the WSL
    • sudo mkdir -p /mnt/r /mnt/q
    • sudo apt -y install cifs-utils
    • sudo chown xbalaji:xbalaji /mnt/r
    • sudo mount -t cifs --verbose -o uid=$(id -u),gid=$(id -g),rw,user=$REMOTEUSER,pass=$REMOTEPASS //192.168.1.3/xbalaji-dev /mnt/r

setup new wsl

  • useradd -m -s /bin/bash -G sudo xbalaji
  • echo "xbalaji:balajiv" | sudo chpasswd
  • grep sudo /etc/group
  • useradd -m -s /bin/bash -G sudo xbalajie
  • echo "xbalajie:balajiv" | sudo chpasswd
  • grep sudo /etc/group
  • usermod -d /mnt/e/Balaji/home/ xbalaji
  • grep xbal /etc/passwd
  • chown -R xbalaji:xbalaji /mnt/e/Balaji/home

update the default user

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