pileogoo/scripts/extract_build.sh

27 lines
709 B
Bash
Raw Normal View History

2021-12-18 20:56:45 +00:00
#!/bin/bash +ex
dd if=/dev/zero of=build/rpi.img bs=1M count=4096
# Copy the first 8k from the original rpi.img, which seems to have
# non-zeroed content
#dd if=rpi.img of=build/rpi.img bs=8192 count=1 conv=notrunc
sudo losetup -Pf build/rpi.img
# Partition:
# start: 8192, size 256M typ W95 FAT32
DEVICE=$(losetup -j build/rpi.img | cut -d ':' -f 1)
mkfs.msdos "${DEVICE}"
sfdisk "${DEVICE}" <<EOF
8192,256M,c
,3.5G,83
EOF
mkfs.vfat "${DEVICE}p1"
mkfs.ext4 "${DEVICE}p2"
TMP=$(mktemp -d)
mount "${DEVICE}p1" "$TMP"
tar -C "$TMP" -xf build/all.tar --strip=1 boot/
umount "$TMP"
mount "${DEVICE}p2" "$TMP"
tar -C "$TMP" -xf build/all.tar --exclude='boot/*'
umount "$TMP"
losetup -D "${DEVICE}"
rm -rf "$TMP"