Where is WSL located on my computer?
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?
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.
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.