Created
May 11, 2018 20:05
-
-
Save E3V3A/d4d84ad02ba76cb8609d60930fa9eb53 to your computer and use it in GitHub Desktop.
Locally mounting a Raspberry Pi Raspbian Linux image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Usage: sudo ./mount-raspbian-image <imagename> | |
# | |
if [ -z "$1" ] | |
then | |
echo "Usage: sudo ./mount-raspbian-image <imagename>" | |
exit | |
fi | |
IMG=$1 | |
# Capture the patition details. | |
BOOT_PARTITION=`fdisk -l "$IMG" | grep "c W95 FAT32 (LBA)"` | |
ROOT_PARTITION=`fdisk -l "$IMG" | grep "83 Linux"` | |
# Grab the starting sector of the partitions. | |
BOOT_START_SECTOR=`echo "$BOOT_PARTITION" | awk '{print $2}'` | |
ROOT_START_SECTOR=`echo "$ROOT_PARTITION" | awk '{print $2}'` | |
# Calculate the start byte of the partitions. | |
((BOOT_START_BYTE=$BOOT_START_SECTOR * 512)) | |
((ROOT_START_BYTE=$ROOT_START_SECTOR * 512)) | |
# Grab the sector length of the partitions. | |
BOOT_SECTOR_LENGTH=`echo "$BOOT_PARTITION" | awk '{print $4}'` | |
ROOT_SECTOR_LENGTH=`echo "$ROOT_PARTITION" | awk '{print $4}'` | |
# Calculate the byte length of the partitions. | |
((BOOT_BYTE_LENGTH=$BOOT_SECTOR_LENGTH * 512)) | |
((ROOT_BYTE_LENGTH=$ROOT_SECTOR_LENGTH * 512)) | |
# Create the mount points. | |
sudo mkdir -p /mnt/image/boot | |
sudo mkdir -p /mnt/image/root | |
# Mount the partitions to the mount points. | |
mount -v -o offset=$BOOT_START_BYTE,sizelimit=$BOOT_BYTE_LENGTH -t vfat "$IMG" /mnt/image/boot | |
mount -v -o offset=$ROOT_START_BYTE,sizelimit=$ROOT_BYTE_LENGTH -t ext4 "$IMG" /mnt/image/root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment