45 lines
707 B
Bash
45 lines
707 B
Bash
#!/bin/bash
|
|
|
|
#
|
|
# mount script for qcow2 images
|
|
# v0.1
|
|
#
|
|
|
|
# read imagename
|
|
if [ -z $1 ]; then
|
|
echo 'usage: "browseqcow2 <image.qcow2>"'
|
|
exit 1
|
|
fi
|
|
|
|
imagename=$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
|
|
|
|
# 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
|