I've installed wsl2 on my windows machine and I was not able to figure out where the files are actually stored.
Note, that I don't mean that I wanna browse them inside the file explorer - I know it can be done by typing in the explorer \\wsl$\
.
If I would have to guess I would say the files are stored in the same hard-drive that the os is stored.
So actually I have two related questions.
EDIT:
I was able to locate the installation path, in my machine the path is:C:\Users\Eliran\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState
Is there a way to mount this to another location?
You can access WSL2 Linux files from the network path \\wsl$\ . Enter it in the File Explorer address bar or any file open dialog.
File storage and performance across file systems For example, when storing your WSL project files: Use the Linux file system root directory: \\wsl$\Ubuntu\home\<user name>\Project. Not the Windows file system root directory: /mnt/c/Users/<user name>/Project$ or C:\Users\<user name>\Project.
All the files are stored in a ext4.vhd
files in the installation directory, which you can't mount directly onto windows as it is in ext4 (obv)
There's two ways to change the location of the above mentioned vhd file the official, tedious way and an unofficial quick and dirty way
The official tedious way
wsl.exe --export <Distro> <FileName>
from CMD/PowerShellwsl.exe --import <Distro> <InstallLocation> <FileName> [Options]
The problems with this is it's quite time consuming and after you do this, pray that it exported and imported several gigabytes worth of thousands of files without any problems
The quick and dirty way
This involes an unofficial opensource WSL manager called lxrunoffline
To install it (takes like a min at max) read through the instructions by the dev here
If you installed it by manually downloading the binaries from the release page, make sure to install it to a directory in PATH, like C:\Windows
Now the process is simple as lxrunoffline move -n <distroname> -d <destination-folder>
For example lxrunoffline move -n Ubuntu-20.04 -d G:\wsl\
Hope I helped
Edit: typo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With