3

inotify worked in WSL1. Then it was deliberately turned off in WSL2 due to an unsupported feature in a GNU software which is now solved.

How can inotify be enabled or turned on in WSL2?

David Jonsson
  • 318
  • 5
  • 19
  • Similar to, but IMO not a duplicate of [How can nodemon be made to work with WSL 2?](https://stackoverflow.com/q/63402588/11810933). I've provided an answer here to your specific question, but can you edit your question to clarify the "GNU software [issue] which is now solved"? – NotTheDr01ds Dec 08 '21 at 13:09
  • I see a CV as "off-topic", but inotify seems to me to be *almost* purely a feature used by developers. Might be good, though, to also update your question to reference a specific inotify use-cases you use. This might alleviate some folks "off-topic" concerns. Thanks! – NotTheDr01ds Dec 08 '21 at 13:29
  • 1
    Had I known that `inotify` in Windows drives wouldn't work on `WSL2`, then I would not have wasted time converting to `WSL2`, this is a deal-breaker. I'm going back to `WSL1`. – daparic Feb 25 '22 at 21:03

1 Answers1

9

inotify is supported in WSL2, but only on the Linux-based ext4 filesystem. Where you may be having trouble is that it does not work on Windows drives which are mounted using the 9P protocol (e.g. /mnt/c) or symlinks to any files on those drives.

I'm unaware of this being (per the question) due to "an unsupported feature in a GNU software which is now solved", nor it being "deliberately turned off". It's my understanding that the WSL team just hasn't "plumbed" (their word from the 2019 Build Conference) it in 9P.

It does, as you mention work in WSL1 on Windows drives mounted via drvfs, and using WSL1 is still a viable option for many development tasks. Of course, this is only necessary if you require that your watched files be on a Windows drive. Also note that WSL1 really used the Windows drive for both the Linux filesystem (via an overlay of sorts in your WSL1 directory), so if inotify worked for one, it likely worked for both for the same reason (same implementation of syscall translation).

The simplest solution, though, if it meets your workflow, is to just move your project somewhere on the WSL/Linux/ext4 filesystem, such as under your $HOME folder (again, not using a symlink).

As for how to enable it, I don't think that's going to be possible. While the 9P client is open-source and included in the WSL2 kernel Github project here, the server that runs in Windows and provides access to those drives is, as far as I know, still closed-source.

For more details, see this answer.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70