forked from adafruit/Adafruit-PiTFT-Helper
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adafruit-pi-chroot
executable file
·58 lines (49 loc) · 1.37 KB
/
adafruit-pi-chroot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
set -e
function print_help() {
echo "$0: get a chroot shell inside of a Raspbian ISO"
echo "Usage: $0 target.img"
echo " -h Print this help"
echo " -i [target] Specify an ISO to chroot to (probably a Pi Foundation Raspbian)"
exit 1
}
args=$(getopt -uo 'ht:i:' -- $*)
[ $? != 0 ] && print_help
set -- $args
for i
do
case "$i"
in
-h)
print_help
;;
-i)
target_image="$2"
echo "Image = ${2}"
shift
shift
;;
esac
done
if [[ $EUID -ne 0 ]]; then
echo "$0 must be run as root. try: sudo $0"
exit 1
fi
target_mnt="/media/raspbian-target"
# assemble a mostly-legit filesystem by mounting / and /boot from the target
# iso, plus /dev from the host pi (/dev/(u)random seems to be required by
# recent versions of GPG):
echo "Mounting $target_image on $target_mnt"
kpartx -av $target_image
mkdir -p $target_mnt
mount /dev/dm-1 $target_mnt
mount /dev/dm-0 $target_mnt/boot
mkdir -p $target_mnt/dev
mount --bind /dev $target_mnt/dev
echo "Dropping you into Bash - image will be unmounted after exit"
chroot $target_mnt sudo /bin/bash
echo "Unmounting $target_image"
umount $target_mnt/boot
umount $target_mnt/dev
umount $target_mnt
kpartx -d $target_image