runqemu-export-rootfs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/bin/unfsd" ]; then
  44. echo "Error: Unable to find unfsd binary in $OECORE_NATIVE_SYSROOT/usr/bin/"
  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 + 2 * $NFS_INSTANCE ]
  74. # mountd port number
  75. MOUNT_PORT=$[ 3048 + 2 * $NFS_INSTANCE ]
  76. ## For debugging you would additionally add
  77. ## --debug all
  78. UNFSD_OPTS="-p -N -i $NFSPID -e $EXPORTS -x $NFS_NFSPROG -n $NFS_PORT -y $NFS_MOUNTPROG -m $MOUNT_PORT"
  79. # Setup the exports file
  80. if [ "$1" = "start" ]; then
  81. echo "Creating exports file..."
  82. echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS
  83. fi
  84. # See how we were called.
  85. case "$1" in
  86. start)
  87. PORTMAP_RUNNING=`ps -ef | grep portmap | grep -v grep`
  88. RPCBIND_RUNNING=`ps -ef | grep rpcbind | grep -v grep`
  89. if [[ "x$PORTMAP_RUNNING" = "x" && "x$RPCBIND_RUNNING" = "x" ]]; then
  90. echo "======================================================="
  91. echo "Error: neither rpcbind nor portmap appear to be running"
  92. echo "Please install and start one of these services first"
  93. echo "======================================================="
  94. echo "Tip: for recent Ubuntu hosts, run:"
  95. echo " sudo apt-get install rpcbind"
  96. echo "Then add OPTIONS=\"-i -w\" to /etc/default/rpcbind and run"
  97. echo " sudo service portmap restart"
  98. exit 1
  99. fi
  100. echo "Starting User Mode nfsd"
  101. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
  102. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS
  103. if [ ! $? = 0 ]; then
  104. echo "Error starting nfsd"
  105. exit 1
  106. fi
  107. # Check to make sure everything started ok.
  108. if [ ! -f $NFSPID ]; then
  109. echo "rpc.nfsd did not start correctly"
  110. exit 1
  111. fi
  112. ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
  113. if [ ! $? = 0 ]; then
  114. echo "rpc.nfsd did not start correctly"
  115. exit 1
  116. fi
  117. echo " "
  118. echo "On your target please remember to add the following options for NFS"
  119. echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=3,port=$NFSD_PORT,mountprog=$MOUNTD_RPCPORT,nfsprog=$NFSD_RPCPORT,udp,mountport=$MOUNTD_PORT"
  120. ;;
  121. stop)
  122. if [ -f "$NFSPID" ]; then
  123. echo "Stopping rpc.nfsd"
  124. kill `cat $NFSPID`
  125. rm -f $NFSPID
  126. else
  127. echo "No PID file, not stopping rpc.nfsd"
  128. fi
  129. if [ -f "$EXPORTS" ]; then
  130. echo "Removing exports file"
  131. rm -f $EXPORTS
  132. fi
  133. ;;
  134. restart)
  135. $0 stop $NFS_EXPORT_DIR
  136. $0 start $NFS_EXPORT_DIR
  137. if [ ! $? = 0 ]; then
  138. exit 1
  139. fi
  140. ;;
  141. *)
  142. echo "$0 {start|stop|restart} <nfs-export-dir>"
  143. ;;
  144. esac
  145. exit 0