Skip to content

Instantly share code, notes, and snippets.

@dakhnod
Created December 16, 2024 10:29
Show Gist options
  • Select an option

  • Save dakhnod/113a7b9f28bf7d9c79c7005433e337c8 to your computer and use it in GitHub Desktop.

Select an option

Save dakhnod/113a7b9f28bf7d9c79c7005433e337c8 to your computer and use it in GitHub Desktop.

mount.img

This utility allows mounting .img files containing multiple partitions to the FS.

Usage

mount.img /path/to/file.img 2 /mnt/mount/point

with 2 being the partition index, as fdisk -l /path/to/file.img reports. First partition is 1.

#!/bin/bash
if [[ ! "$1" || ! "$2" || ! "$3" ]]; then
echo "Usage: mount_file IMAGE PARTITION_NUMBER MOUNTPOINT"
exit 1
fi
line=(`fdisk -l "$1" | tr -d '*' | grep "$1$2"`)
echo "${line[*]}"
mount -o loop,offset=$((512 * ${line[1]})),sizelimit=$((512 * ${line[3]})) $1 $3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment