I have a dual hard-drive laptop with the primary being an SSD for quick-boot and the secondary being an HDD. The primary one, unfortunate for today's demand is a little too less in space of just 250 GB but the secondary one is good with 1 TB in space.
As a discipline, as much as possible I host most of my files and software installations in my largish secondary drive. As with WSL, when you install it from Microsoft Store (earlier known as Windows Store), it defaults to windows operating system location, which becomes my space constrained primary drive.
To preserve the space in my primary drive, I wanted to change the storage location of my WSL distro to my secondary drive. This is possible with WSL import/export commands. See WSL Cheatsheet for reference.
After you import a WSL distribution, you may need to tell WSL 2 to start the distribution using the Linux user account you created when you first created the distribution. Unfortunately, this is not taken care of by default from the export/import procedure; see WSL/Issue in Github, if you are curious.
The Microsoft Docs however proposes a way to change the default user for a distro, which didn't work for me for some reason. This is what you should try first, which is about executing something like `ubuntu config --default-user my_default_username` depending upon the name of your distro executable.
Microsoft Docs also proposes a distro specific configuration that you can make with `wsl.conf`. This is a per distro launch configuration setting. Using this you can automatically configure certain functionality in WSL that will be applied every time you launch the subsystem using `wsl.conf`. This file is located in `/etc/wsl.conf` of your target distro, where the contents looks like below:
Now if even this fails, know the DefaultUid of this user who you wanted to make a default one and use that in setting it up manually in the windows registry like below screenshot:
In the screen-shot above, I had exported my Ubuntu-20.04 distro where I had created a default username kartz at the time of its installation from Microsoft Store. Ubuntu-20 is the new distro that was created by importing from the exported image tar file and I wanted to have kartz as the default username in this distro, because I have my working environment all set to this user in this distro created from imported image. Apparently in my case the value turned out to be 1000.
For easy copy-edit-pasting, I share the snippet below as gist:
Hope that get you going easy with WSL 2!!..