# # ssh_nfs_mnt: A ssh+nfs hack to mount nfs dirs on a PC (e.g. mobile laptop). # # Usage: # # ssh_nfs_mnt (mount the shares) # ssh_nfs_mnt -w (mount the shares and wait for ssh to finish) # ssh_nfs_mnt -u (unmount the shares) # # You can also specify any of the parameters described below on the cmd # line (after any -w or -u option), e.g.: # # ssh_nfs_mnt nfs_dirs=/home nfs_server=runge@hyades0.lbl.gov # # Notes: # # Since it does the local mounting, this script will run sudo(1) # when necessary. Hopefully your sudo(1) will only ask for the # password the first time (i.e. subsequent sudo's will not need # the password unless a timeout of 5 mins is reached). # # If you are not using an ssh-agent, you will need to type your # remote system password/passphrase twice (once for collecting # rpcinfo output and again for the actual port redir). # # If your userid number (run the "id" command to see what it is) # differs between the remote NFS server and the local machine # you may not be able to write and/or read the mounted files. # If possible try to make the number of the userid and groupid be # the same on both machines. Your mount(8) command may allow for # userid remapping. # # REMEMBER: before unmounting (via the -u option), you must cd # every shell out of the mounted areas and no application can have # any mounted file open. If you see 'device is busy' errors you # will know you forgot to do this. # # Except under -w wait mode, the ssh port redir command does a # 'sleep 60' so the mount performed by this script will have to # take place in that time period (note you may be prompted for a # password). Also, if you unmount (-u) quickly, you will have to # wait for the 'sleep 60' by the ssh to finish and the ports freed. # # For MacOS X (Darwin) you will need to make sure local servers nfs, # mountd, and portmap are NOT running before you run this script. # See the details below. If you find your nfs client OS is in # the same boat as MacOS X, specify uname=Darwin on the cmdline. # # For debugging output, use "-d" as the first argument. # # Only tested for Linux NFS servers. # Only tested for Linux NFS clients. # nfs_server="hyades0.lbl.gov" # user@hostname (passed to ssh) works also. # # nfs_server: this is used to ssh to the server machine. Note on Darwin # since the ssh must be run via sudo (for the low ports, portmapper 111, # etc) you may always need to supply the "user@" part and/or supply a # password (because ssh as root won't find your keys). If SSH_AUTH_SOCK # exists in the environment it will be used in the sudo. nfs_ip="10.0.0.220" # server IP relative to nfs_server. # # nfs_ip: Note localhost or 127.0.0.1 is another possibility here but # that probably requires an edit of /etc/exportfs on the nfs server # side to add 127.0.0.1 to a list, so it is likely better to use a real # network interface IP here. nfs_dirs="/opt/snf /home" # The remote shares to mount. # # nfs_dirs: A comma separated list is also acceptable (e.g. if you # specify the parmeter on the command line and want to avoid spaces). mountpoint="$HOME/hyades0" # Local directory to mount the shares in. #mountpoint="/tmp/hyades0" #mountpoint="/var/tmp/hyades0" # # Each share is a subdir of this directory, e.g. /tmp/hyades0/opt/snf # or $HOME/hyades0/opt/snf. Take your pick of the 3 suggestions above or # make your own. Note: the mountpoint dir should be on a local filesystem # (your $HOME may not be...). mount_opts="" # Supply any extra mount(8) opts here. # # You may want to use mount_opts for performance reasons, e.g. over # a high latency link. See your OS mount(8), mount_nfs(8), or nfs(5) # docs for more info. # # Consider: noatime, nodiratime, actimeo (or acregmin, acregmax, acdirmin, # acdirmax), timeo, retrans, rdirplus, etc. This example seems to give # an improvement: # # mount_opts=timeo=15,actimeo=300 # These are the default mount(8) options used, change them if you need to: # default_opts="tcp,nfsvers=3,rsize=8192,wsize=8192,intr,rw,nosuid" sleep=60 # Time of the initial sleep(1) in the # remote ssh cmd, e.g: ssh .... 'sleep 60' # (not used in wait mode -w). keepalive=30 # Period to send a "nfs ping" by running df(1). # (not used in wait mode -w). # keepalive: Some NFS clients will disconnect the TCP connection after, # say, 5 mins of inactivity. If the ssh initial sleep has finished # at that point the ssh connection will be closed. We are screwed at # that point because when NFS activity starts back up there is no ssh # TCP tunnel to the server for it to reconnect through. This option # tries to keep the link active by running df(1) frequently enough # (every keepalive seconds). Set to 0 to disable. # Port redirs for nfs and mountd port via ssh: # # port1 and port2 below are ssh redirection ports for nfs and mountd, # respectively. # # These are fixed local ports for now, but this could cause problems # with multiple instances of this script or hung redirs... # # You can use port1=NNNN, port2=MMMM on the command line to pick different # ones if you need to. # # On Darwin (MacOS X) NFS clients port1 and port2 below will be not # be used at all, the actual remote server ports will be used instead # (i.e. 2049 -> remote:2049). Of course this means those port numbers # and also portmap 111 may not be in use locally (i.e. you cannot run # the Darwin client as an NFS server at the same time). # port1=61001 # nfs redirection port (e.g. 61001 -> remote:2049) port2=61002 # mountd redirection port (e.g. 61002 -> remote:833) # Misc. commands: # ssh=ssh # you can override these too if you like. sudo=sudo #############################################################################