runqemu-export-rootfs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2005-2009 Wind River Systems, Inc.
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. #
  7. usage() {
  8. echo "Usage: $0 {start|stop|restart} <nfs-export-dir>"
  9. }
  10. if [ $# != 2 ]; then
  11. usage
  12. exit 1
  13. fi
  14. if [[ "$1" != "start" && "$1" != "stop" && "$1" != "restart" ]]; then
  15. echo "Unknown command '$1'"
  16. usage
  17. exit 1
  18. fi
  19. if [ ! -d "$2" ]; then
  20. echo "Error: '$2' does not exist"
  21. usage
  22. exit 1
  23. fi
  24. # Ensure the nfs-export-dir is an absolute path
  25. NFS_EXPORT_DIR=$(cd "$2" && pwd)
  26. SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
  27. if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
  28. echo "Error: Unable to find the oe-find-native-sysroot script"
  29. echo "Did you forget to source your build environment setup script?"
  30. exit 1
  31. fi
  32. . $SYSROOT_SETUP_SCRIPT meta-ide-support
  33. if [ ! -e "$OECORE_NATIVE_SYSROOT/usr/bin/unfsd" ]; then
  34. echo "Error: Unable to find unfsd binary in $OECORE_NATIVE_SYSROOT/usr/bin/"
  35. if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
  36. echo "Have you run 'bitbake meta-ide-support'?"
  37. else
  38. echo "This shouldn't happen - something is missing from your toolchain installation"
  39. fi
  40. exit 1
  41. fi
  42. if [ ! -d ~/.runqemu-sdk ]; then
  43. mkdir -p ~/.runqemu-sdk
  44. fi
  45. NFS_INSTANCE=${NFS_INSTANCE:=0}
  46. EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE
  47. RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE
  48. NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid
  49. MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid
  50. PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
  51. PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state"
  52. export PSEUDO_LOCALSTATEDIR
  53. if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
  54. echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
  55. echo "Did you create the export directory using runqemu-extract-sdk?"
  56. exit 1
  57. fi
  58. # NFS server port number
  59. NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]}
  60. # mountd port number
  61. MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]}
  62. ## For debugging you would additionally add
  63. ## --debug all
  64. UNFSD_OPTS="-p -N -i $NFSPID -e $EXPORTS -n $NFSD_PORT -m $MOUNTD_PORT"
  65. # See how we were called.
  66. case "$1" in
  67. start)
  68. PORTMAP_RUNNING=`ps -ef | grep portmap | grep -v grep`
  69. RPCBIND_RUNNING=`ps -ef | grep rpcbind | grep -v grep`
  70. if [[ "x$PORTMAP_RUNNING" = "x" && "x$RPCBIND_RUNNING" = "x" ]]; then
  71. echo "======================================================="
  72. echo "Error: neither rpcbind nor portmap appear to be running"
  73. echo "Please install and start one of these services first"
  74. echo "======================================================="
  75. echo "Tip: for recent Ubuntu hosts, run:"
  76. echo " sudo apt-get install rpcbind"
  77. echo "Then add OPTIONS=\"-i -w\" to /etc/default/rpcbind and run"
  78. echo " sudo service portmap restart"
  79. exit 1
  80. fi
  81. echo "Creating exports file..."
  82. echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS
  83. echo "Starting User Mode nfsd"
  84. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
  85. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS
  86. if [ ! $? = 0 ]; then
  87. echo "Error starting nfsd"
  88. exit 1
  89. fi
  90. # Check to make sure everything started ok.
  91. if [ ! -f $NFSPID ]; then
  92. echo "rpc.nfsd did not start correctly"
  93. exit 1
  94. fi
  95. ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
  96. if [ ! $? = 0 ]; then
  97. echo "rpc.nfsd did not start correctly"
  98. exit 1
  99. fi
  100. echo " "
  101. echo "On your target please remember to add the following options for NFS"
  102. echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=3,port=$NFSD_PORT,udp,mountport=$MOUNTD_PORT"
  103. ;;
  104. stop)
  105. if [ -f "$NFSPID" ]; then
  106. echo "Stopping rpc.nfsd"
  107. kill `cat $NFSPID`
  108. rm -f $NFSPID
  109. else
  110. echo "No PID file, not stopping rpc.nfsd"
  111. fi
  112. if [ -f "$EXPORTS" ]; then
  113. echo "Removing exports file"
  114. rm -f $EXPORTS
  115. fi
  116. ;;
  117. restart)
  118. $0 stop $NFS_EXPORT_DIR
  119. $0 start $NFS_EXPORT_DIR
  120. if [ ! $? = 0 ]; then
  121. exit 1
  122. fi
  123. ;;
  124. *)
  125. echo "$0 {start|stop|restart} <nfs-export-dir>"
  126. ;;
  127. esac
  128. exit 0