2010-08-13 18:26:49 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005-2009 Wind River Systems, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 {start|stop|restart} <nfs-export-dir>"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# != 2 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" != "start" && "$1" != "stop" && "$1" != "restart" ]]; then
|
|
|
|
echo "Unknown command '$1'"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$2" ]; then
|
|
|
|
echo "Error: '$2' does not exist"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# Ensure the nfs-export-dir is an absolute path
|
|
|
|
NFS_EXPORT_DIR=$(cd "$2" && pwd)
|
|
|
|
|
2011-09-01 21:04:48 +00:00
|
|
|
SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
|
2010-08-13 18:26:49 +00:00
|
|
|
if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "Error: Unable to find the oe-find-native-sysroot script"
|
|
|
|
echo "Did you forget to source your build environment setup script?"
|
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
. $SYSROOT_SETUP_SCRIPT
|
|
|
|
|
2011-04-20 16:55:16 +00:00
|
|
|
if [ ! -e "$OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd" ]; then
|
|
|
|
echo "Error: Unable to find rpc.mountd binary in $OECORE_NATIVE_SYSROOT/usr/sbin/"
|
2010-08-13 18:26:49 +00:00
|
|
|
|
2011-07-15 14:53:34 +00:00
|
|
|
if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "Have you run 'bitbake meta-ide-support'?"
|
2010-08-13 18:26:49 +00:00
|
|
|
else
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "This shouldn't happen - something is missing from your toolchain installation"
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-04-21 10:44:08 +00:00
|
|
|
if [ ! -d ~/.runqemu-sdk ]; then
|
|
|
|
mkdir -p ~/.runqemu-sdk
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
|
2010-10-04 04:16:24 +00:00
|
|
|
NFS_INSTANCE=${NFS_INSTANCE:=0}
|
2011-04-21 10:44:08 +00:00
|
|
|
EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE
|
|
|
|
RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE
|
|
|
|
NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid
|
|
|
|
MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid
|
2010-08-13 18:26:49 +00:00
|
|
|
|
2011-04-20 16:55:16 +00:00
|
|
|
PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
|
2012-08-27 18:32:30 +00:00
|
|
|
PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state"
|
2010-08-13 18:26:49 +00:00
|
|
|
export PSEUDO_LOCALSTATEDIR
|
|
|
|
|
|
|
|
if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
|
|
|
|
echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
|
2011-04-20 22:24:51 +00:00
|
|
|
echo "Did you create the export directory using runqemu-extract-sdk?"
|
2010-08-13 18:26:49 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# rpc.mountd RPC port
|
2010-10-04 04:16:24 +00:00
|
|
|
NFS_MOUNTPROG=$[ 21111 + $NFS_INSTANCE ]
|
2010-08-13 18:26:49 +00:00
|
|
|
# rpc.nfsd RPC port
|
2010-10-04 04:16:24 +00:00
|
|
|
NFS_NFSPROG=$[ 11111 + $NFS_INSTANCE ]
|
2010-08-13 18:26:49 +00:00
|
|
|
# NFS port number
|
2012-10-03 22:13:53 +00:00
|
|
|
NFS_PORT=$[ 3049 + 2 * $NFS_INSTANCE ]
|
2011-10-05 15:26:30 +00:00
|
|
|
# mountd port number
|
2012-10-03 22:13:53 +00:00
|
|
|
MOUNT_PORT=$[ 3048 + 2 * $NFS_INSTANCE ]
|
2010-08-13 18:26:49 +00:00
|
|
|
|
|
|
|
## For debugging you would additionally add
|
|
|
|
## --debug all
|
2011-10-05 15:26:30 +00:00
|
|
|
MOUNTD_OPTS="--allow-non-root --mount-pid $MOUNTPID -f $EXPORTS --rmtab $RMTAB --prog $NFS_MOUNTPROG -r -P $MOUNT_PORT"
|
2010-08-13 18:26:49 +00:00
|
|
|
NFSD_OPTS="--allow-non-root --nfs-pid $NFSPID -f $EXPORTS --prog $NFS_NFSPROG -P $NFS_PORT -r"
|
|
|
|
|
|
|
|
# Setup the exports file
|
|
|
|
if [ "$1" = "start" ]; then
|
|
|
|
echo "Creating exports file..."
|
|
|
|
echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS
|
|
|
|
fi
|
|
|
|
|
|
|
|
# See how we were called.
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2012-10-03 22:13:52 +00:00
|
|
|
PORTMAP_RUNNING=`ps -ef | grep portmap | grep -v grep`
|
|
|
|
RPCBIND_RUNNING=`ps -ef | grep rpcbind | grep -v grep`
|
|
|
|
if [[ "x$PORTMAP_RUNNING" = "x" && "x$RPCBIND_RUNNING" = "x" ]]; then
|
|
|
|
echo "======================================================="
|
|
|
|
echo "Error: neither rpcbind nor portmap appear to be running"
|
|
|
|
echo "Please install and start one of these services first"
|
|
|
|
echo "======================================================="
|
|
|
|
echo "Tip: for recent Ubuntu hosts, run:"
|
|
|
|
echo " sudo apt-get install rpcbind"
|
|
|
|
echo "Then add OPTIONS=\"-i -w\" to /etc/default/rpcbind and run"
|
|
|
|
echo " sudo service portmap restart"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-08-13 18:26:49 +00:00
|
|
|
echo "Starting User Mode rpc.mountd"
|
2011-04-20 16:55:16 +00:00
|
|
|
echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd $MOUNTD_OPTS"
|
|
|
|
$PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd $MOUNTD_OPTS
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ ! $? = 0 ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "====================="
|
|
|
|
echo "Error starting MOUNTD"
|
|
|
|
echo "====================="
|
2012-10-03 22:13:52 +00:00
|
|
|
if [ ! "x$RPCBIND_RUNNING" = "x" ] ; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo " If you see an error above that says:"
|
|
|
|
echo " RPC: Authentication error; why = Client credential too weak"
|
2012-10-03 22:13:52 +00:00
|
|
|
echo " You need to add the -i option when running rpcbind"
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "==============================================="
|
2012-10-03 22:13:52 +00:00
|
|
|
echo "For recent Fedora/RedHat hosts:"
|
|
|
|
echo "Add RPCBIND_ARGS=-i to /etc/sysconfig/rpcbind"
|
2012-10-03 22:13:51 +00:00
|
|
|
echo " or"
|
2012-10-03 22:13:52 +00:00
|
|
|
echo "Add RPCBIND_OPTIONS=-i to /etc/sysconfig/rpcbind"
|
|
|
|
echo "Then run as root: /etc/init.d/rpcbind restart"
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "==============================================="
|
2012-10-03 22:13:52 +00:00
|
|
|
echo "For recent Debian/Ubuntu hosts:"
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "Add OPTIONS=\"-i -w\" to /etc/default/rpcbind"
|
|
|
|
echo "sudo service portmap restart"
|
|
|
|
fi
|
2012-10-03 22:13:52 +00:00
|
|
|
|
2012-10-03 22:13:51 +00:00
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
2012-10-03 22:13:52 +00:00
|
|
|
|
2010-08-13 18:26:49 +00:00
|
|
|
echo "Starting User Mode nfsd"
|
2011-04-20 16:55:16 +00:00
|
|
|
echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.nfsd $NFSD_OPTS"
|
|
|
|
$PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.nfsd $NFSD_OPTS
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ ! $? = 0 ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "Error starting nfsd"
|
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
# Check to make sure everything started ok.
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ ! -f $MOUNTPID ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "rpc.mountd did not start correctly"
|
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ ! -f $NFSPID ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "rpc.nfsd did not start correctly"
|
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
ps -fp `cat $MOUNTPID` > /dev/null 2> /dev/null
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ ! $? = 0 ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "rpc.mountd did not start correctly"
|
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ ! $? = 0 ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "rpc.nfsd did not start correctly"
|
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
echo " "
|
|
|
|
echo "On your target please remember to add the following options for NFS"
|
|
|
|
echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=2,mountprog=$NFS_MOUNTPROG,nfsprog=$NFS_NFSPROG,udp"
|
|
|
|
;;
|
|
|
|
stop)
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ -f "$MOUNTPID" ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "Stopping rpc.mountd"
|
|
|
|
kill `cat $MOUNTPID`
|
|
|
|
rm -f $MOUNTPID
|
2010-08-13 18:26:49 +00:00
|
|
|
else
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "No PID file, not stopping rpc.mountd"
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ -f "$NFSPID" ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "Stopping rpc.nfsd"
|
|
|
|
kill `cat $NFSPID`
|
|
|
|
rm -f $NFSPID
|
2010-08-13 18:26:49 +00:00
|
|
|
else
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "No PID file, not stopping rpc.nfsd"
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ -f "$EXPORTS" ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
echo "Removing exports file"
|
|
|
|
rm -f $EXPORTS
|
2010-10-04 04:16:24 +00:00
|
|
|
fi
|
2010-08-13 18:26:49 +00:00
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
$0 stop $NFS_EXPORT_DIR
|
|
|
|
$0 start $NFS_EXPORT_DIR
|
2010-10-04 04:16:24 +00:00
|
|
|
if [ ! $? = 0 ]; then
|
2012-10-03 22:13:51 +00:00
|
|
|
exit 1
|
2010-08-13 18:26:49 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$0 {start|stop|restart} <nfs-export-dir>"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|