summaryrefslogtreecommitdiffstats
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)
downloadpoky-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 @@
1#!/bin/bash
2#
3# Copyright (c) 2005-2009 Wind River Systems, Inc.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12# See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18usage() {
19 echo "Usage: $0 {start|stop|restart} <nfs-export-dir>"
20}
21
22if [ $# != 2 ]; then
23 usage
24 exit 1
25fi
26
27if [[ "$1" != "start" && "$1" != "stop" && "$1" != "restart" ]]; then
28 echo "Unknown command '$1'"
29 usage
30 exit 1
31fi
32
33if [ ! -d "$2" ]; then
34 echo "Error: '$2' does not exist"
35 usage
36 exit 1
37fi
38# Ensure the nfs-export-dir is an absolute path
39NFS_EXPORT_DIR=$(cd "$2" && pwd)
40
41SYSROOT_SETUP_SCRIPT=`which poky-find-native-sysroot`
42if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
43 echo "Error: Unable to find the poky-find-native-sysroot script"
44 echo "Did you forget to source your Poky environment script?"
45 exit 1
46fi
47. $SYSROOT_SETUP_SCRIPT
48
49if [ ! -e "$NATIVE_SYSROOT_DIR/usr/sbin/rpc.mountd" ]; then
50 echo "Error: Unable to find rpc.mountd binary in $NATIVE_SYSROOT_DIR/usr/sbin/"
51
52 if [ "$SYSROOT_MODE" = "in-tree" ]; then
53 echo "Have you run 'bitbake unfs-server-native'?"
54 else
55 echo "This shouldn't happen - something is missing from your toolchain installation"
56 fi
57 exit 1
58fi
59
60if [ ! -d ~/.poky-sdk ]; then
61 mkdir -p ~/.poky-sdk
62fi
63
64TARGET_VIRT_INSTANCE=${TARGET_VIRT_INSTANCE:=0}
65EXPORTS=~/.poky-sdk/exports$TARGET_VIRT_INSTANCE
66RMTAB=~/.poky-sdk/rmtab$TARGET_VIRT_INSTANCE
67NFSPID=~/.poky-sdk/nfs$TARGET_VIRT_INSTANCE.pid
68MOUNTPID=~/.poky-sdk/mount$TARGET_VIRT_INSTANCE.pid
69
70PSEUDO_OPTS="-P $NATIVE_SYSROOT_DIR/usr"
71PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/var/pseudo"
72export PSEUDO_LOCALSTATEDIR
73
74if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
75 echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
76 echo "Did you create the export directory using poky-extract-sdk?"
77 exit 1
78fi
79
80# rpc.mountd RPC port
81NFS_MOUNTPROG="21111"
82# rpc.nfsd RPC port
83NFS_NFSPROG="11111"
84# NFS port number
85NFS_PORT="3049"
86
87## For debugging you would additionally add
88## --debug all
89
90MOUNTD_OPTS="--allow-non-root --mount-pid $MOUNTPID -f $EXPORTS --rmtab $RMTAB --prog $NFS_MOUNTPROG -r"
91NFSD_OPTS="--allow-non-root --nfs-pid $NFSPID -f $EXPORTS --prog $NFS_NFSPROG -P $NFS_PORT -r"
92
93# Setup the exports file
94if [ "$1" = "start" ]; then
95 echo "Creating exports file..."
96 echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS
97fi
98
99# See how we were called.
100case "$1" in
101 start)
102 echo "Starting User Mode rpc.mountd"
103 echo " $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.mountd $MOUNTD_OPTS"
104 $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.mountd $MOUNTD_OPTS
105 if [ ! $? = 0 ] ; then
106 echo "====================="
107 echo "Error starting MOUNTD"
108 echo "====================="
109 ps -ef | grep -v grep | grep rpcbind 2>&1 > /dev/null
110 if [ $? = 0 ] ; then
111 echo " If you see an error above that says:"
112 echo " RPC: Authentication error; why = Client credential too weak"
113 echo " You need to change the startup of rpcbind"
114 echo " on your host by doing the following as root:"
115 echo "==============================================="
116 echo " According to /etc/sysconfig/rpcbind, then "
117 echo " echo RPCBIND_ARGS=-i >> /etc/sysconfig/rpcbind"
118 echo " or"
119 echo " echo RPCBIND_OPTIONS=-i >> /etc/sysconfig/rpcbind"
120 echo " /etc/init.d/rpcbind restart"
121 echo "==============================================="
122 fi
123 exit 1
124 fi
125 echo "Starting User Mode nfsd"
126 echo " $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.nfsd $NFSD_OPTS"
127 $PSEUDO $PSEUDO_OPTS $NATIVE_SYSROOT_DIR/usr/sbin/rpc.nfsd $NFSD_OPTS
128 if [ ! $? = 0 ] ; then
129 echo "Error starting nfsd"
130 exit 1
131 fi
132 # Check to make sure everything started ok.
133 if [ ! -f $MOUNTPID ] ; then
134 echo "rpc.mountd did not start correctly"
135 exit 1
136 fi
137 if [ ! -f $NFSPID ] ; then
138 echo "rpc.nfsd did not start correctly"
139 exit 1
140 fi
141 ps -fp `cat $MOUNTPID` > /dev/null 2> /dev/null
142 if [ ! $? = 0 ] ; then
143 echo "rpc.mountd did not start correctly"
144 exit 1
145 fi
146 ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
147 if [ ! $? = 0 ] ; then
148 echo "rpc.nfsd did not start correctly"
149 exit 1
150 fi
151 echo " "
152 echo "On your target please remember to add the following options for NFS"
153 echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=2,mountprog=$NFS_MOUNTPROG,nfsprog=$NFS_NFSPROG,udp"
154 ;;
155 stop)
156 if [ -f "$MOUNTPID" ] ; then
157 echo "Stopping rpc.mountd"
158 kill `cat $MOUNTPID`
159 rm -f $MOUNTPID
160 else
161 echo "No PID file, not stopping rpc.mountd"
162 fi
163 if [ -f "$NFSPID" ] ; then
164 echo "Stopping rpc.nfsd"
165 kill `cat $NFSPID`
166 rm -f $NFSPID
167 else
168 echo "No PID file, not stopping rpc.nfsd"
169 fi
170 ;;
171 restart)
172 $0 stop $NFS_EXPORT_DIR
173 $0 start $NFS_EXPORT_DIR
174 if [ ! $? = 0 ] ; then
175 exit 1
176 fi
177 ;;
178 *)
179 echo "$0 {start|stop|restart} <nfs-export-dir>"
180 ;;
181esac
182
183exit 0