#!/bin/bash # usage: qemu-mount {imagefile} # 1st argument: QEMU raw image file if [ $# -ne 1 ] ; then echo 'usage: qemu-mount imagefile' echo 'Mounts a QEMU raw image file to /mnt/temp' exit 1 fi start=$( fdisk -l -o Device,Start ${1} | grep "^${1}1" | gawk '{print $2}' ) sectors=$( fdisk -l ${1} | grep '^Units: sectors of' | gawk '{print $(NF-1)}' ) offset=$(( $start * $sectors )) [ -d /mnt/temp ] || mkdir /mnt/temp sudo mount -o loop,offset=$offset ${1} /mnt/temp