runqemu-export-rootfs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. usage() {
  18. echo "Usage: $0 {start|stop|restart} <nfs-export-dir>"
  19. }
  20. if [ $# != 2 ]; then
  21. usage
  22. exit 1
  23. fi
  24. if [[ "$1" != "start" && "$1" != "stop" && "$1" != "restart" ]]; then
  25. echo "Unknown command '$1'"
  26. usage
  27. exit 1
  28. fi
  29. if [ ! -d "$2" ]; then
  30. echo "Error: '$2' does not exist"
  31. usage
  32. exit 1
  33. fi
  34. # Ensure the nfs-export-dir is an absolute path
  35. NFS_EXPORT_DIR=$(cd "$2" && pwd)
  36. SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
  37. if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
  38. echo "Error: Unable to find the oe-find-native-sysroot script"
  39. echo "Did you forget to source your build environment setup script?"
  40. exit 1
  41. fi
  42. . $SYSROOT_SETUP_SCRIPT
  43. if [ ! -e "$OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd" ]; then
  44. echo "Error: Unable to find rpc.mountd binary in $OECORE_NATIVE_SYSROOT/usr/sbin/"
  45. if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
  46. echo "Have you run 'bitbake meta-ide-support'?"
  47. else
  48. echo "This shouldn't happen - something is missing from your toolchain installation"
  49. fi
  50. exit 1
  51. fi
  52. if [ ! -d ~/.runqemu-sdk ]; then
  53. mkdir -p ~/.runqemu-sdk
  54. fi
  55. NFS_INSTANCE=${NFS_INSTANCE:=0}
  56. EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE
  57. RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE
  58. NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid
  59. MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid
  60. PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
  61. PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state"
  62. export PSEUDO_LOCALSTATEDIR
  63. if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
  64. echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
  65. echo "Did you create the export directory using runqemu-extract-sdk?"
  66. exit 1
  67. fi
  68. # rpc.mountd RPC port
  69. NFS_MOUNTPROG=$[ 21111 + $NFS_INSTANCE ]
  70. # rpc.nfsd RPC port
  71. NFS_NFSPROG=$[ 11111 + $NFS_INSTANCE ]
  72. # NFS port number
  73. NFS_PORT=$[ 3049 + $NFS_INSTANCE ]
  74. # mountd port number
  75. MOUNT_PORT=$[ 3048 + $NFS_INSTANCE ]
  76. ## For debugging you would additionally add
  77. ## --debug all
  78. MOUNTD_OPTS="--allow-non-root --mount-pid $MOUNTPID -f $EXPORTS --rmtab $RMTAB --prog $NFS_MOUNTPROG -r -P $MOUNT_PORT"
  79. NFSD_OPTS="--allow-non-root --nfs-pid $NFSPID -f $EXPORTS --prog $NFS_NFSPROG -P $NFS_PORT -r"
  80. # Setup the exports file
  81. if [ "$1" = "start" ]; then
  82. echo "Creating exports file..."
  83. echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS
  84. fi
  85. # See how we were called.
  86. case "$1" in
  87. start)
  88. PORTMAP_RUNNING=`ps -ef | grep portmap | grep -v grep`
  89. RPCBIND_RUNNING=`ps -ef | grep rpcbind | grep -v grep`
  90. if [[ "x$PORTMAP_RUNNING" = "x" && "x$RPCBIND_RUNNING" = "x" ]]; then
  91. echo "======================================================="
  92. echo "Error: neither rpcbind nor portmap appear to be running"
  93. echo "Please install and start one of these services first"
  94. echo "======================================================="
  95. echo "Tip: for recent Ubuntu hosts, run:"
  96. echo " sudo apt-get install rpcbind"
  97. echo "Then add OPTIONS=\"-i -w\" to /etc/default/rpcbind and run"
  98. echo " sudo service portmap restart"
  99. exit 1
  100. fi
  101. echo "Starting User Mode rpc.mountd"
  102. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd $MOUNTD_OPTS"
  103. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd $MOUNTD_OPTS
  104. if [ ! $? = 0 ]; then
  105. echo "====================="
  106. echo "Error starting MOUNTD"
  107. echo "====================="
  108. if [ ! "x$RPCBIND_RUNNING" = "x" ] ; then
  109. echo " If you see an error above that says:"
  110. echo " RPC: Authentication error; why = Client credential too weak"
  111. echo " You need to add the -i option when running rpcbind"
  112. echo "==============================================="
  113. echo "For recent Fedora/RedHat hosts:"
  114. echo "Add RPCBIND_ARGS=-i to /etc/sysconfig/rpcbind"
  115. echo " or"
  116. echo "Add RPCBIND_OPTIONS=-i to /etc/sysconfig/rpcbind"
  117. echo "Then run as root: /etc/init.d/rpcbind restart"
  118. echo "==============================================="
  119. echo "For recent Debian/Ubuntu hosts:"
  120. echo "Add OPTIONS=\"-i -w\" to /etc/default/rpcbind"
  121. echo "sudo service portmap restart"
  122. fi
  123. exit 1
  124. fi
  125. echo "Starting User Mode nfsd"
  126. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.nfsd $NFSD_OPTS"
  127. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/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. if [ -f "$EXPORTS" ]; then
  171. echo "Removing exports file"
  172. rm -f $EXPORTS
  173. fi
  174. ;;
  175. restart)
  176. $0 stop $NFS_EXPORT_DIR
  177. $0 start $NFS_EXPORT_DIR
  178. if [ ! $? = 0 ]; then
  179. exit 1
  180. fi
  181. ;;
  182. *)
  183. echo "$0 {start|stop|restart} <nfs-export-dir>"
  184. ;;
  185. esac
  186. exit 0