runqemu-export-rootfs 4.4 KB

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