1

I'd like to change the default smb settings at startup to remove timeouts. I have the following script;

#!/bin/sh

sysctl net.smb.fs.kern_deadtimer=0
sysctl net.smb.fs.kern_hard_deadtimer=0
sysctl net.smb.fs.kern_soft_deadtimer=0

Running this script with sudo sets the relevant kernel options correctly. So I know that these commands are the correct ones.

I have created the following LaunchDaemon in /Library/LaunchDaemons/ to try and get this script to run at startup;

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.jo.sysctl</string>
    <key>Disabled</key>
    <false/>
    <key>UserName</key>
    <string>admin</string>
    <key>GroupName</key>
    <string>staff</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/admin/scripts/sysctl.sh</string>
    </array>
    <key>KeepAlive</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

I've checked the plist with plutil and it checks out OK. I've set the permissions on the shell script to 0755 and set ownership of the plist file to root:wheel.

Running

sudo launchctl load /Library/LaunchDaemons/com.jo.sysctl.plist

...does nothing. The defaults are still set incorrectly. Where am I going wrong?

Thanks

  • You probably want to use the whole path to sysctl. – Allan Apr 6 '18 at 16:42
  • /private/etc/sysctl.conf should still work in High Sierra! (man sysctl.conf) – klanomath Apr 6 '18 at 16:46
  • @Allan /Users/admin/scripts/sysctl.sh is the whole path? – Jack Westmore Apr 6 '18 at 16:51
  • 2
    To see whats happening, append the following to each sysctl command - 2>&1 >> /Users/admin/myscript.log So, your command should be /usr/bin/sysctl net.smb.fs.kern_deadtimer=0 2>&1 >> /Users/admin/myscript.log This way, you can see what message and error message are being generated, if any. – Allan Apr 6 '18 at 17:10
  • 1
    *.deadtimer are all "sysctl: unknown oid *.deadtimer" in my High Sierra environment. IE they don't exist! – klanomath Apr 6 '18 at 17:40
4

It's probably best to ditch the script approach and use the settings file designed for this purpose: sysctl.conf

This applies up to macOS 10.12 Sierra.
as @klanomath pointed out in comments: " *.deadtimer are all "sysctl: unknown oid *.deadtimer" in my High Sierra environment. IE they don't exist!"
So it looks like that part of the sysctl interface is completely gone now.

sudo nano  /private/etc/sysctl.conf

add the following variables:

net.smb.fs.kern_deadtimer=0
net.smb.fs.kern_hard_deadtimer=0
net.smb.fs.kern_soft_deadtimer=0

If you afterwards boot in verbose mode (cmd+v on startup or sudo nvram boot-args="-v" before a reboot), you should see the custom settings being applied.

You should then see on boot messages like these:

net.smb.fs.kern_deadtimer: 60 -> 0
net.smb.fs.kern_hard_deadtimer: 600 -> 0
net.smb.fs.kern_soft_deadtimer: 30 -> 0

Otherwise check with

sysctl -a | grep smb

This approach should work for most settings that are accessible via sysctl and thus be as generalised as the question title implies.

  • In the comments, the OP said they tried this method and it didn't work. – Allan Apr 6 '18 at 17:37
  • The whole net.smb.* tree vanished. So I would rather write "the kernel states are gone" than "that part of the sysctl interface is completely gone" ;-) – klanomath Apr 6 '18 at 22:05
  • I'm testing on machines running macOS Sierra and High Sierra. Running sysctl -a | grep smb returns the same output. So I'm not sure it's correct to assert that "the sysctl interface is completely gone now". In my testing I noticed that all references to smb* disappeared AFTER I started making changes to /etc/sysctl.conf and rebooted. However the same settings would reappear as soon as I opened an smb connection... – Jack Westmore Apr 7 '18 at 14:51
  • Indeed, I believe that the reason creating/editing /etc/private/sysctl.conf does not work is because the smb service does not start until you initiate an smb connection (I believe...). – Jack Westmore Apr 7 '18 at 15:01
0

I found another way to do this in the end.

The trick was to set a longer default timeout value in /etc/nsmb.conf like so:

[default]
max_resp_timeout=1000     # default is 30 which way too low!

Thanks everyone for all your help :-)

You must log in to answer this question.

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