What is the home directory on Windows Subsystem for Linux?
In the latest versions [2020], the file system is accessed from:
# \\wsl$\<Distribution>:
\\wsl$\Ubuntu
Previously, as of 2018, The current path is related to which distribution you have installed from the Microsoft Store rather than one global path; for Ubuntu, it was located at:
%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs
Other distributions should be (to be confirmed) in a similar location under their respective folders within:
%LOCALAPPDATA%\Packages\
In Bash, to view the current directory in Windows File Explorer just enter:
explorer.exe .
Don't leave out the ".".
This will open windows explorer at the current folder and you can see where everything is in relation to the rest of your Windows system.
-
/mnt/c
is the exact same asC:\
. It's just the syntax for getting to it from WSL. - Look in
C:\Users\<username>\AppData\Local\Lxss\rootfs
.
About the filesystem mounted on /mnt/c
- What exactly is /mnt/c/Users/ compared with C:\Users<username>? It seems they are one in the same---so what is /mnt/c/?
In contrast to Windows, Linux (and the other systems based on Unix) use a single folder structure independent of the number of disks you have. If you have multiple disks, all these disks must me mounted into the folder structure at some point.
- Typically, all the disks (different than the used to boot the system) are mounted in a folder named
/mnt
or/media
WSL has an special type of filesystem named DrvFS that gives you access to the disks used in windows. You can use DrvFS to mount, not only your windows filesystem, but also network disks and other media types.
- In WSL, by default, the
C:
disk in windows is mounted under/mnt/c
- If you have another disk, for instance a
D:
disk in windows, it will be mounted under/mnt/d
The files you can see in /mnt/c
are the same you have in C:
. If you modify some file, you will get the changes in the windows too.
You may use the mount
command to access other types of media (e.g. removable drives or network shares).
About the location of /home/<username>
- How can I view the files in /home/ using the Windows File Explorer? Not that I'd really ever want to---I'm just trying to get a feel for how Windows is organizing this Subsystem for Linux thing.
In WSL, all the linux filesystem is located under a Windows folder. The location of the folder depends on the version of Windows and of the WSL distribution you are using.
-
Initial versions of WSL store the linux filesystem in
%LOCALAPPDATA%\Lxss\rootfs
-
WSL distributions installed from the Windows Store, starting in Windows Build 16215 (mid of 2017), use a folder like
%LOCALAPPDATA%\Packages\{package}\LocalState\rootfs
. The name of the package varies depending on the distribution (e.g. it is different for Ubuntu than for Debian). For Ubuntu on Windows it isCanonicalGroupLimited.UbuntuonWindows_{code}
, for example. - Linux distributions installed using other tools, such as lxRunOffline or WSL-DistroLauncher may store the linux filesystem into any location.
You may check many options to know the location of the WSL folder. For instance, I think the easiest option is to use lxRunOffline to know the installation folder.
## You can use lxrunoffline to check which WSL distributions have installed
## using: lxrunoffline list
C:\> lxrunoffline list
backup
Ubuntu-18.04
## And you can use it to get the location of any of these WSL installations
## using: lxrunoffline get-dir -n <name of distribution>
C:\> lxrunoffline get-dir -n backup
c:\wsl\installed\backup
C:\> lxrunoffline get-dir -n Ubuntu
C:\Users\Jaime\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState
Once you know the location of the installation folder, the /home/<username>
is under <installation folder>\rootfs\home\username
.
- For instance, if your installation folder is
c:\wsl\ubuntu
- the
/home/<username>
is inc:\wsl\ubuntu\rootfs\home\username
NOTE: Both Linux and Windows stores file permissions in different ways. Nowadays, the WSL DrvFS stores the Linux permissions as Streams (metadata) attached to the files you can see in Windows. Microsoft does not recommend to modify linux files using Windows programs. It is possible that some Windows applcations damage the linux permissions without notice it.