Skip to content
Snippets Groups Projects
Commit f23de008 authored by minute's avatar minute
Browse files

Merge branch 'main' into 'main'

support encrypted usb storage device, reform-migrate fixes and improvement

See merge request !18
parents f26b6cdf 4979f376
No related branches found
No related tags found
1 merge request!18support encrypted usb storage device, reform-migrate fixes and improvement
......@@ -5,7 +5,8 @@ echo "MNT Reform: reform-init checking boot media..."
/bin/mount -t proc /proc /proc
BOOTPREF=$(cat /reform-boot-medium)
BOOTPREF=$(cat /reform-boot-medium) # Read config file from reform-boot-config script
BOOTPART="/dev/mmcblk1p1" # SD card
if [ "x$BOOTPREF" == "x" ]
then
......@@ -13,78 +14,57 @@ then
BOOTPREF="sd"
fi
echo "Your boot preference is: $BOOTPREF"
echo "Your boot preference is: '$BOOTPREF'"
# Boot from SD card (already mounted by kernel)
if [ "$BOOTPREF" == "sd" ]
then
# Check config
if [ "$BOOTPREF" == "usb" ]; then
echo "Booting from USB storage device, after 3sec."
sleep 3
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."
exec /sbin/init
fi
# Boot from USB (/dev/sda1)
if [ "$BOOTPREF" == "usb" ]
then
echo "Trying to boot from USB storage (/dev/sda1)."
/bin/mount /dev/sda1 /mnt
if [ "$?" != "0" ]
then
echo "Could not mount /dev/sda1. Falling back to SD card."
read -p Press ENTER to continue.
exec /sbin/init
fi
if [ ! -e /mnt/sbin/init ]
then
echo "No /sbin/init found on mounted disk. Falling back to SD card."
umount /mnt
read -p Press ENTER to continue.
exec /sbin/init
fi
cd /mnt
mount --move . /
exec chroot . /sbin/init
fi
# The remaining option is NVMe.
# In the future, this could check multiple partitions.
NVMEPART=/dev/nvme0n1p1
if [ ! -e $NVMEPART ]
then
echo "NVMe not found. Falling back to SD card."
read -p Press ENTER to continue.
# 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
blkid | grep $NVMEPART | grep crypto_LUKS
LUKS=$?
if [[ "$LUKS" == "0" ]]
then
echo "Attempting to mount encrypted NVMe."
# try to mount encrypted NVMe SSD
# 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 $NVMEPART cryptroot && break
/sbin/cryptsetup luksOpen "$BOOTPART" cryptroot && break
done
/bin/mount /dev/mapper/cryptroot /mnt
else
echo "Attempting to mount unencrypted NVMe."
/bin/mount $NVMEPART /mnt
BOOTPART="/dev/mapper/cryptroot"
fi
if [ ! -e /mnt/sbin/init ]
then
# 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 -p Press ENTER to continue.
read -r -p "Press ENTER to continue."
exec /sbin/init
fi
# move root mount over to encrypted drive
cd /mnt
cd /mnt || exit 9
mount --move . /
exec chroot . /sbin/init
......@@ -21,7 +21,7 @@ then
echo "Usage: "
echo " reform-boot-config sd Boot from SD card (default)."
echo " reform-boot-config nvme Boot from NVMe SSD (encrypted or plain)."
echo " reform-boot-config usb Boot from USB storage device."
echo " reform-boot-config usb Boot from USB storage device (encrypted or plain)."
exit
fi
......
......@@ -24,20 +24,22 @@ then
exit
fi
if [ ! -e $TARGET ]
if [ ! -e "$TARGET" ]
then
echo "Error: The partition $TARGET does not exist."
exit
fi
if [ "$EUID" -ne 0 ]
then echo "reform-standby has to be run as root / using sudo."
then echo "reform-migrate has to be run as root / using sudo."
exit
fi
command -v "rsync" >/dev/null 2>&1 || { echo >&2 "'rsync' is needed. Please install 'rsync' (apt install rsync)."; exit 1; }
echo "Trying to mount $TARGET... (if this fails, format the disk/partition as explained above)"
mount /dev/nvme0n1p1 /mnt
mount "$TARGET" /mnt
echo "Target partition successfully mounted. The next step will copy all your files over to the target, overwriting existing files in the process."
echo ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment