0

Does anyone know why Microsoft chose to mount the WSL directory on /mnt/c instead of /c?

I have seen a tutorial online on how to change it to /c, but I am afraid this change could brake something.

2 Answers 2

4

The location of various mount points is the domain of the FHS. There are a few options available for mounting a permanent volume, such as the Windows C drive. Let's go through them to understand the rationale behind Microsoft's decision.

At /media/c

This would have been my first thought, since /media/* is where I'm personally accustomed to mounting permanently installed drives such as internal hard drives and SSDs on my Linux machines.

The FHS says:

This directory contains subdirectories which are used as mount points for removeable media such as floppy disks, cdroms and zip disks.

So, according to the spec, it's not quite what we want. While I'm not sure whether it's technically possible to unmount c from WSL, it's certainly not removable in the traditional sense of the word.

A number of GUI file browsers will also show volumes mounted there in the sidebar. This usually shouldn't be a huge concern with WSL, but it's good to consider nonetheless.

Pros:

  • A pretty intuitive option
  • Supported by many file managers

Cons:

  • Not exactly spec-compliant
  • Puts removable and permanent media together

At /mnt/c

This is clearly the option Microsoft chose. But why? Looking at the spec again, we see:

This directory is provided so that the system administrator may temporarily mount a filesystem as needed.

Although the use of subdirectories in /mnt as a mount point has recently been common, it conflicts with a much older tradition of using /mnt directly as a temporary mount point.

Hm. This doesn't really fit our use case either. Typically, when using /mnt, it's /mnt itself that's mounted to, rather than a subdirectory -- but since this should only be done temporarily and manually by an administrator, the administrator may still mount wherever they like inside /mnt at their own discretion. Certainly, it's not meant to be automatically mounted to by the system. All in all, this seems like a poor choice on Microsoft's part.

Pros:

  • ???

Cons:

  • Definitely not spec-compliant
  • Means you can't mount anything to /mnt
  • Suggests it was mounted manually rather than automatically

At /c

This may come across as an intuitive and obvious choice. It mirrors the Windows metaphor of the drive name being the first part of every path, and it's easy to type out and remember. But the FHS doesn't like arbitrary directories in /.

There are several reasons why creating a new subdirectory of the root filesystem is prohibited:

  • It demands space on a root partition which the system administrator may want kept small and simple for either performance or security reasons.

  • It evades whatever discipline the system administrator may have set up for distributing standard file hierarchies across mountable volumes.

Distributions should not create new directories in the root hierarchy without extremely careful consideration of the consequences including for application portability.

Pros:

  • Intuitive

Cons:

  • Definitely not spec-compliant

Summary

Where to mount permanent drives is a long-standing question amongst users of *nix systems. Unfortunately, there doesn't seem to be a great amount of consensus right now. My personal opinion is that Microsoft made the wrong decision, and /media/c would have been better, although /c would also be a valid option. It's possible, though, that due to the lack of agreement, it was simply chosen at random by a developer and never changed. Whatever the case, the answer to why WSL mounts C: at /mnt/c is that "it just does".

2
  • but that's for temporary drives, no?
    – mFeinstein
    Apr 23, 2023 at 19:49
  • 1
    @mFeinstein Updated my answer for some more clarity :)
    – theo
    Apr 24, 2023 at 9:32
3

Does anyone know why Microsoft chose to mount the WSL directory on /mnt/c instead of /c?

As the other current answer here demonstrates (and quite well), it may be more a matter of opinion than anything. Since opinion-based questions are, to be fair, off-topic here, I'm going to address the other part of your (implied) question:

I have seen a tutorial online on how to change it to /c, but I am afraid this change could break something.

While I don't necessarily encourage it, I don't worry about it breaking anything, at least not in the traditional sense.

The method for changing it is directly mentioned in the [WSL docs](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#automount-settings. Just sudo -e /etc/wsl.conf and add:

[automount]
root=/

Exit your WSL distribution, run wsl --shutdown (or wsl --terminate <distro>) from PowerShell (as a regular, non-admin user), and restart.

You should now see /c (and any other Windows drives at the root level). Note that the pre-existing mountpoints under /mnt (such as /mnt/c) will still exist, but be empty. You can sudo rmdir /mnt/c (etc.) for each drive.

I have some fairly benign reasons for recommending that you keep the mounts at /mnt:

  • Everybody else is doing it ;-)

    If you are following WSL directions (such as another Stack answer), they'll typically assume that the location is /mnt/c

  • Some code may erroneously assume /mnt/c

    There's a slim chance that some third-party code might assume /mnt/c as well. Not that there's much in the way of third-party WSL code that you'll probably run.

  • Everybody else is doing it (redux)

    When you post a question in the future, if you do change the mountpoint to /c, then I do encourage you to make sure you reference this fact in your question (assuming that you are working with that path). Otherwise, it's just one more detail that will likely have to be sorted out by those who hope to answer.

But again, this just means that keeping the WSL default is the "path of least resistance". I still don't expect anything to "break" if you do it.

1
  • Good answer, covering an aspect I missed! It's worth noting for your second point that code shouldn't assume anything in /mnt: "The content of this directory is a local issue and should not affect the manner in which any program is run." But that's assuming compliance with the specification, and sadly that's not the world we live in ;)
    – theo
    Apr 24, 2023 at 18:31

You must log in to answer this question.

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