Skip to content

Instantly share code, notes, and snippets.

@daikw
Last active April 19, 2023 09:45
Show Gist options
  • Select an option

  • Save daikw/4abd9cb97bb4e61207f8f67e146893ee to your computer and use it in GitHub Desktop.

Select an option

Save daikw/4abd9cb97bb4e61207f8f67e146893ee to your computer and use it in GitHub Desktop.
Extract boot partition files from raspi-os compressed image files
#!/bin/bash
# $file is the xz-ed or zipped file name downloaded from: https://www.raspberrypi.com/software/operating-systems/
file=$1
body=${file%.*}
extension=${file##*.}
if [[ "$extension" == "xz" ]]; then
image_file=$body
xz -d -k $file
elif [[ "$extension" == "zip" ]]; then
image_file=$body.img
unzip $file
else
echo "Unknown file type"
exit 1
fi
start_address=$(parted $image_file -m -s unit B print | grep '^1:' | cut -d: -f 2 | sed 's/.$//')
mountdir=/mnt/file
sudo mkdir $mountdir
echo "mounting $body on $mountdir by starting at $start_address ..."
sudo mount -o loop,ro,offset=$start_address $image_file $mountdir
sudo cp -r $mountdir /home/pi/boot_partitions/$body.boot
sudo umount $mountdir
sudo rmdir $mountdir
rm $image_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment