Skip to content

Instantly share code, notes, and snippets.

@dpavlin
Last active December 20, 2023 18:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpavlin/35a952a946b40a51e859 to your computer and use it in GitHub Desktop.
Save dpavlin/35a952a946b40a51e859 to your computer and use it in GitHub Desktop.
mount Raspberry Pi image, copy qemu-arm-static and chroot into it to tweak it
#!/bin/sh -xe
# mount Raspberry Pi image, copy qemu-arm-static and chroot into it to tweak it
dir=/tmp/rpi
test "umount" = "$1" && sudo umount $dir/boot && sudo umount $dir
image=$1
test -r "$image" || ( echo "Usage: $0 /path/to/rpi.img" && exit 1 )
o_boot=`sudo sfdisk -l $image | grep FAT32 | awk '{ print $2 }'`
o_linux=`sudo sfdisk -l $image | grep Linux | awk '{ print $2 }'`
echo "mount $o_linux and $o_boot"
test -d $dir || mkdir $dir
sudo mount -o offset=`expr $o_linux \* 512`,loop $image $dir
sudo mount -o offset=`expr $o_boot \* 512`,loop $image $dir/boot
test -f $dir/usr/bin/qemu-arm-static || cp `which qemu-arm-static` $dir/usr/bin/
sudo chroot $dir
sudo umount $dir/boot
sudo umount $dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment