Where does WSL store files?

Andi McClure 1 Reputation point

Context: I have WSL installed, and I installed it such a long time ago that my Distribution/VM was designated as "Legacy" (IE, pre-WSL1). Last night I upgraded it to WSL2 using the instructions from this Github question: use wsl.exe to --export, --unregister, and --import. This unfortunately blasted away my /home directory, but a later comment in the Github explained I could find it in "%LOCALAPPDATA%\Lxss". I used "cp" to copy my old home directory into the new home directory (after first downgrading the distribution to WSL1, because disk access was so slow on my initial attempt under WSL2 I feared it would take all night) and fixed up the permissions by hand. So I now have a working WSL1 distribution.

However I am left with several questions.

  1. Where does WSL store its files? Are they stored in more than once place? Is the /home directory stored in a different place than the basic distribution? Is the file storage location different for WSL2, WSL1, and "Legacy"? Is there a document somewhere explaining all this?
  2. When I ran wsl.exe --export and then --import, the --import required me to give a <InstallLocation>. I had no idea what to put here, so I said "%HOMEPATH%\data-wsl". This feels awkward. What is the "typical" <InstallLocation> for wsl.exe --import?
  3. Now that I have created a "Legacy" distribution, later "--unregister"ed it, then imported a new one, there appear to be leftover files all over my drive. I know of new-distribution files in %HOMEPATH%\data-wsl and "old" home files in "%LOCALAPPDATA%\Lxss". Are there more "abandoned" WSL files, for example the root partition of my now-unregistered "Legacy" Linux install, somewhere on m hard drive? Which of these files can be safely deleted? I don't want a 4GB copy of Linux I am no longer using just taking up space on my drive.
  4. To follow on question 1: It appears(?) that WSL stores the home directories in a different place on the host Windows drive than it does the root fs. This implies some kind of magic occurs when wsl users are created to map the home directory to the correct place. However, in my new copy of WSL1, I created the /home/<myuser> directory "manually" (with cp), which makes me suspect the home directory may not be where WSL expects it but rather directly in the rootfs. If a home directory gets created "manually inside linux using mkdir or cp, how do I perform the "magic" to get WSL to treat it like a home directory and/or store it whereever it likes home directories to live?
  5. Super bonus question I don't really need the answer to: As mentioned when I cp'd the files from the WSL Legacy folder windows drive to create my new home directory in the WSL1 drive, all the permissions got lost and I fixed them up by hand. However the WSL documentation, under "WSL metadata on Windows files", describes four NTFS extended attributes used to store those permissions as well as making reference to a "reparse point" used to describe special files like symlinks, implying I could have somehow read those permissions from the Legacy folder and recreated them precisely in my WSL1 drive. However, the WSL documentation says that it is describing something called "DriveFS". The Github comment above however makes reference to a "LxFs" and a "WslFs", suggesting that "Legacy" may use a different from WSL2 (and possibly that WSL1 may use a third thing). What version(s) of WSL does the learn.microsoft.com "WSL metadata on Windows files" document refer to? If "Legacy" is different, is that documented somewhere?

Finally, as a piece of feedback to the operators of this forum, I think it would be helpful if there were a "tag" for WSL on this forum. There is not currently such a tag, and Microsoft support representatives elsewhere on the Internet point to this forum as the preferred place to ask for WSL support.

Thanks D:

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,144 questions
0 comments No comments
{count} votes