Novell Home

Automatically Mounting Remote NCP (NetWare) Shares on SUSE Linux System Boot

Novell Cool Solutions: Feature
By Kirk Coombs

Digg This - Slashdot This

Posted: 11 May 2005
 

The Problem:

Many users want to have remote NCP shares mounted on their SUSE Linux machine on system boot. The ncpmount (8) man page explains that to mount a NetWare share on system boot one simply needs to add the share to /etc/fstab. They do this, but the NCP shares are not mounted on system boot.

The Cause

The cause of this problem is simple: the system is attempting to mount the NCP shares prior to starting the networking. This obviously fails. After the system has boot, the user can execute mount -at ncpfs as root and have the shares mounted fine

The Solution

The most simple solution is to check whether the server hosting the NCP share supports Native File Access for SMB/CIFS. If so, the share can be mounted via Samba. Samba has scripts which mount the shares after networking has been started. These shares can be added to either /etc/fstab or /etc/samba/smbfstab.

If the NCP share does not have Native File Access, then the Samba scripts need to be duplicated and adapted to mount the NCP shares after networking has been brought up. Remember to install the ncpfs package from YaST, which allows for mounting NCP shares. Following is a modified version of the SUSE /etc/rc.d/smbfs script which will do the trick. Copy this script to /etc/rc.d/ncpfs, give it 754 permissions, and enable it using the YaST runlevel editor.

#! /bin/sh
#
# Based upon the smbfs script by
#   Thomas Fehr 1999-2001
#   Lars Mueller 2002-2004
#   Bjoern Jacke 2004
#
### BEGIN INIT INFO
# Provides:       ncpfs
# Required-Start: $network $syslog
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Import remote NCP (NetWare) file systems
### END INIT INFO

. /etc/rc.status
rc_reset

LC_ALL=en_US
NCPFS_STATE_FILE="/var/lock/subsys/ncpfs"
SLEEP=1
TIMEOUT=10

grep -q " \(ncpfs\) " /proc/mounts
test $? -eq 0 && ncpfs_used=yes || ncpfs_used=no

case "$1" in
   start)
      grep -q '^[[:space:]]*[^#].*[[:space:]]\(ncp\)[[:space:]]' /etc/fstab
      rc=$?
      if [ ${rc} -ne 0 ]; then  #Are there ncp mounts listed in /etc/fstab?
         echo -n >&2 "No type ncp active in /etc/fstab. "
         rc_status -s
         exit 6
      fi
      echo -n "Mount NCP File Systems "
      service_used="no"
      if [ ${rc} -eq 0 ]; then
         service_used="yes"
         timer=${TIMEOUT}
         JOBS="none"
         printdot=""
         while [ "${JOBS}" ] && [ ${timer} -gt 0 ]; do
            if [ -z "${printdot}" ]; then
               echo
               echo -n "from /etc/fstab "
               mount -at ncp,ncpfs >/dev/null &

               PID=$!
            fi
            test -e /proc/$PID || JOBS=""
            if [ "${JOBS}" ]; then
               timer=$[${timer}-1]
               echo -n "."
               sleep ${SLEEP}
               printdot="yes"
            fi
         done
         test "${printdot}" && echo -n " "
         if [ "${JOBS}" -a ${timer} -eq 0 ]; then
            echo -n >&2 " Error: timeout while mount. "
            rc_failed
         fi
         rc_status -v
      fi
      test "${service_used}" = "no" && rc_status -u
      touch ${NCPFS_STATE_FILE}
      ;;
   stop)
      echo -n "Umount NCP File Systems "
      if [ "${ncpfs_used}" = "yes" ]; then
         #
         # Unmount in background due to possible long timeouts
         #
         timer=${TIMEOUT}
         JOBS="none"
         printdot=""
         while [ "${JOBS}" ] && [ ${timer} -gt 0 ]; do
            if [ -z "${printdot}" ]; then
               umount -at ncp,ncpfs &
               PID=$!
            fi
            test -e /proc/$PID || JOBS=""
            if [ "${JOBS}" ]; then
               timer=$[${timer}-1]
               echo -n "."
               sleep ${SLEEP}
               printdot="yes"
            fi
         done
         test "${printdot}" && echo -n " "
         if [ "${JOBS}" -a ${timer} -eq 0 ]; then
            echo -n >&2 " Error: timeout while umount. "
            rc_failed
         fi
      fi
      rc_status -v
      ;;
   try-restart|condrestart)
      if test "$1" = "condrestart"; then
         echo "${attn} Use try-restart ${done}(LSB)${attn} \
rather than condrestart ${warn}(RH)${norm}"
      fi
      $0 status
      if test $? = 0; then
         $0 restart
      else 
         rc_reset
      fi
      rc_status
      ;;
   force-reload|restart)
      $0 stop
      $0 start
      rc_status
      ;;
   status)
      echo -n "Checking for mounted NCP File Systems "
      if [ "${ncpfs_used}" = "yes" ]; then
         mount -t ncp,ncpfs | while read service on mountpoint \
