From ebe07f5c3288848cdc57e7392af31356efa71c6c Mon Sep 17 00:00:00 2001 From: Gregor Haas Date: Wed, 11 Dec 2019 16:18:18 -0500 Subject: [PATCH] Add some tools that have proven useful --- tools/chroot-pi.sh | 69 +++++++++++++++++++++++++++++++++++ tools/enable_wireshark_usb.sh | 4 ++ tools/iphone.rules | 3 ++ 3 files changed, 76 insertions(+) create mode 100644 tools/chroot-pi.sh create mode 100644 tools/enable_wireshark_usb.sh create mode 100644 tools/iphone.rules diff --git a/tools/chroot-pi.sh b/tools/chroot-pi.sh new file mode 100644 index 0000000..6bfb32a --- /dev/null +++ b/tools/chroot-pi.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# This script allows you to chroot ("work on") +# the raspbian sd card as if it's the raspberry pi +# on your Ubuntu desktop/laptop +# just much faster and more convenient + +# credits: https://gist.github.com/jkullick/9b02c2061fbdf4a6c4e8a78f1312a689 + +# make sure you have issued +# (sudo) apt install qemu qemu-user-static binfmt-support + +# Write the raspbian image onto the sd card, +# boot the pi with the card once +# so it expands the fs automatically +# then plug back to your laptop/desktop +# and chroot to it with this script. + +# Invoke: +# (sudo) ./chroot-to-pi.sh /dev/sdb +# assuming /dev/sdb is your sd-card +# if you don't know, when you plug the card in, type: +# dmesg | tail -n30 + + +# Note: If you have an image file instead of the sd card, +# you will need to issue +# (sudo) apt install kpartx +# (sudo) kpartx -v -a 2017-11-29-raspbian-stretch-lite.img +# then +# (sudo) ./chroot-to-pi.sh /dev/mapper/loop0p +# With the vanilla image, you have very little space to work on +# I have not figured out a reliable way to resize it +# Something like this should work, but it didn't in my experience +# https://gist.github.com/htruong/0271d84ae81ee1d301293d126a5ad716 +# so it's better just to let the pi resize the partitions + +mkdir -p /mnt/raspbian + +# mount partition +mount -o rw ${1}2 /mnt/raspbian +mount -o rw ${1}1 /mnt/raspbian/boot + +# mount binds +mount --bind /dev /mnt/raspbian/dev/ +mount --bind /sys /mnt/raspbian/sys/ +mount --bind /proc /mnt/raspbian/proc/ +mount --bind /dev/pts /mnt/raspbian/dev/pts + +# ld.so.preload fix +sed -i 's/^/#CHROOT /g' /mnt/raspbian/etc/ld.so.preload + +# copy qemu binary +cp /usr/bin/qemu-arm-static /mnt/raspbian/usr/bin/ + +echo "You will be transferred to the bash shell now." +echo "Issue 'exit' when you are done." +echo "Issue 'su pi' if you need to work as the user pi." + +# chroot to raspbian +chroot /mnt/raspbian /bin/bash + +# ---------------------------- +# Clean up +# revert ld.so.preload fix +sed -i 's/^#CHROOT //g' /mnt/raspbian/etc/ld.so.preload + +# unmount everything +umount /mnt/raspbian/{dev/pts,dev,sys,proc,boot,} diff --git a/tools/enable_wireshark_usb.sh b/tools/enable_wireshark_usb.sh new file mode 100644 index 0000000..819e64c --- /dev/null +++ b/tools/enable_wireshark_usb.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +modprobe usbmon +setfacl -m u:grg:r /dev/usbmon* diff --git a/tools/iphone.rules b/tools/iphone.rules new file mode 100644 index 0000000..514d425 --- /dev/null +++ b/tools/iphone.rules @@ -0,0 +1,3 @@ +SUBSYSTEM=="usb", ATTR{idProduct}=="1227", ATTR{idVendor}=="05ac", MODE="0660", GROUP="grg" +SUBSYSTEM=="usb", ATTRS{idProduct}=="1227", ATTRS{idVendor}=="05ac", MODE="0660", GROUP="grg" +SUBSYSTEM=="usb-serial", MODE="0660", GROUP="grg"