Windows Subsystem for Linux
How to compact an overgrown disk
Overview
Overtime a WSL2 partition may grow and not be reclaimed. The following will fix that.
Process
wsl --list
wsl --terminate Debian
diskpart
select vdisk file="C:\Users\joseph\AppData\Local\Packages\Debian.16571368D6CFF_kd1vv0z0vy70w\LocalState\ext4.vhdx"
compact vdisk
WSL2 and SSH Keys between sessions
The Problem
ssh-agent is a thing we normally take for granted when using SSH on linux. We add the key, then it’s there until we restart.
When switching to WSL2 we quickly find that isn’t the case. We might first try eval $(ssh-agent -s)
but that is lost every time we open a new window or tmux session. Another option is to stop using encrypted SSH keys. For those of us who prefer to keep our keys encrypted, there is a better way. We can use the keychain package to persist our SSH keys between windows and sessions.
The keychain package
Install keychain
sudo apt-get install keychain
Edit your ~/.bashrc
, ~/.zshrc
or your choice of shell, and add the following to the bottom of your file.
# Store SSH key between sessions
/usr/bin/keychain -q --nogui $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOST-sh
This will prompt you for the key on startup if it doesn’t already exist. Adjust to suit your keys.