blob: 7ebc07194d29ed3ed74b2f7f425e524318ad7c8d [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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 oe-find-native-sysroot 2> /dev/null`
42if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
43 echo "Error: Unable to find the oe-find-native-sysroot script"
44 echo "Did you forget to source your build environment setup script?"
45 exit 1
46fi
47. $SYSROOT_SETUP_SCRIPT
48
Patrick Williamsf1e5d692016-03-30 15:21:19 -050049if [ ! -e "$OECORE_NATIVE_SYSROOT/usr/bin/unfsd" ]; then
50 echo "Error: Unable to find unfsd binary in $OECORE_NATIVE_SYSROOT/usr/bin/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051
52 if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
53 echo "Have you run 'bitbake meta-ide-support'?"
54 else
55 echo "This shouldn't happen - something is missing from your toolchain installation"
56 fi
57 exit 1
58fi
59
60if [ ! -d ~/.runqemu-sdk ]; then
61 mkdir -p ~/.runqemu-sdk
62fi
63
64NFS_INSTANCE=${NFS_INSTANCE:=0}
65EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE
66RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE
67NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid
68MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid
69
70PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
71PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state"
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 runqemu-extract-sdk?"
77 exit 1
78fi
79
80# rpc.mountd RPC port
Brad Bishop37a0e4d2017-12-04 01:01:44 -050081MOUNTD_RPCPORT=${MOUNTD_RPCPORT:=$[ 21111 + $NFS_INSTANCE ]}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082# rpc.nfsd RPC port
Brad Bishop37a0e4d2017-12-04 01:01:44 -050083NFSD_RPCPORT=${NFSD_RPCPORT:=$[ 11111 + $NFS_INSTANCE ]}
84# NFS server port number
85NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086# mountd port number
Brad Bishop37a0e4d2017-12-04 01:01:44 -050087MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088
89## For debugging you would additionally add
90## --debug all
Brad Bishop37a0e4d2017-12-04 01:01:44 -050091UNFSD_OPTS="-p -N -i $NFSPID -e $EXPORTS -x $NFSD_RPCPORT -n $NFSD_PORT -y $MOUNTD_RPCPORT -m $MOUNTD_PORT"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092
93# See how we were called.
94case "$1" in
95 start)
96 PORTMAP_RUNNING=`ps -ef | grep portmap | grep -v grep`
97 RPCBIND_RUNNING=`ps -ef | grep rpcbind | grep -v grep`
98 if [[ "x$PORTMAP_RUNNING" = "x" && "x$RPCBIND_RUNNING" = "x" ]]; then
99 echo "======================================================="
100 echo "Error: neither rpcbind nor portmap appear to be running"
101 echo "Please install and start one of these services first"
102 echo "======================================================="
103 echo "Tip: for recent Ubuntu hosts, run:"
104 echo " sudo apt-get install rpcbind"
105 echo "Then add OPTIONS=\"-i -w\" to /etc/default/rpcbind and run"
106 echo " sudo service portmap restart"
107
108 exit 1
109 fi
110
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500111 echo "Creating exports file..."
112 echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS
113
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 echo "Starting User Mode nfsd"
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500115 echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
116 $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117 if [ ! $? = 0 ]; then
118 echo "Error starting nfsd"
119 exit 1
120 fi
121 # Check to make sure everything started ok.
122 if [ ! -f $NFSPID ]; then
123 echo "rpc.nfsd did not start correctly"
124 exit 1
125 fi
126 ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
127 if [ ! $? = 0 ]; then
128 echo "rpc.nfsd did not start correctly"
129 exit 1
130 fi
131 echo " "
132 echo "On your target please remember to add the following options for NFS"
133 echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=3,port=$NFSD_PORT,mountprog=$MOUNTD_RPCPORT,nfsprog=$NFSD_RPCPORT,udp,mountport=$MOUNTD_PORT"
134 ;;
135 stop)
136 if [ -f "$NFSPID" ]; then
137 echo "Stopping rpc.nfsd"
138 kill `cat $NFSPID`
139 rm -f $NFSPID
140 else
141 echo "No PID file, not stopping rpc.nfsd"
142 fi
143 if [ -f "$EXPORTS" ]; then
144 echo "Removing exports file"
145 rm -f $EXPORTS
146 fi
147 ;;
148 restart)
149 $0 stop $NFS_EXPORT_DIR
150 $0 start $NFS_EXPORT_DIR
151 if [ ! $? = 0 ]; then
152 exit 1
153 fi
154 ;;
155 *)
156 echo "$0 {start|stop|restart} <nfs-export-dir>"
157 ;;
158esac
159
160exit 0