From: Greg Ercolano <erco@(email surpressed)> Subject: [OSX/Admin] How to create a custom boot script to mount a file server Date: Thu, 20 Mar 2008 15:23:30 -0400 |
Msg# 1710 View Complete Thread (2 articles) | All Threads Last Next |
Often it's useful to create your own boot scripts to statically mount your file server, instead of hacking commands into existing boot scripts (which might get overwritten by future software updates). Using your own static mount commands ensures creating mounts exactly where you want them, without weirdness from the automounter. Also, once the scripts are configured correctly and tested, you can just copy them around to the rest of the net easily. Plus, you can configure Rush to "Require" your script as a dependency, to ensure Rush doesn't start until your mount commands have successfully executed (preventing OSX from parallelizing the scripts on boot). Creating a custom boot script is fairly easy to do under OSX.. it just involves: 1) Creating a directory in /Library/StartupItems 2) Creating 2 files in that dir: a script and a plist file. 3) Modifying the "requires" line in the Rush "StarupParameters.plist" file HOW TO CREATE A CUSTOM STATIC MOUNT BOOT SCRIPT ----------------------------------------------- 1) As root, create a "MountFileServer" directory in /Library/StartupItems: mkdir -m 755 /Library/StartupItems/MountFileServer chown 0:0 /Library/StartupItems/MountFileServer 2) In that directory, create a bourne shell script called: /Library/StartupItems/MountFileServer/MountFileServer Note the filename is the same as the directory. Into that file, put: --- snip #!/bin/sh ### Set up local mounts for our file server if [ -x /etc/rc.common ]; then . /etc/rc.common; fi export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec if [ "`tty`" = "not a tty" ]; then LOGGER="logger -t MountFileServer" else LOGGER="logger -s -t MountFileServer" fi # HANDLE STOP/START ARG1=${1:-start} # assume 'start' if unset case "$ARG1" in stop) $LOGGER "Un-mounting /meade/net" ( umount /meade/net ) 2>&1 | $LOGGER ;; start) # ENSURE MOUNT POINT EXISTS if [ ! -d /meade/net ]; then $LOGGER "Creating /meade/net mount point" mkdir -p -m 755 /meade/net fi # ALREADY MOUNTED? DONT MOUNT TWICE if mount | grep -q /meade/net; then $LOGGER "/meade/net already mounted" else $LOGGER "Mounting /meade/net" ( mount -t nfs -o intr,bg 192.168.0.14:/net /meade/net ) 2>&1 | $LOGGER fi ;; restart) $0 stop $0 start ;; *) echo "usage: $0 {start|stop|restart}" exit 1 ;; esac exit 0 --- snip Don't include the "--- snip" lines in the script. 3) Make the following modifications to the above script: o Change all instances of "/meade/net" to the mount point you want to use. Be sure your mount point be BELOW the root directory, and not in the root itself, eg. "/jobs/stuff" and *not* just "/stuff". o Change the instance of "192.168.0.14:/net" to the IP of your file server, followed by a ":", and the directory on the server that you're trying to mount. The example shows an NFS mount, but you can change the mount command to be something else. NOTE: Use the IP address instead of the hostname for your file server in the mount command. At boot time DNS/NIS may not be fully operational, so avoid situations that can induce hostname lookups. 4) Create a "StartupParameters.plist" file in that dir, eg: vi /Library/StartupItems/MountFileServer/StartupParameters.plist ..with the following contents: ---- snip { Description = "Mounts the local file server"; Provides = ("MountFileServer"); Requires = ("Network", "System Log", "Resolver"); OrderPreference = "Last"; Messages = { start = "Mounting local file server"; stop = "Unmounting local file server"; }; } ---- snip 5) Configure the permissions: chown -R 0:0 /Library/StartupItems/MountFileServer/ chmod 755 /Library/StartupItems/MountFileServer/ chmod 755 /Library/StartupItems/MountFileServer/MountFileServer chmod 644 /Library/StartupItems/MountFileServer/StartupParameters.plist 6) Run the script manually to test that it mounts and umounts your file server correctly: /Library/StartupItems/MountFileServer/MountFileServer start /Library/StartupItems/MountFileServer/MountFileServer stop 7) Now configure Rush to start *after* your mount script. Edit the Rush boot file /Library/StartupItems/Rush/StartupParameters.plist: vi /Library/StartupItems/Rush/StartupParameters.plist ..then find the line that reads: Requires = ("Network", "System Log", "Resolver"); ..and add "MountFileServer" to the list, so that it now reads: Requires = ("Network", "System Log", "Resolver", "MountFileServer"); Be sure to include the extra comma, so that the syntax is consistent. 8) Now reboot to check your work. When you login, you should find your file server mounted, and rush started. Your /var/log/system.log should show mount messages from your script, and messages from Rush *following* those. To make this change to OTHER machines is easy: just copy the /Library/StartupItems/Rush and /Library/StartupItems/MountFileServer dirs to the other machines, making sure to preserve permissions, eg: scp -rp /Library/StartupItems/{Rush,MountFileServer} somehost:/Library/StartupItems/ That's it. CAVEATS ------- o The above has been tested on Tiger (10.4) and Leopard (10.5), and the technique follows Apple's rules for boot scripts. [Works with Snow Leopard (10.6) and Lion (10.7) as well. -erco 07/11/12] o Step #5 (setting permissions) is very important. OSX is very picky about all boot files being owned by root, and not writable to others. o When copy/pasting from the above, be sure your mail/news reader window is set wide enough, so that lines aren't wrapping, otherwise it may mess up the script's code. o It goes without saying, but don't include the "--- snip" lines when you paste. o If you decide to change the name of the MountFileServer script, be careful; the directory name must be the same as the script's. So make sure you follow through by replacing all instances of that name within both the script and plist files. SEE ALSO -------- If you want to make a boot script that creates /several/ mounts, you may want to use this more robust script instead: http://seriss.com/cgi-bin/rush/newsgroup-threaded.cgi?-view+1847+1847 |
From: Greg Ercolano <erco@(email surpressed)> Subject: Re: [OSX/Admin] How to create a custom boot script to mount a file Date: Thu, 15 May 2008 07:12:58 -0400 |
Msg# 1731 View Complete Thread (2 articles) | All Threads Last Next |
Greg Ercolano wrote: > 4) Create a "StartupParameters.plist" file in that dir, eg: > [..] > ---- snip > { > Description = "Mounts the local file server"; > Provides = ("MountLocalFileServer"); > Requires = ("Network", "System Log", "Resolver"); *** THE FOLLOWING IS FOR TIGER (10.4) AND OLDER *** THIS INFO DOES *NOT* APPLY TO LEOPARD (10.5) If you get errors in the /var/log/system.log like: NFS Portmap: RPC: Port mapper failure - RPC: Unable to send ..then edit your: /Library/StartupItems/MountLocalFileServer/StartupParameters.plist ..file, and change the "Requires" line to include "NFS", eg: BEFORE: Requires = ("Network", "System Log", "Resolver"); AFTER: Requires = ("Network", "System Log", "Resolver", "NFS"); ^^^^^ This way your boot script won't be started until the client side NFS daemons have been started. "NFS" is what the System's own 'NFS' startup script supplies when starting the NFS daemons, so it's probably a good thing to 'Require' if your system has an /System/Library/StartupItems/NFS directory. |