1
1
Fork 0

added small qcow2 mounting script for virtualization hosts

This commit is contained in:
David Starzengruber 2011-01-02 18:17:58 +01:00
parent 20bfc4a131
commit 277d66a78c
1 changed files with 43 additions and 0 deletions

43
browseqcow2.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
#
# mount script for qcow2 images
# v0.1
#
# im i root
if [ $(whoami) != "root" ]; then
echo "only root can do this"
exit 1
fi
# run unmount
if [[ $1 = "--unmount" || $1 = "-u" || $1 = "--umount" ]]; then
umount /mnt/
qemu-nbd --disconnect /dev/nbd0
echo "image unmounted"
echo
exit 0
fi
# read imagename
if [ -z $1 ]; then
echo 'usage: "browseqcow2 <image.qcow2>"'
exit 1
fi
imagename=$1
# load kernel module
modprobe nbd max_part=8
# gen blockdevice
qemu-nbd --connect=/dev/nbd0 $imagename
# make the actual mount
sleep 2
mount /dev/nbd0p1 /mnt/
echo "$imagename is mounted in /mnt"
echo 'run "browseqcow2.sh --unmount" when ready'
echo