Some Bits: Nelson's log

Setting up a second WSL distribution

I want to switch from Ubuntu 20.04 to 22.04 on my WSL system. But I’m cautious, so my plan is to install a second WSL image and move my stuff over. Maybe there’s an easier way, but here’s what I did. Installing a first distribution is easy btw, the trick is getting a second without clobbering the first.

Step 1: install second distribution. I followed the procedure here. It boils down to downloading an Ubuntu cloud tarball and using wsl.exe to install it. WSL’s installer puts distributions in C:\Users\Nelson\AppData\Local\Packages so I put the new one there too.

Step 2: set up a user. The distro from step 1 works fine but you’re root. I followed the procedure here. It boils down to using adduser to create the user, then editing /etc/wsl.conf to make that user the default. Note that WSL configuration changes apparently take 8 seconds to apply.

Step 3: copy over your home directory files. There’s no easy and efficient way to access files from one WSL distro in another. So I went way old school and used tar over netcat for /home/nelson. Sometimes the old ways are the best ways.

Step 4: change default distribution. wsl.exe --default sets this for WSL as a whole; I also had to configure which distribution to launch in Windows Terminal.

It’d be nice if my home directory were a separate virtual disk instead of buried inside the WSL image. Some quick Googling suggests it might be possible but it involves an extra mount process and I worry it might not be 100% reliable. There are ways to access other WSL distributions or files from a Windows folder but they seem to involve localhost network mounts (via 9p) or other inefficient things.

Given WSL2 is just a fancy wrapper around virtual machines it seems like this whole process could be a lot simpler and more explicit. But the WSL team came at this from a different direction; “make a Linux program work just like a Windows program on Windows” instead of “manage a library of virtual machines”.