Skip to content

Instantly share code, notes, and snippets.

@Juul
Created May 18, 2019 05:49
Show Gist options
  • Save Juul/1d54fd05ce254edc04032e43d4b5e471 to your computer and use it in GitHub Desktop.
Save Juul/1d54fd05ce254edc04032e43d4b5e471 to your computer and use it in GitHub Desktop.
Mount all partitions from a full drive image
#!/bin/bash
# Mount all partitions from a full drive image
# in subdirs inside the specified dir
set -e
if [ ! "$#" -eq "2" ]; then
echo "Usage: $(basename $0) <image.dd> <mount_dir>" >&2
exit 1
fi
IMAGE=$1
MNT_DIR=$2
if [ ! -f "$IMAGE" ]; then
echo "$IMAGE does not exist" >&2
exit 1
fi
if [ ! -d "$MNT_DIR" ]; then
echo "$MNT_DIR is not a directory" >&2
exit 1
fi
LOOPDEV=$(sudo losetup --partscan --find --read-only --show $IMAGE)
echo "Image loop device created: $LOOPDEV"
for DEV in ${LOOPDEV}?*; do
DEV_MNT=${MNT_DIR}/$(basename $DEV)
echo "Mounting $DEV in $DEV_MNT"
mkdir -p $DEV_MNT
mount -o ro $DEV $DEV_MNT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment