1

As NotTheDr01ds mentioned in this answer, /dev/sda in WSL2 is a virtual drive which Windows creates to store a swap file shared between WSL instances. But it isn't mounted by default when instance starts.

I have a few questions about it.

  1. cat /proc/swaps references file /swap/file as used swap, but /swap directory even doesn't exist. Why?

  2. How is swap used without this drive being mounted there by default?

  3. Should it be mounted by hand to be used?

  4. If no, will something be broken if I do it or add the corresponding line to /etc/fstab?

Actually, 4'th is the most important question for me, because I'm getting annoyed by thunar-volman's mount suggestion for /dev/sda. But it's interesting to get answers for other questions too.

3
  • 3
    In WSL 2, every distribution runs in the same VM, but in different namespaces (similar to Docker). You cannot see what's in the "root" namespace.
    – Daniel B
    Commented Apr 4, 2022 at 5:43
  • @DanielB I still can mount /dev/sda and see the file named file there. So your comment says nothing linked to my questions to me.
    – lem0nify
    Commented Apr 4, 2022 at 5:58
  • 1
    I think my comment very accurately answers your questions 1, 2 and 3.
    – Daniel B
    Commented Apr 4, 2022 at 7:02

1 Answer 1

1

@DanielB does actually answer this perfectly correctly in the comments, but, as I said in my reply on another question, it probably needs an answer to fully explain it.

First, realize that there are (for the sake of this discussion) two parts to WSL2:

  1. The Virtual Machine Platform where the actual WSL2 virtual machine is running. To my knowledge, there's no way for you to actually see or interact with this virtual machine.

  2. The WSL2 distributions that you run. These aren't virtual machines themselves, but are instead separate containers created inside individual namespaces.

Each WSL2 distribution (I call them "instances") has its own individual:

  • Users
  • Mounts
  • PID mapping
  • And more

But it also shares some resources with the parent. As with a Docker container:

  • The same kernel is being used for all WSL2 instances
  • The same memory is being used for all WSL2 instances
  • Of course, the same CPU
  • The same device tree (/dev), which includes /dev/sdb where the swap lives.
  • And, most importantly for your question, the same Swap memory itself is being used for all instances.

This swap is handled by and mounted in the parent VM that you can't access. It's reported in /proc/swaps, but that report comes from the parent VM kernel.

This is identical to the way that Docker containers handle swap. I just ran an Ubuntu Docker container on two different hosts (one virtual itself, the other physical). One reported:

$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/swapfile                               file            2097148 300288  -2

The other:

$ cat /proc/swaps
Filename                                Type            Size            Used            Priority
/dev/sdb                                partition       524284          780             -2

In the first case, /swapfile does not exist within the container. On the second, /dev/sdb is not mounted within the container.

will something be broken if I do it or add the corresponding line to /etc/fstab?

I don't know the answer to that. In my previous answer that you linked to, I said it was "not recommended", but I do not know if there's any potential problem that could occur. It seems safe, but it certainly seems safer not to ;-).

7
  • But still, is there any other known way to prevent /dev/sda to be suggested for mount by thunar-volman and similar plugins? Just it but not other drives.
    – lem0nify
    Commented Apr 4, 2022 at 12:53
  • @lem0nify I hate to keep saying this, but that feels like another separate question, and one that I don't know the answer to at the moment. I just installed and ran thunar, turned on the volume management, but I'm not getting warnings about the swap drive. Could you post a question with enough detail on how you've installed and configured thunar and thunar-volman for me to reproduce it? Commented Apr 4, 2022 at 15:33
  • you need thunar, thunar-volman and gvfs. No warnings, it just suggests you to mount every unmounted /dev/[s,h]d* in left side pane.
    – lem0nify
    Commented Apr 4, 2022 at 18:28
  • @lem0nify I already had gvfs before installing the other two, but I'm not seeing it. A couple of possible differences - Are you running any Systemd script? Ubuntu 18.04 or 20.04? I'm not running Systemd, using 20.04. I've launched both with thunar and dbus-launch thunar (required for GVfs), but in neither case am I seeing mounting suggestions. Commented Apr 4, 2022 at 19:02
  • 1
    @lem0nify Try this for sda. I got Thunar working under my Artix distro (non-Systemd) and using udev rules worked for me to remove that drive from the auto-mount list in Thunar. Commented Apr 5, 2022 at 2:22

You must log in to answer this question.

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