Skip to content

Instantly share code, notes, and snippets.

@tikg
Last active February 16, 2023 03:21
Show Gist options
  • Select an option

  • Save tikg/72d3d64d61710de8b43524646d6509a0 to your computer and use it in GitHub Desktop.

Select an option

Save tikg/72d3d64d61710de8b43524646d6509a0 to your computer and use it in GitHub Desktop.

WSL

Checking WSL distros

PS C:\Users\tik> wsl --list --online
The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.

NAME               FRIENDLY NAME
Ubuntu             Ubuntu
Debian             Debian GNU/Linux
kali-linux         Kali Linux Rolling
SLES-12            SUSE Linux Enterprise Server v12
SLES-15            SUSE Linux Enterprise Server v15
Ubuntu-18.04       Ubuntu 18.04 LTS
Ubuntu-20.04       Ubuntu 20.04 LTS
Ubuntu-22.04       Ubuntu 22.04 LTS
OracleLinux_8_5    Oracle Linux 8.5
OracleLinux_7_9    Oracle Linux 7.9

Import Rocky to WSL

enabling systemd on wsl

set up wsl conf file
on single/specified wsl distro
/etc/wsl.conf
on all distro on wsl (global) C:\Users\username\.wslconfig use ni on powershell

ni .wslconfig  
notepad.exe .wslconfig

.wslconfig and .wslconf format

[boot]
systemd=true

removing docker from wsl

fix for failed to connect by alyleite

sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig  
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target  
#ps auxf | grep systemd # get systemd PID
ps auxf | grep 'systemd/systemd --system' | tail -n1 | awk '{print $2}' > systemd.pid.temp; cat systemd.pid.temp;
TEST_VAR=$(cat systemd.pid.temp); echo $TEST_VAR
touch log.file
### WORK IN PROGRESS - NEED TO FIX ###
#exec sudo nsenter -t $TEST_VAR -a su - log.file
snap version  

Windows packaging manager client

Open powershell or Git bash.
Make directory that is for all your git packages

mkdir my.personal.git  
cd my.personal.git  
git clone https://github.com/microsoft/winget-cli.git

Build it yourself. Or follow this and install from App Installer/Microsoft Store
Also Install Windows Terminal

Ubuntu on Windows

home directory of windows subsystem for linux

opening your folder on windows. easier transferring of files

$ explorer.exe .  

image

logging in as root and changing user pass

In Powershell, voila!

wsl -u root

changing default username login on Ubuntu on Windows

On Powershell check WSL version

wsl -l -v  

On Windows CMD change it to existing user or root

#option1  
ubuntu config --default-user <username>  
#option2  
ubuntu config --default-user root  

Add user and edit /etc/wsl.conf as necessary and terminate distro on powershell

wsl --terminate <distro name>  

If you're using WSL1. Restart LxssManager
If you're using WSL2. No need for Restart

sc stop LxssManager  
sc start LxssManager   

image

@tikg
Copy link
Author

tikg commented Feb 10, 2023

@tikg
Copy link
Author

tikg commented Feb 10, 2023

after adding user internally
useradd tik -u 999999 -m

execute on wsl
ubuntu2204.exe config --default-user tik

@tikg
Copy link
Author

tikg commented Feb 16, 2023

exporting and importing distro for wsl

mkdir D:\WSL\images # For example
mkdir D:\WSL\instances\<newDistroName>
cd D:\WSL

wsl -l -v # Verify distro name to export
wsl --export <distroname> .\images\<distroname>.tar
wsl --import <newDistroName> .\instances\<newDistroName> .\images\<distroname>.tar
wsl --set-default <newDistroName>

@tikg
Copy link
Author

tikg commented Feb 16, 2023

installing ubuntu

wsl --install -d ubuntu

setup user and passwd user
setup passwd of root

exporting

wsl --export ubuntu ubuntu-default.tar

deleting

wsl --unregister ubuntu 

importing ubuntu1

wsl --import ubuntu1 ubuntu1dir ubuntu-default.tar

importing ubuntu2

wsl --import ubuntu2 ubuntu2dir ubuntu-default.tar

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