#!/bin/busybox sh sleep 1 echo "MNT Reform: reform-init checking boot media..." /bin/mount -t proc /proc /proc # Read config file generated by reform-boot-config script BOOTPREF=$(cat /reform-boot-medium) # Default to SD card BOOTPART="/dev/mmcblk1p1" if [ "x$BOOTPREF" == "x" ] then echo "Defaulting to SD card." BOOTPREF="sd" fi echo "Your boot preference is: \"$BOOTPREF\"" # Check config if [ "$BOOTPREF" == "usb" ]; then echo "Booting from USB storage in 3 seconds." BOOTPART="/dev/sda1" elif [ "$BOOTPREF" == "nvme" ]; then echo "Booting from NVMe SSD." BOOTPART="/dev/nvme0n1p1" else # Default. Boot from SD card (already mounted by kernel). echo "Booting from SD card (or eMMC)." exec /sbin/init fi # Check if partition exists if [ ! -e $BOOTPART ]; then echo "Partition \"$BOOTPART\" not found. Falling back to SD card." read -r -p "Press ENTER to continue." exec /sbin/init fi # Check if partition is encrypted if blkid | grep "$BOOTPART" | grep "crypto_LUKS"; then echo "Attempting to mount encrypted partition \"$BOOTPART\"." while : do /sbin/cryptsetup luksOpen "$BOOTPART" cryptroot && break done BOOTPART="/dev/mapper/cryptroot" fi # Mount echo "Trying to boot from partition \"$BOOTPART\"." if ! /bin/mount "$BOOTPART" "/mnt"; then echo "Could not mount '$BOOTPART'. Falling back to SD card." read -r -p "Press ENTER to continue." exec /sbin/init fi # Fallback if [ ! -e /mnt/sbin/init ]; then echo "No /sbin/init found on mounted disk. Falling back to SD card." umount /mnt read -r -p "Press ENTER to continue." exec /sbin/init fi # Move root mount over to encrypted drive cd /mnt || exit 9 mount --move . / exec chroot . /sbin/init