If your Xsan volume isn’t mounting automatically

24 Nov 2021

We have seen some systems where our Xsan volume(s) do not mount consistently on restart.  We have seen this occasionally on both macOS Catalina and Big Sur.  After confirming that the fibre channel HBA driver is loaded, and seeing that manually running xsanctl mount <volumeName> works as expected, we can turn to launchd to make sure the volume mounts.

The simple check for the volume being mounted it to test for the existence of /Volumes/<volumeName>.  Then if it doesn’t exist, we can ask xsanctl to mount it.  For our example, our Mac is connect to 2 volumes, TestSan and TestBackup.

#!/bin/sh
if [ ! -e /Volumes/TestSan ]; then
xsanctl mount TestSan
fi
if [ ! -e /Volumes/TestBackup ]; then
xsanctl mount TestBackup
fi

We save this as a shell script, mountSan.sh (it can go a lot of places, we use /Library/Scripts/RSKGroup/), and make sure it is executable (chmod +x /Library/Scripts/RSKGroup/mountSan.sh).   

For an Xsan client system, we may only need to check for the volume mount when a user logs in.  For this use, we would use a LaunchAgent that runs once when a user logs in.  This file would be saved in /Library/LaunchDaemons/org.rskgroup.mountsan.plist so it applies to any user that logs in.

<?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>org.rskgroup.mountsan</string>
<key>Program</key>
<string>/Library/Scripts/RSKGroup/mountSan.sh</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

If instead this system is a file server and we want to make sure the volume is mounted no matter what, we can have launchd run the script every so many seconds (10 in this example) even when no one is logged in.  This would be saved in /Library/LaunchDaemons/org.rskgroup.mountsan.plist.

<?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.rskgroup.mountsan</string>
<key>Program</key>
<string>/Library/Scripts/RSKGroup/mountSan.sh</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>10</integer>
</dict>
</plist>

Then to tell launchd to run these scripts we load the plist file with launchctl.  For the LaunchAgent, use launchctl bootstrap gui/501 /Library/LaunchAgents/org.rskgroup.test.plist where 501 is the user’s UID number (id -u will give you your UID number).  For the LaunchDaemon, use sudo launchctl bootstrap system /Library/LaunchDaemons/org.rskgroup.mountsan.plist

Depending on which plist is now loaded, the Xsan volume should always be mounted when a user logs in, or any time it unmounts.

Share

Eric Hemmeter