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

50 lines
1.4 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
2020-05-15 12:00:03 +02:00
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
2020-05-15 10:41:44 +02:00
info "Making mount dir..." &&
mkdir -p /mnt/raspbian ||
error
2020-05-15 10:41:44 +02:00
2020-05-15 12:00:03 +02:00
root_mount_path="/mnt/raspbian"
boot_mount_path="/mnt/raspbian/boot"
root_partition_path=$(echo_partition_name $1 "2")
boot_partition_path=$(echo_partition_name $1 "1")
2020-05-15 10:41:44 +02:00
info "Mount partitions..."
2020-05-15 12:00:03 +02:00
mount -o rw "$boot_partition_path" "$boot_mount_path" ||
mount -o rw "$root_partition_path" "$root_mount_path" &&
error
2020-05-15 10:41:44 +02:00
info "Mount binds..." &&
2020-05-15 12:00:03 +02:00
mount --bind /dev "$root_mount_path/dev/" &&
mount --bind /sys "$root_mount_path/sys/" &&
mount --bind /proc "$root_mount_path/proc/" &&
mount --bind /dev/pts "$root_mount_path/dev/pts" ||
2020-05-15 11:18:19 +02:00
error
2020-05-15 10:41:44 +02:00
info "ld.so.preload fix" &&
2020-05-15 12:00:03 +02:00
sed -i 's/^/#CHROOT /g' "$root_mount_path/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" &&
2020-05-15 12:00:03 +02:00
cp -v /usr/bin/qemu-arm-static "$root_mount_path/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" &&
2020-05-15 12:00:03 +02:00
chroot "$root_mount_path" /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" &&
2020-05-15 12:00:03 +02:00
sed -i 's/^#CHROOT //g' "$root_mount_path/etc/ld.so.preload" ||
2020-05-15 11:18:19 +02:00
error
2020-05-15 10:41:44 +02:00
info "unmount everything" &&
2020-05-15 12:00:03 +02:00
umount "$root_mount_path"/{dev/pts,dev,sys,proc,boot,} ||
2020-05-15 11:18:19 +02:00
error