Skip to content

system

Change user directory

Use sudo and at to schedule the usermod command, which changes the user's home dir.

sudo at "now +5 minutes"  # Run the following commands in 5 minutes

In the at interface

usermod -m -d /new/home/path # Change user home dir (-d) and move (-m) the content into the new folder

Ctrl+D to exit the at interface. Logout, wait 10 minutes, and login.

See

Install AMD chipset driver Windows 11 24H2

How to solve the "AMD system not detected" error when installing AMD chipset driver in Windows 11 24H2.

Install VBS support: Settings > System > Optional features > Add "VBSCRIPT". You should be able to install the driver afterward.

heredoc: Passing multiple lines of string

Use heredoc to pass the string as-is between two delimiters (e.g. EOF)

cat << "EOF" >> ~/.xprofile
# ~/.xprofile
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
ibus-daemon -drx
EOF

Will append the following lines in ~/.xprofile:

.xprofile
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
ibus-daemon -drx

Ubuntu 24.04 NTFS mount error

Ubuntu 24.04 (with kernel 6.8) may give an error while mounting NTFS partitions.

Solution: disable the open source ntfs3 driver and force Ubuntu to use the old ntfs-3g driver. Reboot to apply.

echo 'blacklist ntfs3' | sudo tee /etc/modprobe.d/disable-ntfs3.conf

Kill zombie processes

Find and kill zombie process(es). Source

ps axo stat,ppid,pid,comm | grep -w defunct

Kill parent process(es)

sudo kill -9 <ppid>

Windows subsystem for Linux 2 (WSL2)

Set up Windows subsystem for Linux 2 (WSL2) for Linux development experience in Windows 10 and 11.

Instal WSL2

Open powershell with administrator privilege, run the following command in the host.

wsl --install --no-distribution

or install the components manually

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

After reboot, install the Linux distribution

wsl --update
wsl --set-default-version 2
wsl --install -d Ubuntu  # Or another Linux distribution

WSL2 post-install (optional) setup

Backup/move the virtual disk

If you want to move the WSL virtual disk file to another disk (in this example, D:\), run the following commands in Windows12:

wsl --export Ubuntu .\Ubuntu\ext4.tar
wsl --unregister Ubuntu
wsl --import Ubuntu D:\Ubuntu\ .\Ubuntu\ext4.tar

Default login user

Edit /etc/wsl.conf in the WSL. You may need to set the default user if you have moved the virtual disk file of the WSL distribution.

/etc/wsl.conf
[user]
default=username

Host settings

Edit .wslconfig 3 in your Windows home directory (%USERPROFILE%).

For example,

.wslconfig
[wsl2]
memory=20GB              # How much memory to assign to the WSL2 VM.
swap=8GB                 # How much swap space to add to the WSL2 VM. 0 for no swap file.
swapfile=C:\\temp\\wsl-swap.vhdx # Sets swap file path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx. Useful if your C drive has limited disk space.

Auto reclaim RAM and disk space

Edit .wslconfig 3 in your Windows home directory (%USERPROFILE%). 4

.wslconfig
[experimental]
autoMemoryReclaim=gradual    # Reclaim RAM usage
sparseVhd=true               # Reclaim virtual disk (vhd) usage

Maintenance

Update kernel

To (manually) update the WSL kernel, run the following commands with administrator privileges:

wsl --shutdown
wsl --update

Reclaim virtual disk space

Optimize-VHD

Note

Optimize-VHD is not available in Windows Home edition.

To reclaim disk space from virtual hard disks (VHDs), run the following commands with administrator privileges 5:

wsl --shutdown
Optimize-VHD -Path %path-to.vhdx% -Mode Full
Export and re-import

Alternatively, export the VHD as a tar file and reimport it again.

Caveats about WSL2

Poor filesystem performance across OSes

Cross-OS file access (e.g., accessing /mnt/c in WSL) is at least one order of magnitude (10x) slower than accessing natively (/home/user/).7