david/scripts-archive
david
/
scripts-archive
Archived
1
0
Fork 0
This repository has been archived on 2022-04-16. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-archive/kvm-tools/archive/browseqcow2.sh

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