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

#!/bin/bash
set -euo pipefail
mkdir --parents root
IMAGE_DATE=2018-11-15
# Weird but the image is from a different date.
FILE_DATE=2018-11-13
FILENAME="${FILE_DATE}-raspbian-stretch-lite"
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
# https://gist.github.com/htruong/7df502fb60268eeee5bca21ef3e436eb
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/ld.so.preload
sudo cp /usr/bin/qemu-arm-static root/usr/bin/