umount_img 709 B

123456789101112131415161718192021222324252627282930313233
  1. #/bin/sh
  2. #
  3. # Copyright (C) 2015-2016 ilbers GmbH
  4. #
  5. # Calls sudo from within the script, since ISARROOT is dropped from PATH if
  6. # the script is called with sudo.
  7. set -e
  8. dir=rootfs
  9. if [ -n "$1" ]; then
  10. dev=/dev/nbd$1p2
  11. else
  12. case `mount |grep "^/dev/nbd.* on \`pwd\`/$dir type " |wc -l` in
  13. 0)
  14. echo "$0: ERROR: Couldn't find mounted nbd device" >&2
  15. exit 2
  16. ;;
  17. 1)
  18. line=`mount |grep "^/dev/nbd.* on \`pwd\`/$dir type "`
  19. dev=`echo $line |sed 's,^\(/dev/nbd[^ ]*\) .*$,\1,'`
  20. d=`echo $line |sed 's,^/dev/nbd[^ ]* on \(.*\) type .*$,\1,'`
  21. ;;
  22. *)
  23. echo "$0: ERROR: Found too many nbd devices" >&2
  24. exit 2
  25. ;;
  26. esac
  27. fi
  28. sudo umount $dev
  29. sudo qemu-nbd -d $dev