kill existing image, mount all partitions
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 12 May 2009 15:52:05 +0000 (15:52 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 12 May 2009 15:52:05 +0000 (15:52 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@56 191e9f34-6774-4a6d-acfc-7664dacd4a2a

recepies/kvm/image-device.sh

index 0ef15cd..f88ae71 100755 (executable)
@@ -3,13 +3,21 @@
 test -e $1 || ( echo echo "Usage: $0 image.qcow2" ; exit 1 )
 
 image=$1
-path=$2
-running=`ps ax | grep nbd | grep -v grep | wc -l`
+
+test -e $image.pid && kill `cat $image.pid` 
+
+running=`ps ax | grep kvm-nbd | grep -v grep | wc -l`
 port=`expr 10000 + $running`
 
 kvm-nbd --port $port $image &
 echo $! > $image.pid
 
+sleep 1
+
 nbd-client localhost $port /dev/nbd$running || exit
 
 fdisk -l /dev/nbd$running
+
+fdisk -l /dev/nbd1 | grep ^/dev/nbd | cut -d" " -f1 | sed 's!/dev/!!' | xargs -i sh -x -c "mkdir -p /mnt/$image/{} ; mount -v /dev/{} /mnt/$image/{}"
+
+df -h /mnt/$image/*