Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL2 Increase the maximum amount of inotify user watches #4293

Closed
Comevius opened this issue Jul 10, 2019 · 5 comments
Closed

WSL2 Increase the maximum amount of inotify user watches #4293

Comevius opened this issue Jul 10, 2019 · 5 comments

Comments

@Comevius
Copy link

Comevius commented Jul 10, 2019

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
@therealkenc
Copy link
Collaborator

#4232

@marcinolek
Copy link

@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.

@jiangbo0216
Copy link

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!!

@gorbunovav
Copy link

@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.

@alan23273850
Copy link

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
Projects
None yet
Development

No branches or pull requests

6 participants