You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[wsl2] values from /etc/sysctl.conf not applied on container start #4232
Your Windows build number: (Type ver at a Windows Command Prompt)
Microsoft Windows [Version 10.0.18922.1000]
What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)
Trying to increase max_user_watches according to vs-code instructions.
Edit /etc/sysctl.conf, then apply values with sudo sysctl -p
Reboot, reopen vs-code, get same error. cat /proc/sys/fs/inotify/max_user_watches --> 8192, not the 524288 value listed in sysctl.conf
actually apply the sysctl values manually: sudo sysctl -p cat /proc/sys/fs/inotify/max_user_watches --> 524288
What's wrong / what should be happening instead:
some process in /init should be applying sysctl values from /etc/sysctl.conf, but that isn't happening.
workaround:
add sudo sysctl -p to .bashrc or similar. Not ideal, not guaranteed to be triggered unless a bash process is started.
Reacted by Tony Narlock, Isaac Daly, Marek, Matej Simek, Joe Maller, Adam Michał Małecki, Mitchell Skaggs, Paweł J. Wal, Matt Wojick, Jesus Pulido and 35 more
This is variation everything systemd. Nothing is reading /etc/sysctl.conf. [Nothing is reading /etc/environment ref #1405 either.]
I believe SOP for now would be to stick it in .bashrc with sudors tricks (make a script and give the script full reign). Or go ballz #994. Or alt approach hypothetical open-ended #2530 flips status.
I am tentatively (really super tentatively) looking at posting something to get us by, for a while, on these. No promises. Not really fair to dupe #994#2530 either. So, yeah.
[ed: Pulled suggestion maybe WSL2 should just have a bigger default in the kernel. Doesn't seem as great/simple an idea on the second day.]
Ran in to this as well following the VSCode WSL setup. Slight change to the shell init script workaround: use sudo sysctl -qp to prevent it printing the set values at the start of every new shell.
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
does this issue have any attention from maintainers? It's critical bug, because it makes user responsible to e.g. increase notify limits every system start which is ridiculous... To be honest its last thing which hold me from switching completely from Linux to Windows...
I confirm that this is bug /etc/sysctl.conf is not apply. Also when you restart computer you also need to set the value again I had test on /etc/sysctl.conf : vm.max_map_count too.
I too have the same issue - I'm running GreenGrass and it requires some settings to be applied in sysctl. Currently I've got this in a sudo script but it would be nice to have those applied when firing up the container.
One of my containers is an elasticsearch instance, and I have the issue where I need to increase vm.max_map_count in order to get it to work properly.
I've added vm.max_map_count=262144 to /etc/sysctl.conf and then load the value with sysctl -p and the ES instance then loads properly. But once my computer is rebooted, that value, while still written, isn't loaded. Is there still no movement on this issue after two years? Are people beating it another way?
Reacted by Gheorghe Avram, Ahn, JongMoon and lgraves
Use wsl.exe -u root command to access sudo level access. No need to use sudo or password in WSL environment.
Thank you so much for this. I did not know you can drop into the the root wsl vm like this.
I dropped into the shell ran this for Elastic Search docker (or sonarqube docker) sudo sysctl -w vm.max_map_count=262144
Quite a few people have found my solution on Stack Overflow, but for those that come across this first, I'll repost here.
There are multiple ways to automatically set kernel parameters in WSL2 when booting. IMHO, both of these are preferable to the techniques mentioned in this issue already:
Best option: .wslconfig using kernelCommandLine
Any kernel parameters that can be changed via /etc/sysctl.conf can be set through the .wslconfig. This file does not exist by default, so if you don't have one, you'll need to create it in your Windows user profile directory (typically C:\Users\username\.wslconfig).
Option 2: Windows 11 [boot].command in /etc/wsl.conf:
Windows 11 users can take advantage of a new WSL feature to run any command as root during the WSL distribution startup. As sudo, create or modify /etc/wsl.conf:
Reacted by Biswapriyo Nath, nights99, Argelbargel, Bruno Buiret, Andrei Pangin, Dawid Makowski, Bas van den Wollenberg, Tushar Singh, Zsolt Szikora, David Emmerson and 2 more
If any of the WSL team come across this one, I'd recommend this could be closed based on "workaround-available" (I don't think kernelCommandLine was available when this issue was originally written) and the fact that the root issue is tracked in #994.
Option 2: Windows 11 [boot].command in /etc/wsl.conf:
Windows 11 users can take advantage of a new WSL feature to run any command as root during the WSL distribution startup. As sudo, create or modify /etc/wsl.conf:
Interestingly, it seems that only /usr/local/bin:/usr/bin gets loaded to $PATH when WSL executes commands in /etc/wsl.conf.
# /etc/wsl.conf
[boot]
command="sysctl -V > /out 2> /out2"
# /out2
sh: line 1: sysctl: command not found
@rlSimonLi Hmm -- That's odd. It's probably safer to call it with a fully qualified path anyway, but I'm wondering why yours isn't found on the search path.
Are you using a Preview release, and if so which one? And what distribution are you using?
Douglas (@NotTheDr01ds) I am using WSL Preview from MS Store and the distro is Fedora 36 installed via Fedora Container Base roofs. I can confirm this behaviour doesn't happen with Ubuntu downloaded from MS Store. It might just be that the container base does things differently, but again I don't know how $PATH is loaded on vanilla Linux as well as WSL to investigate this further.
I just stumbled upon this, and it looks like systemd support is available but not enabled by default. Enabling it either in .wslconfig or wsl.conf will start systemd and apply the sysctl.conf changes.
I just stumbled upon this, and it looks like systemd support is available but not enabled by default. Enabling it either in .wslconfig or wsl.conf will start systemd and apply the sysctl.conf changes.
This will lead to a situation where kernel parameters will depend on the distro whose /etc/sysctl.conf is applied first.
Activity
therealkenc commentedon Jun 25, 2019
This is variation everything
systemd. Nothing is reading/etc/sysctl.conf. [Nothing is reading/etc/environmentref #1405 either.]I believe SOP for now would be to stick it in
.bashrcwith sudors tricks (make a script and give the script full reign). Or go ballz #994. Or alt approach hypothetical open-ended #2530 flips status.I am tentatively (really super tentatively) looking at posting something to get us by, for a while, on these. No promises. Not really fair to dupe #994 #2530 either. So, yeah.
[ed: Pulled suggestion maybe WSL2 should just have a bigger default in the kernel. Doesn't seem as great/simple an idea on the second day.]
magneticflux- commentedon Oct 9, 2019
Ran in to this as well following the VSCode WSL setup. Slight change to the shell init script workaround: use
sudo sysctl -qpto prevent it printing the set values at the start of every new shell.jiangbo0216 commentedon Oct 15, 2019
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
#4293
please help!!
jiangbo0216 commentedon Oct 15, 2019
I complete this with https://github.com/shayne/wsl2-hacks
nice job!
murbanowicz commentedon Oct 18, 2019
does this issue have any attention from maintainers? It's critical bug, because it makes user responsible to e.g. increase notify limits every system start which is ridiculous... To be honest its last thing which hold me from switching completely from Linux to Windows...
Stanzilla commentedon Apr 25, 2020
Craig Loewen (@craigloewen-msft) any update on this?
wdrdres3qew5ts21 commentedon Jun 2, 2020
I confirm that this is bug /etc/sysctl.conf is not apply. Also when you restart computer you also need to set the value again I had test on /etc/sysctl.conf : vm.max_map_count too.
krojew commentedon Jul 27, 2020
Just stumbled upon this. Is anyone working on it?
mitsos1os commentedon Sep 11, 2020
Also confirmed on Microsoft Windows [Version 10.0.19041.508]
Setting
vm.swappinessdoes not have any effect after restart. Have to manually setmariotoffia commentedon Nov 12, 2020
I too have the same issue - I'm running GreenGrass and it requires some settings to be applied in sysctl. Currently I've got this in a sudo script but it would be nice to have those applied when firing up the container.
shelllee commentedon Jun 19, 2021
maybe run a powershell script when windows startup can help?
ps: use pipeline to redirect output password to sh input
benyaminl commentedon Jul 19, 2021
Seems not secure as password is written on shortcut and shown on powershell history
jdhorner commentedon Sep 17, 2021
One of my containers is an elasticsearch instance, and I have the issue where I need to increase
vm.max_map_countin order to get it to work properly.I've added
vm.max_map_count=262144to/etc/sysctl.confand then load the value withsysctl -pand the ES instance then loads properly. But once my computer is rebooted, that value, while still written, isn't loaded. Is there still no movement on this issue after two years? Are people beating it another way?RaulSokolova commentedon Sep 19, 2021
I tried all the approaches and non worked for me... However I was able to set it permanently like this.
To verify it works:
Hope it works for you.
shelllee commentedon Oct 15, 2021
yean, it's not secure
Biswa96 commentedon Oct 15, 2021
Use
wsl.exe -u rootcommand to access sudo level access. No need to use sudo or password in WSL environment.p10tyr commentedon Jan 25, 2022
Thank you so much for this. I did not know you can drop into the the root wsl vm like this.
I dropped into the shell ran this for Elastic Search docker (or sonarqube docker)
sudo sysctl -w vm.max_map_count=262144Recreated the docker compose.. boom. working
Thank you Biswapriyo Nath (@Biswa96) !!
NotTheDr01ds commentedon Aug 31, 2022
Quite a few people have found my solution on Stack Overflow, but for those that come across this first, I'll repost here.
There are multiple ways to automatically set kernel parameters in WSL2 when booting. IMHO, both of these are preferable to the techniques mentioned in this issue already:
Best option:
.wslconfigusingkernelCommandLineAny kernel parameters that can be changed via
/etc/sysctl.confcan be set through the.wslconfig. This file does not exist by default, so if you don't have one, you'll need to create it in your Windows user profile directory (typicallyC:\Users\username\.wslconfig).Place the following in that file:
If you have multiple parameters to modify:
Option 2: Windows 11
[boot].commandin/etc/wsl.conf:Windows 11 users can take advantage of a new WSL feature to run any command as root during the WSL distribution startup. As
sudo, create or modify/etc/wsl.conf:NotTheDr01ds commentedon Aug 31, 2022
If any of the WSL team come across this one, I'd recommend this could be closed based on "workaround-available" (I don't think
kernelCommandLinewas available when this issue was originally written) and the fact that the root issue is tracked in #994.simonsimonli commentedon Sep 17, 2022
Interestingly, it seems that only
/usr/local/bin:/usr/bingets loaded to $PATH when WSL executes commands in/etc/wsl.conf.So you might need to do this instead:
I am not too familiar with the intricacy of how $PATH gets loaded during boot, would be great if anyone can verify and shed some light on this.
NotTheDr01ds commentedon Sep 19, 2022
@rlSimonLi Hmm -- That's odd. It's probably safer to call it with a fully qualified path anyway, but I'm wondering why yours isn't found on the search path.
Are you using a Preview release, and if so which one? And what distribution are you using?
simonsimonli commentedon Sep 19, 2022
Douglas (@NotTheDr01ds) I am using WSL Preview from MS Store and the distro is Fedora 36 installed via Fedora Container Base roofs. I can confirm this behaviour doesn't happen with Ubuntu downloaded from MS Store. It might just be that the container base does things differently, but again I don't know how $PATH is loaded on vanilla Linux as well as WSL to investigate this further.
magnen commentedon Oct 26, 2022
I just stumbled upon this, and it looks like systemd support is available but not enabled by default. Enabling it either in .wslconfig or wsl.conf will start systemd and apply the sysctl.conf changes.
tusharsnx commentedon Dec 7, 2022
This will lead to a situation where kernel parameters will depend on the distro whose
/etc/sysctl.confis applied first.benhillis commentedon May 18, 2026
This works once systemd is enabled — systemd processes
/etc/sysctl.confat boot. Enable systemd in/etc/wsl.conf:See https://learn.microsoft.com/windows/wsl/systemd. Please reply if you still see the issue with systemd enabled.
harden(sandbox/wsl2): narrow AppArmor + boot-time reapply + version p…