type vfstype rest; do
            echo
            echo -n "${service} on ${mountpoint} type ${vfstype} "
         done
      else
         rc_failed 3
      fi
      rc_status -v
      ;;
   *)
      echo "Usage: $0 {start|stop|status|force-reload|restart}"
      exit 1
      ;;
esac
rc_exit

Note: Although this script works with both ncp and ncpfs being used as file system types in /etc/fstab, the man page suggests using ncp only.

Now, the NCP shares listed in /etc/fstab will automatically be mounted on boot and unmounted when shutting down.

For an even cleaner solution, it is good to edit /etc/rc.d/boot.localfs so that it will not attempt to mount the NCP shares before the networking has started, or unmount them after networking has stopped. Change the following:

  1. Find the line:
    mount -av -t nonfs,noproc,nodevpts,nosmbfs -O no_netdev
    (it should be around line 139) and append noncpfs and noncp like this:
    mount -av -t nonfs,noproc,nodevpts,nosmbfs,noncpfs,noncp \ -O no_netdev
  2. Find the line:
    umount -avt noproc,nonfs,nosmbfs || {
    (it should be around line 176) and append noncpfs and noncp as well:
    umount -avt noproc,nonfs,nosmbfs,noncpfs,noncp || {
  3. Find the line:
    smbfs)  continue ;; # Avoid hanging reboot/halt
    (it should be around line 196) and add a couple of similar line after it, with NCPFS:
    smbfs)    continue ;; # Avoid hanging reboot/halt
    ncpfs)    continue ;; # Avoid hanging reboot/halt
    ncp)      continue ;; # Avoid hanging reboot/halt

Additional Information

This information is for those who don't know how to add NCP shares to /etc/fstab. The man page for ncpmount (8) explains how. There are many options, but the basic form is straightforward.

For example, to mount the volume SYS on the server MIRROR with the user DOWNLOAD and no password, add the following:

MIRROR/DOWNLOAD    /home/pub/mirror    ncp \
defaults,mode=644,uid=mirror,gid=mirror,owner=root,volume=SYS,\
nopasswd,multiple 0 0

Remember to change the UID and GID to the local user and group you want to own the files in the share. The owner= option specifies who will own the share itself (i.e. who will be able to unmount it). The multiple option should always be used to allow more than one connection to the server with the same name.

If you must connect over UDP, then you must also specify the DNS name for the server. Use the ipserver= option:

MIRROR/DOWNLOAD    /home/pub/mirror    ncp \
defaults,mode=644,uid=mirror,gid=mirror,owner=root,\
ipserver=dns.name.for.mirror,volume=SYS,\
nopasswd,multiple 0 0

If the user MIRROR requires a password, it is best to put the user name and password in a file readable by only root like this:

(/etc/fstab entry)

MIRROR/DOWNLOAD    /home/pub/mirror    ncp \
defaults,mode=644,uid=mirror,gid=mirror,owner=root,\
volume=SYS,passwdfile=/etc/ncppasswords,multiple

(/etc/ncppassword entry)

MIRROR/DOWNLOAD:PASSWORD:

Multiple servers/users can be specified, with one on each line.


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell