Created on - Aug 3rd 2023.
WSL - Windows Subsystem for Linux
Scenario #1 - After installation of ubuntu on windows and working for few days hapily in ubuntu, I realized that drive C is getting full. Now I wanted to move my ubuntu to some other drive that has enough free space.
Solution - Sources - https://dev.to/equiman/move-wsl-file-system-to-another-drive-2a3d
Steps:
get into exisitng ubuntu terminal and check current user
whoami #In my case it's rohitverma
switch to powershell onwards ; Identify which instance we want to move.
wsl --list --verbose # this should show instances and their state, In my case instance was 'Ubuntu'
wsl --shutdown Ubuntu # Shutdown instance that we want to move.
Create backup of current ubuntu installation.
mkdir D:\wsl_bak #here we would save/backup of our ubuntu instance
wsl --export Ubuntu D:\wsl_bak\Ubuntu_bak.tar #It takes few minutes to complete, depending on files available in ubuntu to backup. Exports instance to single file as backup. Ensure backup file was created after this command completes and before you move to next one.
unregister backed-up ubuntu
wsl --unregister Ubuntu # Removes instance from current/default directory in drive C
import ubuntu instance from backed up file
mkdir D:\WSL # new location for installation
wsl --import Ubuntu D:\WSL D:\wsl_bak\Ubuntu_bak.tar #imports instance in new location
configure default user to some other than root.
cd C:\Users\rohit\AppData\Local\Microsoft\WindowsApps\
ubuntu config --default-user rohitverma # sets default user
wsl --distribution Ubuntu --user rohitverma --cd /home/rohitverma #This will launch ubuntu and switch to current prompt to ubuntu default prompt.