2017-02-07 19:24:32 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script will mount a given image in loop mode.
|
|
|
|
# Make sure to change the path and offsets for the image you use. You can get
|
|
|
|
# the correct offsets using `file $PATH_TO_IMAGE` or fdisk.
|
|
|
|
|
|
|
|
# To make debugging easier
|
|
|
|
echo "KittenGroomer: in mount_image.sh" 1>&2
|
|
|
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
echo "This script must be run as root" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
|
|
|
# Double check the path and offsets as noted above!
|
|
|
|
# Path to the image
|
2020-01-15 18:01:38 +01:00
|
|
|
IMAGE='2019-09-26-raspbian-buster-lite.img'
|
2017-02-07 19:24:32 +01:00
|
|
|
# Start sector of boot (first) partition
|
2019-03-02 09:18:25 +01:00
|
|
|
BOOT_START=`sfdisk -J ${IMAGE} | grep img1 | sed -n 's/.*"start":*\([[:digit:]]*\).*/\1/p'`
|
2018-01-29 14:20:58 +01:00
|
|
|
# Amount of sectors of boot (first) partition
|
2019-03-02 09:18:25 +01:00
|
|
|
BOOT_SIZE=`sfdisk -J ${IMAGE} | grep img1 | sed -n 's/.*"size":*\([[:digit:]]*\).*/\1/p'`
|
2017-02-07 19:24:32 +01:00
|
|
|
# Start sector of root (second) partition
|
2019-03-02 09:18:25 +01:00
|
|
|
ROOT_START=`sfdisk -J ${IMAGE} | grep img2 | sed -n 's/.*"start":*\([[:digit:]]*\).*/\1/p'`
|
2018-01-29 14:20:58 +01:00
|
|
|
# Amount of sectors of root (second) partition
|
2019-03-02 09:18:25 +01:00
|
|
|
ROOT_SIZE=`sfdisk -J ${IMAGE} | grep img2 | sed -n 's/.*"size":*\([[:digit:]]*\).*/\1/p'`
|
2018-01-29 14:20:58 +01:00
|
|
|
|
2017-02-07 19:24:32 +01:00
|
|
|
# Locations you'd like the partitions mounted
|
|
|
|
BOOT_PATH='/mnt/rpi-boot'
|
|
|
|
ROOTFS_PATH='/mnt/rpi-root'
|
|
|
|
|
|
|
|
# Calculate offsets for each partition
|
|
|
|
offset_boot=$((${BOOT_START} * 512))
|
2018-01-29 14:20:58 +01:00
|
|
|
sizelimit_boot=$((${BOOT_SIZE} * 512))
|
2017-02-07 19:24:32 +01:00
|
|
|
offset_rootfs=$((${ROOT_START} * 512))
|
2018-01-29 14:20:58 +01:00
|
|
|
sizelimit_rootfs=$((${ROOT_SIZE} * 512))
|
2017-02-07 19:24:32 +01:00
|
|
|
# TODO: add logic for creating directories if they aren't already there
|
|
|
|
mkdir -p ${BOOT_PATH}
|
|
|
|
mkdir -p ${ROOTFS_PATH}
|
|
|
|
# Mount each partition in loop mode
|
2018-01-29 14:20:58 +01:00
|
|
|
mount -o loop,offset=${offset_boot},sizelimit=${sizelimit_boot} ${IMAGE} ${BOOT_PATH}
|
|
|
|
mount -o loop,offset=${offset_rootfs},sizelimit=${sizelimit_rootfs} ${IMAGE} ${ROOTFS_PATH}
|
2017-02-07 19:24:32 +01:00
|
|
|
|
|
|
|
echo "Image mounted" 1>&2
|