I am currently configuring and setting up my Windows Subsystem for Linux (WSL) on my Windows 10 workstation to use command line tools. Both WSL and Git Bash allow access to all drives, partitions, and files on the PC (for the user’s access), but the file paths are different. For example, I have a temp directory with some files in it.
tree C:\Temp
C:\TEMP
├───tempfile1.txt
├───tempfile2.txt
└───tempfile3.txt
When I open Git Bash (by following this StackOverflow question and answer), navigate to the C:\Temp directory, and run the “pwd” command, I see the path as.
/c/Temp
However, when I run the “ls” command in the root directory of Git Bash, I don’t see a “c” directory or a “mnt” directory. On the other hand, when I use the “Open Linux Shell here” option in the right-click menu in Windows Explorer to open WSL, and run the “pwd” command, it shows the path as being.
/mnt/c/Temp
I am wondering what and where the root directory “/” is in Windows, and if these are just two different ways of mimicking the root directory.
Note: The Windows version used is Windows 10 Enterprise Edition Version 1903 (Build 18362.267) and the WSL version is 1809 (Build 17763) (latest at the time of writing).
2 Answers
The root directory in WSL and Git-Bash on Windows 10 is the file system root of the respective environment. In WSL, the root directory maps Windows file system drives to the “/mnt” directory (e.g. “/mnt/c” maps to the “C:” drive). In Git-Bash, the root directory maps Windows file system drives to “/” with the drive letter removed (e.g. “/c/Temp” maps to “C:\Temp”). These are two different ways to access the Windows file system from a Unix-like environment.
Windows Subsystem for Linux (WSL) is a compatibility layer that allows you to run Linux applications natively on Windows. The WSL file system is separate from the Windows file system, but it can access the Windows file system through the “/mnt” directory. This means that the “/mnt/c” directory in WSL maps to the “C:” drive in Windows, “/mnt/d” maps to the “D:” drive, and so on.
Git Bash, on the other hand, is a Unix-like shell for Windows that provides Git version control system and Unix commands. In Git Bash, the root directory “/” maps Windows file system drives with the drive letter removed (e.g. “/c/Temp” maps to “C:\Temp”).
Both WSL and Git Bash provide access to the same Windows file system, but the way they present the file system is different. The paths to the same file or directory in WSL and Git Bash will look different, but they both point to the same location in the Windows file system.
Git Bash is a typical Windows program and operates as such, with C:\
as its root directory. On the other hand, WSL is different and may be a container or VM, but it is not a typical Windows program. While it runs on Windows, any program running in WSL perceives itself as running on Linux, not Windows. This means it follows Linux standards, such as the Linux directory structure.
As a result, WSL has its own root directory, which is located at /
, instead of C:
. The location of this directory can vary based on the version of WSL and the distribution used (such as Ubuntu, OpenSUSE, etc.) and is somewhere within the AppData.
In Linux, drives are not assigned letters; they are given mount points. The root directory /
is the mount point of the root partition or folder in the case of WSL. Not everything under /
is on the same drive. For example, on my laptop, /home/
is on a separate partition.
The directory /mnt/
is a mount directory in the Linux file structure, meant for external files. /mnt/c/
is the equivalent of C:\
in Windows. This is necessary because Linux does not assign letters to drives. Accessing Windows files from WSL is done through this method.
If you are using the common WSL distribution Ubuntu, your /
is located at: %LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs
If it’s not located there or you are using a different distribution, you can look in: %LOCALAPPDATA%\Packages
It’s important to note that Linux handles file permissions differently from Windows, so it is not recommended to use Windows tools like File Explorer to interact with the files in this directory. If you need to interact between the operating systems, it’s best to do it from within WSL.