aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorScott Garman <scott.a.garman@intel.com>2010-08-13 11:26:49 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-08-20 16:20:11 +0100
commit313bda1d8781f625ff157dc7e6b5ba62f494077a (patch)
tree41db3ccbe6d0fb1a00bf953996fefb2a9b7c6a67 /scripts
parentc23da3d37e4d59322830ebee8a0f5ab919a9843b (diff)
downloadopenembedded-core-313bda1d8781f625ff157dc7e6b5ba62f494077a.tar.gz
poky-export-rootfs: script for exporting userspace nfsroots
This script automates the exporting of a root filesystem (created with the poky-extract-sdk utility) using pseudo and the native userspace NFS server. That filesystem can then be booted using nfsroot with either QEMU or the target hardware using one of our kernels. Signed-off-by: Scott Garman <scott.a.garman@intel.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/poky-export-rootfs183
1 files changed, 183 insertions, 0 deletions
diff --git a/scripts/poky-export-rootfs b/scripts/poky-export-rootfs
new file mode 100755
index 0000000000..fd9018a9e8
--- /dev/null
+++ b/scripts/poky-export-rootfs
@@ -0,0 +1,183 @@
+#!/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)
+
+SYSROOT_SETUP_SCRIPT=`which poky-find-native-sysroot`
+if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
+ echo "Error: Unable to find the poky-find-native-sysroot script"
+ echo "Did you forget to source your Poky environment script?"
+ exit 1
+fi
+. $SYSROOT_SETUP_SCRIPT
+
+if [ ! -e "$NATIVE_SYSROOT_DIR/usr/sbin/rpc.mountd" ]; then
+ echo "Error: Unable to find rpc.mountd binary in $NATIVE_SYSROOT_DIR/usr/sbin/"
+
+ if [ "$SYSROOT_MODE" = "in-tree" ]; then
+ echo "Have you run 'bitbake unfs-server-native'?"
+ else
+ echo "This shouldn't happen - something is missing from your toolchain installation"
+ fi
+ exit 1
+fi
+
+if [ ! -d ~/.poky-sdk ]; then
+ mkdir -p ~/.poky-sdk
+fi
+
+TARGET_VIRT_INSTANCE=${TARGET_VIRT_INSTANCE:=0}
+EXPORTS=~/.poky-sdk/exports$TARGET_VIRT_INSTANCE
+RMTAB=~/.poky-sdk/rmtab$TARGET_VIRT_INSTANCE
+NFSPID=~/.poky-sdk/nfs$TARGET_VIRT_INSTANCE.pid
+MOUNTPID=~/.poky-sdk/mount$TARGET_VIRT_INSTANCE.pid
+
+PSEUDO_OPTS="-P $NATIVE_SYSROOT_DIR/usr"
+PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/var/pseudo"
+export PSEUDO_LOCALSTATEDIR
+
+if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
+ echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
+ echo "Did you create the export directory using poky-extract-sdk?"
+ exit 1
+fi
+
+# rpc.mountd RPC port
+NFS_MOUNTPROG="21111"
+# rpc.nfsd RPC port
+NFS_NFSPROG="11111"
+# NFS port number
+NFS_PORT="3049"
+
+## For debugging you would additionally add
+## --debug all
+
+MOUNTD_OPTS="--allow-non-root --mount-pid $MOUNTPID -f $EXPORTS --rmtab $RMTAB --prog $NFS_MOUNTPROG -r"
+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)
+ echo "Starting User Mode rpc.mountd"
+ echo " $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.mountd $MOUNTD_OPTS"
+ $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.mountd $MOUNTD_OPTS
+ if [ ! $? = 0 ] ; then
+ echo "====================="
+ echo "Error starting MOUNTD"
+ echo "====================="
+ ps -ef | grep -v grep | grep rpcbind 2>&1 > /dev/null
+ if [ $? = 0 ] ; then
+ echo " If you see an error above that says:"
+ echo " RPC: Authentication error; why = Client credential too weak"
+ echo " You need to change the startup of rpcbind"
+ echo " on your host by doing the following as root:"
+ echo "==============================================="
+ echo " According to /etc/sysconfig/rpcbind, then "
+ echo " echo RPCBIND_ARGS=-i >> /etc/sysconfig/rpcbind"
+ echo " or"
+ echo " echo RPCBIND_OPTIONS=-i >> /etc/sysconfig/rpcbind"
+ echo " /etc/init.d/rpcbind restart"
+ echo "==============================================="
+ fi
+ exit 1
+ fi
+ echo "Starting User Mode nfsd"
+ echo " $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.nfsd $NFSD_OPTS"
+ $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.nfsd $NFSD_OPTS
+ if [ ! $? = 0 ] ; then
+ echo "Error starting nfsd"
+ exit 1
+ fi
+ # Check to make sure everything started ok.
+ if [ ! -f $MOUNTPID ] ; then
+ echo "rpc.mountd did not start correctly"
+ exit 1
+ fi
+ if [ ! -f $NFSPID ] ; then
+ echo "rpc.nfsd did not start correctly"
+ exit 1
+ fi
+ ps -fp `cat $MOUNTPID` > /dev/null 2> /dev/null
+ if [ ! $? = 0 ] ; then
+ echo "rpc.mountd did not start correctly"
+ exit 1
+ fi
+ ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
+ if [ ! $? = 0 ] ; then
+ echo "rpc.nfsd did not start correctly"
+ exit 1
+ 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)
+ if [ -f "$MOUNTPID" ] ; then
+ echo "Stopping rpc.mountd"
+ kill `cat $MOUNTPID`
+ rm -f $MOUNTPID
+ else
+ echo "No PID file, not stopping rpc.mountd"
+ fi
+ if [ -f "$NFSPID" ] ; then
+ echo "Stopping rpc.nfsd"
+ kill `cat $NFSPID`
+ rm -f $NFSPID
+ else
+ echo "No PID file, not stopping rpc.nfsd"
+ fi
+ ;;
+ restart)
+ $0 stop $NFS_EXPORT_DIR
+ $0 start $NFS_EXPORT_DIR
+ if [ ! $? = 0 ] ; then
+ exit 1
+ fi
+ ;;
+ *)
+ echo "$0 {start|stop|restart} <nfs-export-dir>"
+ ;;
+esac
+
+exit 0