Advertisement
Ikem

mount.qcow

Mar 12th, 2013
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. IMAGE="$1"
  4. DISK="0"
  5. PARTITION="1"
  6. MOUNTPOINT="$2"
  7.  
  8. print_usage(){
  9.  
  10. echo "Usage: mount.qcow <IMAGE> <MOUNTPOINT>"
  11. }
  12.  
  13. if [ "$#" -eq "0" ] # if there is no parameter
  14. then
  15.   print_usage
  16. else
  17.   if [ $(id -u) -eq "0" ] # if the user is root
  18.   then
  19.     if file "$IMAGE"|grep -q "QEMU QCOW Image" && [ -d "$MOUNTPOINT" ] # if image is a qcow file and mountpoint is a directory
  20.     then
  21.       modprobe nbd max_part=16
  22.  
  23.       qemu-nbd -c /dev/nbd${DISK} "$IMAGE"
  24.  
  25.       mount /dev/nbd${DISK}p${PARTITION} "$MOUNTPOINT"
  26.     else
  27.       print_usage
  28.     fi
  29.   else
  30.     echo "mount.qcow: only root can do that"
  31.   fi
  32. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement