turn qemu/kvm image into nbd device
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 11 May 2009 21:48:57 +0000 (21:48 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 11 May 2009 21:48:57 +0000 (21:48 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@52 191e9f34-6774-4a6d-acfc-7664dacd4a2a

recepies/kvm/20.mount-image
recepies/kvm/image-device.sh [new file with mode: 0755]

index 1f9c2db..e9fe50c 100644 (file)
@@ -1,4 +1,4 @@
-root@klin:/btrfs# kvm-nbd --port 10000 212052.cqow2 &
+root@klin:/btrfs# kvm-nbd --port 10000 212052.qcow2 &
 
 root@klin:/btrfs# nbd-client localhost 10000 /dev/nbd0
 Negotiation: ..size = 52428800KB
diff --git a/recepies/kvm/image-device.sh b/recepies/kvm/image-device.sh
new file mode 100755 (executable)
index 0000000..0ef15cd
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh -x
+
+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`
+port=`expr 10000 + $running`
+
+kvm-nbd --port $port $image &
+echo $! > $image.pid
+
+nbd-client localhost $port /dev/nbd$running || exit
+
+fdisk -l /dev/nbd$running