runqemu-export-rootfs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 qemu-helper-native
  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. echo "This shouldn't happen - something is missing from your toolchain installation"
  36. exit 1
  37. fi
  38. if [ ! -d ~/.runqemu-sdk ]; then
  39. mkdir -p ~/.runqemu-sdk
  40. fi
  41. NFS_INSTANCE=${NFS_INSTANCE:=0}
  42. EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE
  43. RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE
  44. NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid
  45. MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid
  46. PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
  47. PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state"
  48. export PSEUDO_LOCALSTATEDIR
  49. if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
  50. echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
  51. echo "Did you create the export directory using runqemu-extract-sdk?"
  52. exit 1
  53. fi
  54. # NFS server port number
  55. NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]}
  56. # mountd port number
  57. MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]}
  58. ## For debugging you would additionally add
  59. ## --debug all
  60. UNFSD_OPTS="-p -i $NFSPID -e $EXPORTS -n $NFSD_PORT -m $MOUNTD_PORT"
  61. # See how we were called.
  62. case "$1" in
  63. start)
  64. echo "Creating exports file..."
  65. echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS
  66. echo "Starting User Mode nfsd"
  67. echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
  68. $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS
  69. if [ ! $? = 0 ]; then
  70. echo "Error starting nfsd"
  71. exit 1
  72. fi
  73. # Check to make sure everything started ok.
  74. if [ ! -f $NFSPID ]; then
  75. echo "rpc.nfsd did not start correctly"
  76. exit 1
  77. fi
  78. ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
  79. if [ ! $? = 0 ]; then
  80. echo "rpc.nfsd did not start correctly"
  81. exit 1
  82. fi
  83. echo " "
  84. echo "On your target please remember to add the following options for NFS"
  85. echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=3,port=$NFSD_PORT,udp,mountport=$MOUNTD_PORT"
  86. ;;
  87. stop)
  88. if [ -f "$NFSPID" ]; then
  89. echo "Stopping rpc.nfsd"
  90. kill `cat $NFSPID`
  91. rm -f $NFSPID
  92. else
  93. echo "No PID file, not stopping rpc.nfsd"
  94. fi
  95. if [ -f "$EXPORTS" ]; then
  96. echo "Removing exports file"
  97. rm -f $EXPORTS
  98. fi
  99. ;;
  100. restart)
  101. $0 stop $NFS_EXPORT_DIR
  102. $0 start $NFS_EXPORT_DIR
  103. if [ ! $? = 0 ]; then
  104. exit 1
  105. fi
  106. ;;
  107. *)
  108. echo "$0 {start|stop|restart} <nfs-export-dir>"
  109. ;;
  110. esac
  111. exit 0