qemu-mount - Tools for mounting QEMU images

qemu-umount 686B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. #
  3. # umount qemu image file
  4. #
  5. prog=`basename $0`
  6. # use sudo for unprivileged users
  7. SUDO=
  8. [ "$(id -u)" -ne 0 ] && SUDO=sudo
  9. # check command line
  10. if [ $# -ne 1 -o "$1" = "-h" -o "$1" = "-?" ]; then
  11. cat << EOF >&2
  12. Unmount the qemu image file
  13. Usage: $prog <qemu_image or mount_point>
  14. EOF
  15. exit 1
  16. fi
  17. # argument
  18. mount="$1"
  19. full_mount=`readlink -f "$mount"`
  20. # get the nbd device
  21. nbd_path=`grep -l -F -x "$full_mount" /tmp/nbd*.mount 2> /dev/null`
  22. if [ -z "$nbd_path" ]; then
  23. echo "$prog: $mount not mounted"
  24. exit 1
  25. fi
  26. nbd=`basename "$nbd_path" .mount`
  27. # umount and detach
  28. sync
  29. $SUDO sh -c "umount '/dev/$nbd' && qemu-nbd -d '/dev/$nbd'" || exit $?
  30. rm -f "/tmp/${nbd}.mount"