Skip to content

Instantly share code, notes, and snippets.

@marcusmueller
Last active October 24, 2015 10:11
Show Gist options
  • Save marcusmueller/8b515296241cc87832b0 to your computer and use it in GitHub Desktop.
Save marcusmueller/8b515296241cc87832b0 to your computer and use it in GitHub Desktop.
Mounting images
#!/bin/bash
if [ "$#" -ne 1 -o "$1" == "--help" -o "$1" == "-h" ]; then
echo """
Usage:
$0 image-file
creates the loopback device for the image file, lets the kernel detect partitions inside, tries to mount every single partition.
Doesn't work on unpartitioned devices
"""
exit -1
fi
if [ ! -r $1 ]; then
echo "Input file $1 not readable. Exiting."
exit -2
fi
LOOPDEV=$(losetup --show -P -f $1)
echo "Got loop device $LOOPDEV."
SED_SECURE_LOOPDEV=$(echo $LOOPDEV | sed 's/\//\\\//g')
DIRSTRING=$(echo $LOOPDEV* | sed "s/$SED_SECURE_LOOPDEV//g")
echo "making partition directories$DIRSTRING."
for partition in $DIRSTRING; do
mkdir "$partition"
echo "mounting the partition $partition"
mount "$LOOPDEV$partition" "$partition"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment