Created
January 20, 2020 08:18
-
-
Save jsfaint/96c4d3fae06e72df3c15e8386eecbf8d to your computer and use it in GitHub Desktop.
Mount image under /tmp
This file contains 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 | |
set -e | |
[[ -z $1 ]] && echo "$(basename $0) <image>" && exit 1 | |
image=$1 | |
[[ ! -e $image ]] && echo "Invalid image file" && exit 1 | |
sudo losetup -o 1048576 -f $image | |
lodev=$(losetup | grep $1 | awk '{print $1}') | |
MOUNT_POINT="/tmp/$(basename "$image")" | |
mkdir -p $MOUNT_POINT | |
sudo mount -o ro $lodev $MOUNT_POINT || sudo losetup -D | |
echo "The image was mounted at '$MOUNT_POINT'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment