1

So I'm currently in the process of configuring and setting up my WSL on my Windows 10 workstation so I can use some very useful command line tools on Windows. Now in both WSL and Git-Bash you have access to all drives and partitions and all the files on the PC (that your user has access to), but the paths are different. Let's say I have a temp directory located at with a few files in it

tree C:\Temp
C:\TEMP
├───tempfile1.txt
├───tempfile2.txt
└───tempfile3.txt

Then when I open Git-Bash (using this SO Q&A) in the C:\Temp directory run the pwd command I see the path as

/c/Temp

but weirdly enough when I run an ls command in / in Git-Bash I don't see a c directory and no mnt directory either.

Now to WSL, when I do Open Linux Shell here via the right-click context menu in the Windows Explorer and run pwd it shows the path as being

/mnt/c/Temp

So my question is this: What and where is the '/' directory in Windows? And are these just 2 different ways of "mocking" the root directory?

Edit:
Windows version: Windows 10 Enterprise Edition Version 1903 (Build 18362.267)
WSL Version: 1809 (Build 17763) (Newest release as of time of writing)

  • @Ramhound Just added the information – MindSwipe Aug 16 '19 at 13:03
3

Your Git-Bash is a typical Windows program, and functions as such. It sees C:\ as its root directory.

Your WSL however, is different. I'm not sure if it's a container or VM, but regardless, it is definitively not a typical Windows program.
It still runs on Windows, but anything you run in WSL, essentially, sees itself as running on Linux, not Windows. This makes it follow Linux standards, such as Linux's directory structure.

This means, it has its own root directory, which instead of C:\, is /. The location of this directory is somewhere in your AppData, and varies based on the version of WSL and whether you're using Ubuntu, OpenSUSE, or whatever else.

In Linux, drives are not given letters. They are given mount points. The root / for example is the mount point of your root partition- or folder, in the case of WSL. Not everything under / is the same drive. For example, on my laptop, /home/ is on a separate partition.

/mnt/ is a mount directory in the Linux file structure. It's meant for external stuff.

/mnt/c/ is your C:\. It has to be like this because Linux doesn't give drives letters. This is the correct and most elegant way of accessing Windows files from WSL. This is why bash in WSL has a different location for your C:\.

Assuming you have the most common WSL distro (Ubuntu), your / should be here:

%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

If it's not there or you use a different distro, look here:

%LOCALAPPDATA%\Packages\

But be warned, Linux handles file permissions very differently from Windows. Do not do anything in here using windows tools like the File Explorer. If you need to interact between OSs, do it from within WSL.

  • 1
    Ah thanks. I don't have Ubuntu installed as I personally prefer Debian, but my Debian install was located at %LOCALDATA%\TheDebianProject.DebianGNULinux_76v4gfsz19hv4. Also just a quick note: WSL actually runs a full "fat" Linux kernel under the hood, using Pico Processes – MindSwipe Aug 16 '19 at 13:24
  • I see, I'd never heard of pico processes. Seems to work kind of similarly to virtualization. I'll have to look into it more later. I know Linux better than I know WSL, lol. – udlp Aug 16 '19 at 13:29
  • I think pico processes are a lot lower level and are spun up/ shut down like you would when working with threads. I'll also have a look into it later, as I know Windows a lot better than I know Linux. Although I can find my way around a terminal with ease at this point – MindSwipe Aug 16 '19 at 13:36
  • 1
    WSL1 doesn't run a Linux kernel at all; it just emulates the kernel syscall interface -- somewhat comparable to Wine. Each program in WSL gets its own pico-process; they're like normal Windows processes except they don't receive all the Win32-specific stuff upon creation, instead receiving the Linux-syscall shim. (However, WSL2 will run a full HyperV-based VM with standard Linux kernel, and will not use those.) – user1686 Aug 16 '19 at 13:37
  • 1
    WSL is not a virtual machine. It also is nothing like WINE. " WSL actually runs a full "fat" Linux kernel" - The current version of WSL does NOT run the Linux kernel. WSL 2 will run the Linux kernel. You are using the current version of WSL, which does not, run the Linux kernel. "Do not do anything in here using windows tools like the File Explorer." - Except 1903 WSL supports doing this. (Please fix these two major technical mistakes in your answer) – Ramhound Aug 16 '19 at 18:04
0

The / folder for WSL is in C:\Users\<userName>\AppData\Local\Packages\some serial number for ubuntu installation and can also be found as a network resource in \\wsl$\Ubuntu-18.04 or similar depending on what Linux distro you installed with for WSL.

For git bash its located at C:\Program Files\Git

You can always find the real location of any folder by going into it typing explorer.exe . git bash and wsl will both translate the . path for you and pass it along to the windows applications you run.

That being said you shouldn't open files these emulated / folders via windows at applications as they can have trouble reading it properly esp with WSL ones.

These programs are emulating the Unix file system for you without creating a virtual machine with segregated cpu and memory allocations. They just share with windows like a normal application does. (except in the case of WSLv2 which is running a full VM using windows 10 pro Hyper-V)

The /c or /mnt/c locations are network mounts very similar to mapping a network drive in windows to say Z: and pretending its a local disk.

GIT bash and WSL are mounting your windows root drives as if they are network resources. In Linux, you mount drive to a /folder because there is no such concept of a drive letter.

If you want you can tell WSL to mount the drives the same way that git bash does.

In wsl type edit the /etc/wsl.conf file

And add the following:

[automount]
root = /

Save the file and LOG OFF from Windows and back in again.

Now when you launch WSL it will have the same paths as git bash for your local hard drives.

Also, keep in mind that these are emulating the file system used by Linux operating systems but they don't do it perfectly and they don't do it the same way.

For example, Unix file systems have permissions on files, git bash will automatically detect what "SHOULD BE" and executable file and add the +x attribute. WSL does not do this very well usually just makes everything executable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.