When working with disk images, it’s often necessary to access the contents of a specific partition inside the image. Tools like parted, jq, and mount make this process straightforward by letting you find partition start offsets and then mount them directly. Adding sizelimit= makes the loop mount safer and more explicit by constraining how much of the image is exposed to the mount operation.
Use parted with JSON output to list all partitions and capture both their starting offsets and lengths (in bytes). The following command stores the results into a Bash array named PARTS, where each element contains start:size:
mapfile -t PARTS < <(parted --json 2025-05-13-raspios-bookworm-arm64-lite-f2fs.img unit B print 2>/dev/null \
| jq -r '.disk.partitions[] | "\(.start):\(.size)"' \
| sed 's/B//g')Here’s what happens in this command:
parted --json ... unit B printshows partition information in bytes.jqextracts both the starting byte (start) and the partition length (size).sed 's/B//g'removes the trailingBcharacter from both values.mapfile -t PARTS < <(...)stores allstart:sizepairs into the Bash arrayPARTS.
Now:
PARTS[0]will look like8388608:xxxxxxPARTS[1]will look likeyyyyyy:zzzzzz- etc.
To split a given entry into OFFSET and SIZELIMIT:
IFS=: read -r OFFSET SIZELIMIT <<< "${PARTS[0]}"
echo "offset=$OFFSET sizelimit=$SIZELIMIT"Once you have both the start offset and the partition size, mount using both options:
sudo mount -o loop,offset=OFFSET,sizelimit=SIZELIMIT \
2025-05-13-raspios-bookworm-arm64-lite-f2fs.img ./mntFor example, if PARTS[0] expands to 8388608:536870912, you would use:
sudo mount -o loop,offset=8388608,sizelimit=536870912 \
2025-05-13-raspios-bookworm-arm64-lite-f2fs.img ./mntIn this example:
offset=8388608tellsmountto start reading the file system at the 8 MB mark (the start of the partition).sizelimit=536870912constrains the loop device to the partition’s length, preventing accidental reads into adjacent partitions../mntis the directory where the partition will be accessible.
This mounts partition index N (0-based) by extracting offset and sizelimit from PARTS[N]:
N=0
IFS=: read -r OFFSET SIZELIMIT <<< "${PARTS[$N]}"
sudo mount -o loop,offset="$OFFSET",sizelimit="$SIZELIMIT" \
2025-05-13-raspios-bookworm-arm64-lite-f2fs.img ./mntThis method is especially handy when:
- You need to examine or modify files inside a Raspberry Pi OS image before flashing it.
- You want to copy specific configuration files without booting the image.
- You’re debugging or analyzing partitions in forensics or recovery tasks.
Using sizelimit= is a best practice in these workflows because it reduces the risk of mounting beyond the intended partition boundary.