runqemu-export-rootfs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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`
  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$POKY_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/var/pseudo"
  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. ## For debugging you would additionally add
  75. ## --debug all
  76. MOUNTD_OPTS="--allow-non-root --mount-pid $MOUNTPID -f $EXPORTS --rmtab $RMTAB --prog $NFS_MOUNTPROG -r"
  77. NFSD_OPTS="--allow-non-root --nfs-pid $NFSPID -f $EXPORTS --prog $NFS_NFSPROG -P $NFS_PORT -r"
  78. # Setup the exports file
  79. if [ "$1" = "start" ]; then
  80. echo "Creating exports file..."
  81. echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS
  82. fi
  83. # See how we were called.
  84. case "$1" in
  85. start)
  86. echo "Starting User Mode rpc.mountd"
  87. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd $MOUNTD_OPTS"
  88. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.mountd $MOUNTD_OPTS
  89. if [ ! $? = 0 ]; then
  90. echo "====================="
  91. echo "Error starting MOUNTD"
  92. echo "====================="
  93. ps -ef | grep -v grep | grep rpcbind 2>&1 > /dev/null
  94. if [ $? = 0 ] ; then
  95. echo " If you see an error above that says:"
  96. echo " RPC: Authentication error; why = Client credential too weak"
  97. echo " You need to change the startup of rpcbind"
  98. echo " on your host by doing the following as root:"
  99. echo "==============================================="
  100. echo " According to /etc/sysconfig/rpcbind, then "
  101. echo " echo RPCBIND_ARGS=-i >> /etc/sysconfig/rpcbind"
  102. echo " or"
  103. echo " echo RPCBIND_OPTIONS=-i >> /etc/sysconfig/rpcbind"
  104. echo " /etc/init.d/rpcbind restart"
  105. echo "==============================================="
  106. fi
  107. exit 1
  108. fi
  109. echo "Starting User Mode nfsd"
  110. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.nfsd $NFSD_OPTS"
  111. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/sbin/rpc.nfsd $NFSD_OPTS
  112. if [ ! $? = 0 ]; then
  113. echo "Error starting nfsd"
  114. exit 1
  115. fi
  116. # Check to make sure everything started ok.
  117. if [ ! -f $MOUNTPID ]; then
  118. echo "rpc.mountd did not start correctly"
  119. exit 1
  120. fi
  121. if [ ! -f $NFSPID ]; then
  122. echo "rpc.nfsd did not start correctly"
  123. exit 1
  124. fi
  125. ps -fp `cat $MOUNTPID` > /dev/null 2> /dev/null
  126. if [ ! $? = 0 ]; then
  127. echo "rpc.mountd did not start correctly"
  128. exit 1
  129. fi
  130. ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
  131. if [ ! $? = 0 ]; then
  132. echo "rpc.nfsd did not start correctly"
  133. exit 1
  134. fi
  135. echo " "
  136. echo "On your target please remember to add the following options for NFS"
  137. echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=2,mountprog=$NFS_MOUNTPROG,nfsprog=$NFS_NFSPROG,udp"
  138. ;;
  139. stop)
  140. if [ -f "$MOUNTPID" ]; then
  141. echo "Stopping rpc.mountd"
  142. kill `cat $MOUNTPID`
  143. rm -f $MOUNTPID
  144. else
  145. echo "No PID file, not stopping rpc.mountd"
  146. fi
  147. if [ -f "$NFSPID" ]; then
  148. echo "Stopping rpc.nfsd"
  149. kill `cat $NFSPID`
  150. rm -f $NFSPID
  151. else
  152. echo "No PID file, not stopping rpc.nfsd"
  153. fi
  154. if [ -f "$EXPORTS" ]; then
  155. echo "Removing exports file"
  156. rm -f $EXPORTS
  157. fi
  158. ;;
  159. restart)
  160. $0 stop $NFS_EXPORT_DIR
  161. $0 start $NFS_EXPORT_DIR
  162. if [ ! $? = 0 ]; then
  163. exit 1
  164. fi
  165. ;;
  166. *)
  167. echo "$0 {start|stop|restart} <nfs-export-dir>"
  168. ;;
  169. esac
  170. exit 0