Created
May 18, 2019 05:49
-
-
Save Juul/1d54fd05ce254edc04032e43d4b5e471 to your computer and use it in GitHub Desktop.
Mount all partitions from a full drive image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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