linux-image-manager/scripts/image/chroot.sh

45 lines
1.2 KiB
Bash
Raw Normal View History

2020-05-02 11:46:39 +02:00
#!/bin/bash
2020-05-15 10:41:44 +02:00
# shellcheck source=/dev/null # Deactivate SC1090
# shellcheck disable=SC2015 # Deactivating bool hint
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
info "Making mount dir..." &&
mkdir -p /mnt/raspbian ||
error
2020-05-15 10:41:44 +02:00
info "Mount partitions..."
mount -o rw "$1""2" /mnt/raspbian &&
mount -o rw "$1""1" /mnt/raspbian/boot ||
error
2020-05-15 10:41:44 +02:00
info "Mount binds..." &&
mount --bind /dev /mnt/raspbian/dev/ &&
mount --bind /sys /mnt/raspbian/sys/ &&
mount --bind /proc /mnt/raspbian/proc/ &&
2020-05-15 10:42:49 +02:00
mount --bind /dev/pts /mnt/raspbian/dev/pts ||
2020-05-15 11:18:19 +02:00
error
2020-05-15 10:41:44 +02:00
info "ld.so.preload fix" &&
sed -i 's/^/#CHROOT /g' /mnt/raspbian/etc/ld.so.preload ||
2020-05-15 11:18:19 +02:00
error
2020-05-15 10:41:44 +02:00
info "copy qemu binary" &&
cp -v /usr/bin/qemu-arm-static /mnt/raspbian/usr/bin/ ||
2020-05-15 11:18:19 +02:00
error
2020-05-15 10:41:44 +02:00
info "You will be transferred to the bash shell now." &&
info "Issue 'exit' when you are done." &&
info "Issue 'su pi' if you need to work as the user pi." &&
info "chroot to raspbian" &&
chroot /mnt/raspbian /bin/bash ||
2020-05-15 11:18:19 +02:00
error
2020-05-15 10:41:44 +02:00
info "Clean up" &&
info "revert ld.so.preload fix" &&
sed -i 's/^#CHROOT //g' /mnt/raspbian/etc/ld.so.preload ||
2020-05-15 11:18:19 +02:00
error
2020-05-15 10:41:44 +02:00
info "unmount everything" &&
umount /mnt/raspbian/{dev/pts,dev,sys,proc,boot,} ||
2020-05-15 11:18:19 +02:00
error