Add flasher credential provisioning, LUKS2 FDE, LED fixes, and docs

This commit is contained in:
Luxferre committed 2026-11-23 08:21:37 +02:00
1 parent 2706b9a901
commit b7dca4f15f
49 files changed
+1524 -183

No files matched your search

+82 -16
View File
@@ -1,18 +1,57 @@
#!/bin/sh
# Geminux initramfs init (normal boot + off-mode charger guard + safe rootfs e2fsck/resize)
# Geminux initramfs init (off-mode charger guard + optional LUKS2 FDE unlock + safe rootfs e2fsck/resize)
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
export DM_DISABLE_UDEV=1
mkdir -p /proc /sys /dev /dev/pts /run /mnt/root
mkdir -p /proc /sys /dev /dev/pts /dev/mapper /run /run/cryptsetup /mnt/root
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev
mkdir -p /dev/pts
mkdir -p /dev/pts /dev/mapper /run/cryptsetup
chmod 0700 /run/cryptsetup
mount -t devpts devpts /dev/pts 2>/dev/null || true
if [ ! -c /dev/mapper/control ] && [ -r /sys/class/misc/device-mapper/dev ]; then
IFS=: read -r maj min < /sys/class/misc/device-mapper/dev
mknod /dev/mapper/control c "$maj" "$min" 2>/dev/null || true
fi
if command -v loadkmap >/dev/null 2>&1 && [ -f /etc/gemini-us.kmap ]; then
loadkmap < /etc/gemini-us.kmap >/dev/tty1 2>/dev/null || \
loadkmap < /etc/gemini-us.kmap 2>/dev/null || true
fi
set_console_quiet() {
echo 3 > /proc/sys/kernel/printk 2>/dev/null || true
}
tty_msg() {
if [ -c /dev/tty1 ]; then
printf '%s\n' "$1" > /dev/tty1 2>/dev/null || echo "$1"
else
echo "$1"
fi
}
ensure_dm_node() {
name="$1"
[ -b "/dev/mapper/$name" ] && return 0
for dmp in /sys/class/block/dm-*; do
[ -r "$dmp/dm/name" ] || continue
if [ "$(cat "$dmp/dm/name" 2>/dev/null)" = "$name" ]; then
dmdev="$(basename "$dmp")"
if [ -b "/dev/$dmdev" ]; then
ln -sf "/dev/$dmdev" "/dev/mapper/$name"
return 0
elif [ -r "$dmp/dev" ]; then
IFS=: read -r maj min < "$dmp/dev"
mknod "/dev/mapper/$name" b "$maj" "$min" 2>/dev/null && return 0
fi
fi
done
return 1
}
set_console_quiet
is_charger_mode() {
@@ -63,15 +102,17 @@ find_root_dev() {
echo /dev/disk/by-partlabel/linux
return 0
fi
for p in /proc/cmdline; do
:
done
return 1
}
emergency_shell() {
tty_msg "[geminux-init] ERROR: $1"
tty_msg "[geminux-init] Dropping to initramfs emergency shell."
echo "[geminux-init] ERROR: $1"
echo "[geminux-init] Dropping to initramfs emergency shell."
if [ -c /dev/tty1 ]; then
exec /bin/sh -i </dev/tty1 >/dev/tty1 2>&1
fi
exec /bin/sh
}
@@ -79,19 +120,39 @@ if is_charger_mode; then
run_offmode_charger
fi
ROOT_DEV=""
tty_msg "[geminux] Booting Geminux initramfs..."
RAW_ROOT_DEV=""
i=0
while [ "$i" -lt 60 ]; do
ROOT_DEV="$(find_root_dev || true)"
[ -n "$ROOT_DEV" ] && break
RAW_ROOT_DEV="$(find_root_dev || true)"
[ -n "$RAW_ROOT_DEV" ] && break
usleep 250000 2>/dev/null || sleep 1
i=$((i + 1))
done
[ -n "$ROOT_DEV" ] || emergency_shell "PARTLABEL=linux root block device not found"
[ -n "$RAW_ROOT_DEV" ] || emergency_shell "PARTLABEL=linux root block device not found"
ROOT_DEV="$RAW_ROOT_DEV"
if command -v cryptsetup >/dev/null 2>&1 && cryptsetup isLuks "$RAW_ROOT_DEV" >/dev/null 2>&1; then
[ -c /dev/tty1 ] || emergency_shell "LUKS2 encrypted rootfs detected but /dev/tty1 unavailable"
printf '\n=======================================================\n' > /dev/tty1 2>/dev/null || true
printf ' Geminux Full-Disk Encryption (LUKS2)\n' > /dev/tty1 2>/dev/null || true
printf ' Unlocking %s ...\n' "$RAW_ROOT_DEV" > /dev/tty1 2>/dev/null || true
printf '=======================================================\n\n' > /dev/tty1 2>/dev/null || true
while ! ensure_dm_node geminux_root; do
if cryptsetup open --allow-discards "$RAW_ROOT_DEV" geminux_root </dev/tty1 >/dev/tty1 2>&1; then
ensure_dm_node geminux_root && break
fi
printf '\n[geminux-init] Incorrect passphrase or unlock error; please try again.\n\n' > /dev/tty1 2>/dev/null || true
sleep 1
done
ROOT_DEV="/dev/mapper/geminux_root"
tty_msg "[geminux] Unlocked PARTLABEL=linux; checking root filesystem..."
fi
if command -v e2fsck >/dev/null 2>&1; then
e2fsck -p "$ROOT_DEV" >/dev/null 2>&1 || {
e2fsck -p "$ROOT_DEV" </dev/null >/dev/null 2>&1 || {
rc=$?
[ "$rc" -le 1 ] || echo "[geminux-init] Warning: e2fsck returned $rc on $ROOT_DEV"
}
@@ -105,12 +166,16 @@ if [ ! -f /mnt/root/var/lib/geminux/.rootfs-resized ]; then
fi
umount /mnt/root
if [ "$NEEDS_RESIZE" = "1" ] && command -v resize2fs >/dev/null 2>&1; then
echo "[geminux-init] Expanding $ROOT_DEV to fill full partition..."
resize2fs -f "$ROOT_DEV" >/dev/null 2>&1 || true
if command -v e2fsck >/dev/null 2>&1; then
e2fsck -p "$ROOT_DEV" >/dev/null 2>&1 || true
if [ "$NEEDS_RESIZE" = "1" ]; then
tty_msg "[geminux] First boot: expanding ext4 filesystem to full partition (~15-30s)..."
if command -v resize2fs >/dev/null 2>&1; then
echo "[geminux-init] Expanding $ROOT_DEV to fill full partition..."
resize2fs -f "$ROOT_DEV" </dev/null >/dev/null 2>&1 || true
if command -v e2fsck >/dev/null 2>&1; then
e2fsck -p "$ROOT_DEV" </dev/null >/dev/null 2>&1 || true
fi
fi
tty_msg "[geminux] Filesystem expansion complete; starting Geminux..."
fi
mount -t ext4 -o rw,noatime,commit=60 "$ROOT_DEV" /mnt/root || \
@@ -123,6 +188,7 @@ fi
[ -x /mnt/root/sbin/init ] || emergency_shell "/sbin/init missing on $ROOT_DEV"
unset DM_DISABLE_UDEV
umount /dev/pts 2>/dev/null || true
mount --move /dev /mnt/root/dev
mount --move /sys /mnt/root/sys