Mount SD Image Script - iot-root/garden-of-eden GitHub Wiki

Create the following mount-image.sh script.

Run nano mount-image.sh and paste and save the following script.

Run sudo chmod +x mount-image.sh

Run ./mount-image.sh <path/to/sd/image> /mnt/gardyn

#!/bin/bash

# Check if two arguments are provided
if [ $# -ne 2 ]; then
    echo "Usage: $0 <image> <mount_point>"
    exit 1
fi

# Get the image path and mount point from the arguments
IMAGE=$1
MOUNT_POINT=$2

# Get the start sector for the Linux partition and calculate the offset
SECTOR_SIZE=512
START_SECTOR=$(fdisk -l $IMAGE | grep Linux | awk '{print $2}')

# If a Linux partition wasn't found, exit the script
if [ -z "$START_SECTOR" ]; then
    echo "No Linux partition found in $IMAGE."
    echo "Run fdisk -l $IMAGE to investigate."
    exit 1
fi

echo "StartSector Found: $START_SECTOR"


# Calculate the offset
START_OFFSET=$(($START_SECTOR * $SECTOR_SIZE))
echo "StartOffset: $START_OFFSET"
# Check if mount point exists and create it if necessary
if [ ! -d $MOUNT_POINT ]; then
    mkdir -p $MOUNT_POINT
fi

# Mount the image
sudo mount -o loop,offset=$START_OFFSET $IMAGE $MOUNT_POINT

# Check if mount command was successful
if [ $? -eq 0 ]; then
    echo "Image successfully mounted to $MOUNT_POINT"
    sudo chown $USER:$USER $MOUNT_POINT
else
    echo "Failed to mount image."
fi

unmount-image.sh

#!/bin/bash

sudo umount /mnt/gardyn
⚠️ **GitHub.com Fallback** ⚠️