Skip to content

WSL2 Increase the maximum amount of inotify user watches #4293

Closed

Description

Please consider increasing the maximum amount of inotify user watches (fs.inotify.max_user_watches) in WSL2.
The current limit (8192) is too low for most projects.

For a seamless Visual Studio Code Remote Development experience a new limit of 524288 is suggested. That would allow to watch up to 524288 files, using up to 540 MiB kernel memory.

Alternatively make fs.inotify.max_user_watches configurable, which would probably require the init system of WSL2 to read configuration files placed in /etc/sysctl.d/. See #4232.

The current workaround is:

  • Create a script:
#!/bin/sh
sysctl fs.inotify.max_user_watches=524288
sysctl -p
  • Run sudo chown root:root and sudo chmod 755 on the script
  • Either move the script to a directory owned by root or run sudo chattr +i on it, otherwise it can be deleted
  • Run sudo EDITOR=nano visudo and add this:
    %sudo ALL=(ALL:ALL) NOPASSWD:/path/to/script.sh
  • Add this to .profile:
    sudo /path/to/script.sh
  • Don't forget to remove the line above from visudo if you delete /path/to/script.sh

Activity

  1. therealkenc commented on Jul 10, 2019

    @therealkenc
  2. marcinolek commented on Jul 30, 2019

    @marcinolek

    @Comevius thank you, thank you, thank you! This is really a brilliant workaround, and actually the only one that works. I spent several hours trying to make it work and the most of 'google' solutions claimed that:
    sudo sysctl fs.inotify.max_user_watches=524288 && sudo sysctl -p should've been enough to make it pernament. It is not the case for WSL. Now everything works smoothely.

    This really needs to be documented (at least) or implemented in WSL2.

  3. jiangbo0216 commented on Oct 14, 2019

    @jiangbo0216

    I use sudo passwd root to enable root user ,
    then cd /root
    then I create a init.sh file in /root
    then I sudo chown root:root init.sh and sudo chmod 755
    then vim /etc/sudoers
    add %sudo ALL=(ALL:ALL) NOPASSWD:/root/init.sh
    then vim .profile
    add sudo /root/init.sh

    the result : fail
    #4232
    please help!!

  4. gorbunovav commented on Oct 23, 2019

    @gorbunovav

    jiangbo (@jiangbo0216) it works for me.

    You don't need to enable password for root, just use
    sudo su -

    You can't use vim directly to edit /etc/sudoers, you should use visudo (pay attention to the original instructions).

    There is already a line in /etc/sudoers for the %sudo group, the order of records is important, so you should put the additional record after the existing one:

    %sudo   ALL=(ALL:ALL) ALL
    %sudo   ALL=(ALL:ALL) NOPASSWD:/root/init.sh
    

    You need to exit the editor the changes to take effect.

    To check, that everything works just open another bash shell and try to execute:
    sudo /root/init.sh
    it should not ask for a password.

    After placing script call into the .profile there should be init.sh output visible during the shell start.

  5. alan23273850 commented on Jun 12, 2021

    @alan23273850

    https://auo.nu/posts/wsl2-livereload/

    This blog post says that WSL2 only watches file in the WSL-related folders. So I move my original one from Windows-related to WSL-related and it works! Many thanks to this blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions