Skip to content

December 12, 2012

Mount KVM images on Linux

by e1ven

Just a quick little script I use once in a while, which I need to mount my KVM images, to access the files manually.

The way it works is to calculate where the data starts, then simply pass that as a paramter to the mount command.

simple, but very useful! 😉


#!/bin/bash
if [ $# -lt 2 ]
        then
        echo "Usage $0 image mountpoint"
        exit
fi

IMAGEFILE=$1
MOUNTPOINT=$2

SECTORSIZE=$(parted -s $IMAGEFILE unit s print | grep "Sector size" | awk -F": " {'print $2'} | awk -F"B/" {'print $1'})
OFFSETBLOCKS=$(parted -s $IMAGEFILE unit s print | grep "^ 3" | awk {'print $2'} | awk -Fs {'print $1'})
OFFSETSECTORS=$(echo "$SECTORSIZE * $OFFSETBLOCKS"  | bc)
mount -o loop,offset=$OFFSETSECTORS $IMAGEFILE $MOUNTPOINT

Advertisements
Read more from Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

%d bloggers like this: