2021-06-02

  • Mount Raspberry Pi Distribution Image
    #!/bin/bash
    # $ fdisk -l retropie-buster-4.7.1-rpi2_3.img
    # Disk retropie-buster-4.7.1-rpi2_3.img: 2.91 GiB, 3099590656 bytes, 6053888 sectors
    # Units: sectors of 1 * 512 = 512 bytes
    # Sector size (logical/physical): 512 bytes / 512 bytes
    # I/O size (minimum/optimal): 512 bytes / 512 bytes
    # Disklabel type: dos
    # Disk identifier: 0x917c041d
    #
    # Device                            Boot  Start     End Sectors  Size Id Type
    # retropie-buster-4.7.1-rpi2_3.img1 *      8192  532479  524288  256M  e W95 FAT16 (LBA)
    # retropie-buster-4.7.1-rpi2_3.img2      532480 6053887 5521408  2.6G 83 Linux
    
    BASE_DIR=/home/andrwj/workspace
    IMAGE_FILE=${BASE_DIR}/retropie-buster-4.7.1-rpi2_3.img
    MOUNT_POINT=${BASE_DIR}/mnt
    BOOT_COUNT=$1
    BOOT_SIZE=$2
    
    ROOT_COUNT=$3
    ROOT_SIZE=$4
    if [ ! -e ${MOUNT_POINT} ]; then
       sudo mkdir -p ${MOUNT_POINT}
    fi
    echo "mount -v -o offset=${ROOT_COUNT},sizelimit=${ROOT_SIZE} -t ext4 ${IMAGE_FILE} ${MOUNT_POINT}"
    sudo mount -v -o offset=${ROOT_COUNT},sizelimit=${ROOT_SIZE} -t ext4 ${IMAGE_FILE} ${MOUNT_POINT}
    if [ ! -e ${MOUNT_POINT}/boot ]; then
       echo "'boot' mount point created"
       sudo mkdir -p ${MOUNT_POINT}/boot
    fi
    echo "mount -v -o offset=${BOOT_COUNT} -t vfat  ${IMAGE_FILE} ${MOUNT_POINT}/boot"
    sudo mount -v -o offset=${BOOT_COUNT},sizelimit=${BOOT_SIZE} -t vfat  ${IMAGE_FILE} ${MOUNT_POINT}/boot

References

References
1 512 * 8192
2 524288 * 512
3 512 * 532480
4 5521408 * 512