Work-in-progress. This repository contains some scripts to prepare SD card images for the raspberry Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.2 KiB

set -euo pipefail
mkdir --parents root
# Weird but the image is from a different date.
BOOT_START_SECTOR=$(sfdisk --json ${FILENAME}.img | jq '.partitiontable.partitions[] | select(.type == "c") | .start')
BOOT_SECTOR_SIZE=$(sfdisk --json ${FILENAME}.img | jq '.partitiontable.partitions[] | select(.type == "c") | .size')
ROOT_START_SECTOR=$(sfdisk --json ${FILENAME}.img | jq '.partitiontable.partitions[] | select(.type == "83") | .start')
[[ -z $(mount | grep "${PWD}/root") ]]\
&& sudo mount --options loop,offset=$((512*ROOT_START_SECTOR)) "${FILENAME}.img" root
[[ -z $(mount | grep "${PWD}/boot") ]]\
&& sudo mount --options loop,offset=$((512*BOOT_START_SECTOR)),sizelimit=$((512*BOOT_SECTOR_SIZE)) "${FILENAME}.img" root/boot
sudo mount --bind /dev root/dev/
sudo mount --bind /sys root/sys/
sudo mount --bind /proc root/proc/
sudo mount --bind /dev/pts root/dev/pts
sudo mount --bind /etc/resolv.conf root/etc/resolv.conf
sudo sed -i 's/^/#CHROOT /g' root/etc/
sudo cp /usr/bin/qemu-arm-static root/usr/bin/