July 01, 2012 Archives

01-07-2012 19:18

idmapd + autofs on OpenSuSe 12.1

I realised that the ID of files on NFSv4 mounts on my desktop (client) were the default nobody, 4294967294. In checking there was no idmapd running. Also I noted I had not even edited the /etc/idmapd.conf file to enter the local domain name. Did that but still, there was no idmapd init script to launch and executing idmapd would not start. I found out from some google searching that this is a commonly report problem, that is, idmap is started in the /etc/init.d/nfs script, but if you are mounting NFSv4 mounts (that need idmapd) with autofs, then this script won't be called. Calling it manually doesn't help as it aborts after not finding any NFS monts in /etc/fstab.

So I hacked up an idmapd using the nfs init script and tearing out everything besides the idmapd lines. I have not thoroughly tested it, so YMMV. ensure the file is named rpc.idmapd as this is important. Script is below:

cat /etc/init.d/rpc.idmapd
#! /bin/bash -x
# Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany.
# Copyright (c) 2008 SuSE LINUX Products GmbH, Nuernberg, Germany.
# All rights reserved.
#
# Author: Florian La Roche, 1996
#      Werner Fink , 1996,2008
#      Burchard Steinbild, 1996
#
# Please send feedback to http://www.suse.de/feedback
#
# /etc/init.d/nfs
#
### BEGIN INIT INFO
# Provides:       rpc.idmapd
# Required-Start: $network $portmap
# Required-Stop:  $network $portmap
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Short-Description: idmap Daemon 
# Description:    The NFSv4 idmap Dameon
### END INIT INFO

. /etc/rc.status
. /etc/sysconfig/nfs

# XXX: there should be separate init scripts for these really
IDMAPD_BIN=/usr/sbin/rpc.idmapd

IDMAPD_CLIENT_STATE=/var/run/nfs/nfs-rpc.idmapd
IDMAPD_SERVER_STATE=/var/run/nfs/nfsserver-rpc.idmapd

if [ -z "$RPC_PIPEFS_DIR" ]; then
    RPC_PIPEFS_DIR=/var/lib/nfs/rpc_pipefs
fi

NEED_IDMAPD=no
NEED_GSSD=no
NEED_LDCONFIG=no
state=0
usr=""
opt=""
mnt=""
nfs=$NFS_START_SERVICES
if [ "x$nfs" != "xyes" ]
then nfs=no
fi

if test "$NFS4_SUPPORT" = yes ; then
    NEED_IDMAPD=yes
fi
if grep -E '^(sunrpc|fs.nfs)' /etc/sysctl.conf > /dev/null 2>&1 ; then
    nfs=yes
fi

mount_rpc_pipefs() {
    # See if the file system is there yet
    case `stat -c "%t" -f "$RPC_PIPEFS_DIR"` in
    *67596969*)
        return 0;;
    esac
    mount -t rpc_pipefs rpc_pipefs "$RPC_PIPEFS_DIR"
}

umount_rpc_pipefs() {
    # See if the file system is there
    case `stat -c "%t" -f "$RPC_PIPEFS_DIR"` in
    *67596969*)
        umount "$RPC_PIPEFS_DIR"
    esac
}

do_start_idmapd() {
    mount_rpc_pipefs

    # as idmapd needs to be run by server and client
    # check if there is already a idmapd running
    if checkproc $IDMAPD_BIN && test -f $IDMAPD_SERVER_STATE; then
        killproc -HUP $IDMAPD_BIN
    else
        startproc $IDMAPD_BIN
        return $?
    fi
}

rc_reset

case "$1-$nfs" in
    start-no|reload-no)
        # Always run smnotify, even if no mounts are listed in fstab.
        # If there is nothing to do, it will exit quickly, and if there
        # is something to do, the sooner it is done, the better.
        /usr/sbin/sm-notify $SM_NOTIFY_OPTIONS
        echo -n "Not starting NFS client services - no NFS found in /etc/fstab:"
        rc_status -u
        ;;
    start-yes|force-start-*)
        echo -n "Starting NFS client services:"
        # start idmapd
        if test "$NEED_IDMAPD" = yes ; then
            echo -n " idmapd"
            do_start_idmapd || {
                rc_status -v
                rc_exit
            }
            [ -d /var/run/nfs ] || mkdir /var/run/nfs
            echo $IDMAPD_BIN > $IDMAPD_CLIENT_STATE
        fi

        rc_status -v
        #
        # generate new list of available shared libraries
        #
        if test "$NEED_LDCONFIG" = yes; then
            # check if ld.so.cache needs to be refreshed
            /etc/init.d/boot.ldconfig start
        fi
        #
        ;;
    stop* )
            # stop idmapd
            if test -f $IDMAPD_CLIENT_STATE; then
                # only stop idmapd if it is not needed by server
                if test ! -f $IDMAPD_SERVER_STATE ; then
                    echo -n " idmapd"
                    killproc $IDMAPD_BIN
                fi
                rm -f $IDMAPD_CLIENT_STATE
            fi 
            umount_rpc_pipefs

            rc_status -v
        ;;
    reload*|force-reload*)
        # only IDMAP has any sense in which 'reload' makes sense.
        if checkproc $IDMAPD_BIN; then
            killproc -HUP $IDMAPD_BIN
        fi
        rc_status
        ;;
    restart*)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 force-start
        rc_status
        ;;
    status*)
        # 
        if test "$NEED_IDMAPD" = yes && ! checkproc $IDMAPD_BIN; then
            echo "idmapd not running"
            rc_failed 3
        fi
        rc_status -v
        ;;
    try-restart*|condrestart*)
        # This restart is not only conditional on the services already
        # running, but is also gentler in that NFS filesystems are
        # not unmounted or remounted.
        # It is possible that the programs have been reinstalled so
        # we pass a basename rather than a full path to checkproc and killproc
        echo -n "Restarting NFS services:"
        if checkproc ${IDMAPD_BIN##*/}; then
            echo -n " idmapd"
            killproc ${IDMAPD_BIN##*/}
            startproc $IDMAPD_BIN
        fi
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|reload|force-reload|restart|try-restart}"
        exit 1
esac
rc_exit                                    

Posted by DaveQB | Permanent Link | Categories: IT