44 lines
706 B
Bash
44 lines
706 B
Bash
|
#!/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
|