40

I am new to Windows and have installed WSL2 based on the instructions provided here.

It works fine, but I cannot locate where it has been installed on my computer. The output for pwd is home/nkp68.

How do I access files in my Windows machine from WSL2?

5
  • 2
    Look under /mnt/c/Users/ Commented Dec 11, 2021 at 1:01
  • 1
    Does this answer your question? Where is the Ubuntu file system root directory in Windows Subsystem for Linux and vice versa?
    – muru
    Commented Dec 11, 2021 at 6:04
  • The answers posted in the question you posted @muru are very helpful but the answer given by NotTheDr01ds was not present there. I think this answer is extremely good and may help other people so keeping this post active would be best.
    – Krutik
    Commented Dec 14, 2021 at 11:10
  • 1
    If anything, this post should be merged with that one, since the question(s) are pretty much the same.
    – muru
    Commented Dec 14, 2021 at 12:15
  • I think that is reasonable. I am not sure how to do this though. - Should I comment in the other post adding a link to this post?
    – Krutik
    Commented Dec 14, 2021 at 13:44

1 Answer 1

88

If I read your post literally, there may be a few different questions there:

  • Where is your WSL Ubuntu instance installed on your machine?
  • (Presumably based on the first question) How do I access files in WSL2 from Windows?
  • "How do I access files in my Windows machine from WSL2?" (sort of the opposite question of the first two)

Where is your WSL Ubuntu instance?

Short answer: In your case, given the basic installation, the actual files are in a virtual disk named ext4.vhdx. You really don't need to worry about the "where" at this point (since it's a virtual drive), but you'll typically find it under %userprofile%\AppData\Local\Packages\Canonical...\LocalState\ext4.vhdx. Your %userprofile% is typically something like C:\Users\<username>.

More Detail:

That's for a default installation. You can have multiple distributions installed, and even multiple instances of the same distribution. One of the great things about WSL is the ability to quickly copy a distribution, test something out, and throw away the test. This keeps you from polluting your "good", daily distribution with packages, tests, or other things that may create "cruft" over the long-term.

To see all the distributions you have installed, go to PowerShell and run:

Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse

In your case, you'll probably see something like:

{cff9bfd6-39db-42af-a85b-d6fca State              : 1
94beff8}                       DistributionName   : Ubuntu
                               Version            : 2
                               BasePath           : C:\Users\krutik\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState
                               Flags              : 15
                               DefaultUid         : 1000
                               PackageFamilyName  : CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
                               KernelCommandLine  : BOOT_IMAGE=/kernel init=/init
                               DefaultEnvironment : {HOSTTYPE=x86_64, LANG=en_US.UTF-8, PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games, TERM=xterm-256color}

I have quite a few more, in various locations.

How do I access files in WSL2 from Windows?

But the title of your question, "where", doesn't really matter much unless you need to do something with the ext4.vhdx file (like perhaps reclaim space).

To access files in WSL from Windows, use the \\wsl$\Ubuntu path (or whatever your distribution is named). Here, you'll find \\wsl$\Ubuntu\home\nkp68, where you can safely copy in and out files.

Updated note: Under Windows 11, \\wsl$\<distro_name> still works, but there is also a new \\wsl.localhost\<disro_name> path as well. Both work the same, but wsl.localhost should be a bit more robust in certain situations.

How do I access files in my Windows machine from WSL2?

If you are in Ubuntu and need access to a file on a Windows drive (e.g. C:), then you'll find those are (by default) auto-mounted for you:

ls /mnt/c/Users
ls /mnt/c

There are some nuances in working with files on a Windows drive from within WSL, especially around permissions and performance. You'll typically want to keep any project files inside the Ubuntu ext4 filesystem (e.g. under your /home/nkp68 directory). But you can certainly access, copy, and move files around between the drives as needed.

Where is the WSL feature located?

The title of the question could be interpreted to mean that you want to know where the actual WSL feature is installed. I know that wasn't the case for you, the original poster, but the question has come up from others, so I'll add it here in case they find this based on the title.

The location of the WSL feature on your system will depend on the version of WSL you are using:

  • Older versions of WSL were included with Windows itself since at least Windows 10 21H2 (and perhaps before) as a Windows feature, and it's still possible to enable this feature today.

    When you do turn on the WSL Windows feature, the WSL applicable binaries are found under C:\Windows\System32\lxss. You'll rarely need to worry about this folder, but there are some times when it comes in handy.

    The WSL2 kernel is also located in this folder, and you can back up older kernels if you want to rollback more than one release.

  • Newer releases of WSL are installed as an application package, typically from the Microsoft Store.

    When you install the WSL application package, the files are located (as is typically the case with Windows application packages) in C:\Program Files\WindowsApps\<package_dir>.

    Note that C:\Program Files\Windows Apps is a protected directory, and you won't be able to see the contents by default. You should not attempt to change the permissions on this directory, and that will compromise the security and stability of your system.

    However, you can still see the contents of the package directory, assuming you know its name. To find it, run the following from PowerShell:

    Get-AppxPackage |? { $_.Name -like "*WindowsSubsystemforLinux*" } | tee-object -Variable packageMatches
    

    You should see an InstallLocation returned with the results. If there's only one result (which should be the case), you can open it with:

    explorer "$($packageMatches.InstallLocation)"
    

    Also, inside this directory, you'll find tools\kernel, which is the WSL2 kernel for this release.

  • On Windows 10 systems, you'll likely have both of these.

  • On Windows 11 systems, you may have both of these installation locations if you've installed WSL1.

3
  • 2
    To add to the last part of this answer: How to access network drives (e.g. mapped by NET USE F: \\server\share) from WSL? Do something like sudo mount -t drvfs F: /mnt/f/ (after first creating directory /mnt/f, or use a different directory as mount point - not recommended) Commented Dec 11, 2021 at 14:15
  • I normally don't do this, but ... bravo! This is the golden kind of content that used to shine around here...
    – weisk
    Commented Feb 9 at 13:56
  • 1
    @weisk Thank you! I'd love to be doing more of it, but about a year back I shifted too much of my Stack Exchange time over to finding and flagging ChatGPT/AI/LLM-generated answers (the kind of content that seems to not-shine around here now), especially on Stack Overflow. I'm hoping to get back to posting more answers soon, though. Commented Feb 9 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .