When I run the new reform-boot-config
script I get an error:
check if rootfs is already mounted somewhere that is not /
MOUNTROOT=“$(lsblk --noheadings --output=MOUNTROOT “/dev/$ROOTPART”)”
lsblk --noheadings --output=MOUNTROOT /dev/sda1
lsblk: unknown column: MOUNTROOT
I suspect you meant MOUNTPOINT, but that raises a problem I have with the script as a whole. Variable names are confusingly similar and sometimes interchanged. BOOTPART and ROOTPART look similar as well. Here’s another snippet:
OLDBOOTPART=“$(LIBMOUNT_FSTAB=”$MOUNTROOT/etc/fstab" findmnt --fstab --noheadings --evaluate --mountpoint /boot --output SOURCE)"
if [ -z “$OLDBOOTPART” ]; then
echo “cannot find /boot device referenced by /etc/fstab in rootfs at /dev/$ROOTPART” >&2
exit 1
fi
I’m going to go out on a limb and suggest that the condition doesn’t equate to the error message, but I don’t know because honestly BOOTPREF, BOOTPART, OLDBOOTPART, ROOTPART, etc. are just swimming in my head as I stare at this code. After thinking about trying to figure what’s going on here I thought I’d kick it up to you for your thoughts, as you’ve spent a lot of time on it.
Minor patch below.
Ehud
P.S. I hope I’m not offending in using PRE instead of CODE tags. The former requires a lot less ‘fixup’ in post 
# diff -u 20221010_reform-boot-config.orig 20221010_reform-boot-config
--- 20221010_reform-boot-config.orig 2022-10-12 11:46:08.088940957 -0700
+++ 20221010_reform-boot-config 2022-10-12 12:48:17.870261940 -0700
@@ -16,38 +16,49 @@
# that must fit the correct kernel version. The choice of rootfs stored inside
# the initramfs is derived from the settings of /etc/fstab in the rootfs.
+# Constants:
+EXIT_FAILURE=1
+EXIT_SUCCESS=0
+UID_ROOT=0
+
set -eu
-if [ "$(id -u)" -ne 0 ]
- then echo "reform-boot-config has to be run as root / using sudo."
+if [ "${UID_ROOT}" -ne "$(id -u)" ]
+ then
+ echo "$0 has to be run as root / or by using sudo."
exit
fi
-echo "This script selects your preferred boot medium. It writes your choice to the file /etc/fstab"
-echo
+echo "This script selects your preferred boot medium. It writes your choice to the file /etc/fstab \n"
usage() {
- echo "Usage: " >&2
- echo " reform-boot-config [--emmc] sd # rootfs on SD card (/dev/mmcblk1p2, default)." >&2
- echo " reform-boot-config [--emmc] nvme # rootfs on NVMe SSD (/dev/nvme0n1p1)." >&2
- echo " reform-boot-config [--emmc] usb # rootfs on USB storage device (/dev/sda1)." >&2
- echo " reform-boot-config [--emmc] emmc # rootfs on eMMC (/dev/mmcblk0p2)." >&2
- echo "" >&2
- echo " --emmc Record boot preference on eMMC instead of SD card." >&2
- echo " This is only useful with SoM dip switch turned off." >&2
- echo "" >&2
- echo "Choosing sd, nvme, usb or emmc will set the root partition to" >&2
- echo "/dev/mmcblk1p2, /dev/nvme0n1p1, /dev/sda1 or /dev/mmcblk0p2," >&2
- echo "respectively.i You can choose another root partition by passing" >&2
- echo "the absolute device path starting with /dev/ explicitly." >&2
- echo "For example, to boot a rootfs on an LVM volume, run:" >&2
- echo "" >&2
- echo " reform-boot-config /dev/reformvg/root" >&2
+ cat >&2 <<EOD
+ Usage:
+ reform-boot-config [--emmc] {sd,nvme,usb,emmc}
+
+ --emmc Record boot preference on eMMC instead of SD card.
+ This is used once the SoM dip switch is turned off.
+
+ Examples:
+ reform-boot-config [--emmc] sd # rootfs on SD card (/dev/mmcblk1p2, default).
+ reform-boot-config [--emmc] nvme # rootfs on NVMe SSD (/dev/nvme0n1p1).
+ reform-boot-config [--emmc] usb # rootfs on USB storage device (/dev/sda1).
+ reform-boot-config [--emmc] emmc # rootfs on eMMC (/dev/mmcblk0p2).
+
+ Choosing sd, nvme, usb or emmc will set the root partition to
+ /dev/mmcblk1p2, /dev/nvme0n1p1, /dev/sda1 or /dev/mmcblk0p2,
+ respectively. A different root partition can be specified by passing
+ the absolute device path starting with /dev/ explicitly.
+
+ For example, to boot a rootfs on an LVM volume, run:
+
+ reform-boot-config /dev/reformvg/root
+EOD
}
if [ $# -ne 1 ] && [ $# -ne 2 ]; then
usage
- exit 1
+ exit $EXIT_FAILURE
fi
BOOTPREF="$1"