Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created January 20, 2020 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsfaint/96c4d3fae06e72df3c15e8386eecbf8d to your computer and use it in GitHub Desktop.
Save jsfaint/96c4d3fae06e72df3c15e8386eecbf8d to your computer and use it in GitHub Desktop.
Mount image under /tmp
#!/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