-
Notifications
You must be signed in to change notification settings - Fork 0
/
chroot-to-armhf.sh
executable file
·61 lines (45 loc) · 1.7 KB
/
chroot-to-armhf.sh
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
59
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script requires root, run it again with sudo"
exit 1
fi
LOOPDEV=$(losetup -P -f --show ${1})
mkdir -p /mnt/rpi-image/
# mount partition
mount -o rw ${LOOPDEV}p2 /mnt/rpi-image
mount -o rw ${LOOPDEV}p1 /mnt/rpi-image/boot
# mount binds
mount --bind /dev /mnt/rpi-image/dev/
mount --bind /sys /mnt/rpi-image/sys/
mount --bind /proc /mnt/rpi-image/proc/
mount --bind /dev/pts /mnt/rpi-image/dev/pts
mount --bind /run /mnt/rpi-image/run
# We need to comment out the copies and fills preload
# because we may be running on a machine/emulator that doesn't
# supoort the specical instructions that are used
sed -i 's/^/#QEMU /g' /mnt/rpi-image/etc/ld.so.preload
# copy qemu binary
cp /usr/bin/qemu-arm-static /mnt/rpi-image/usr/bin/
# chroot to rpi-image
chroot /mnt/rpi-image /bin/bash
# -------------------------- ON EXIT ---------------------------- #
# Clean up
# revert ld.so.preload fix
sed -i 's/^#QEMU //g' /mnt/rpi-image/etc/ld.so.preload
# unmount everything
umount -lf /mnt/rpi-image/{dev/pts,dev,sys,proc,boot,run}
umount -lf /mnt/rpi-image
# KNOWN ISSUES
#
# 1 sudo: no tty present and no askpass program specified
# Explanation: The error message sudo: no tty present and no askpass program specified will occur
# when the sudo command is trying to execute a command that requires a password
# but sudo does not have access to a tty to prompt the user for a passphrase.
# As it can’t find a tty, sudo fall back to an askpass method but can’t find an
# askpass command configured.
#
# Solution: Execute a command with sudo and no password requirements
#
# This is by adding to /etc/sudoers:
#
# %admin ALL=(ALL) NOPASSWD:ALL