3 |
test -e $1 || ( echo echo "Usage: $0 image.qcow2" ; exit 1 ) |
test -e $1 || ( echo echo "Usage: $0 image.qcow2" ; exit 1 ) |
4 |
|
|
5 |
image=$1 |
image=$1 |
6 |
path=$2 |
|
7 |
running=`ps ax | grep nbd | grep -v grep | wc -l` |
test -e $image.pid && kill `cat $image.pid` |
8 |
|
|
9 |
|
running=`ps ax | grep kvm-nbd | grep -v grep | wc -l` |
10 |
port=`expr 10000 + $running` |
port=`expr 10000 + $running` |
11 |
|
|
12 |
kvm-nbd --port $port $image & |
kvm-nbd --port $port $image & |
13 |
echo $! > $image.pid |
echo $! > $image.pid |
14 |
|
|
15 |
|
sleep 1 |
16 |
|
|
17 |
nbd-client localhost $port /dev/nbd$running || exit |
nbd-client localhost $port /dev/nbd$running || exit |
18 |
|
|
19 |
fdisk -l /dev/nbd$running |
fdisk -l /dev/nbd$running |
20 |
|
|
21 |
|
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/{}" |
22 |
|
|
23 |
|
df -h /mnt/$image/* |