Useful instructions for WSL/WSL2.

Installing, maintaining, and moving. Many links go to russian-language pages:

WSL в Windows: How to move to another disk/computer.


A chain of important commands:

wsl –shutdown
mkdir e:\backup
wsl –export Ubuntu-20.04 e:\backup\ubuntu.tar
wsl –unregister Ubuntu-20.04
mkdir E:\WSL
wsl –import Ubuntu-20.04 E:\WSL\ E:\backup\ubuntu.tar

By default, the root account is used in WSL Ubuntu. To change the user, for example sysops:

cd $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps
.\ubuntu2004.exe config –default-user sysops

And then

wsl -s Ubuntu-20.04

The error message “Unable to set up transient service directory: XDG_RUNTIME_DIR “/mnt/wslg/runtime-dir” can be written by others (mode 040777)” can be fixed by the command:

chmod 0700 /mnt/wslg/runtime-dir

Manual install of WSL

How to install Linux WSL2 on Windows 10/11

Terminator

To rename a user in WSL, first change the default user to root using the command line, then terminate the distro. Log back in as root and use usermod -l newusername -d /home/newusername -m oldusername to rename the user, move their home directory, and change the login name. Finally, configure the distro to set the new username as the default.
Detailed steps to rename a WSL user
Open PowerShell or Command Prompt and terminate the current WSL session to ensure the user is not running processes.
wsl –terminate (Replace with your distribution, e.g., wsl –terminate Ubuntu)
Temporarily switch the default user to root for the distribution.
wsl –default-user root
Start a shell as root to perform the rename.
wsl -u root or just wsl (if you just set it to root)
Rename the user and update the home directory.
Run the usermod command, replacing oldusername, newusername, and /home/newusername with the correct names:
usermod -l newusername -d /home/newusername -m oldusername
The -l flag changes the login name, the -d flag sets the new home directory, and the -m flag moves the contents of the old home directory to the new one.
Set the new username as the default user.
In the same root shell, run: config –default-user newusername
Terminate and restart the WSL distribution to apply the changes.
wsl –terminate
wsl -d or open your distro from the start menu
You should now log in with the new username automatically.