V8.13.440.2025.11.19
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
@@ -37,31 +37,35 @@ log() {
|
||||
fi
|
||||
}
|
||||
|
||||
### Declare variables ----------------------------------------------------------------------------------------------------------
|
||||
CDLB_LUKS_FS="/live/ciss_rootfs.crypt"
|
||||
CDLB_ISO_LABEL="CISS.debian.live"
|
||||
### Declare variables. ---------------------------------------------------------------------------------------------------------
|
||||
export CDLB_ISO_LABEL="CISS.debian.live"
|
||||
export CDLB_LUKS_FS="/live/ciss_rootfs.crypt"
|
||||
export CDLB_MAPPER_NAME="ciss_rootfs.crypt"
|
||||
MNT_MEDIUM="/run/live/medium"
|
||||
MNT_ROOTFS="/run/live/rootfs"
|
||||
_PARAMETER=""
|
||||
_dev=""
|
||||
|
||||
### Read the kernel cmdline once -----------------------------------------------------------------------------------------------
|
||||
### Read the kernel cmdline once. ----------------------------------------------------------------------------------------------
|
||||
CMDLINE="$(cat /proc/cmdline 2>/dev/null || printf '')"
|
||||
|
||||
for _PARAMETER in ${CMDLINE}; do
|
||||
|
||||
case "${_PARAMETER}" in
|
||||
|
||||
ciss_crypt_path=*) CDLB_LUKS_FS="${_PARAMETER#ciss_crypt_path=}";;
|
||||
ciss_iso_label=* ) CDLB_ISO_LABEL="${_PARAMETER#ciss_iso_label=}";;
|
||||
ciss_crypt_path=*) export CDLB_LUKS_FS="${_PARAMETER#ciss_crypt_path=}";;
|
||||
ciss_iso_label=* ) export CDLB_ISO_LABEL="${_PARAMETER#ciss_iso_label=}";;
|
||||
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
printf "\e[92m[INFO] CDLB_LUKS_FS : [%s] \n\e[0m" "${CDLB_LUKS_FS}"
|
||||
printf "\e[92m[INFO] CDLB_ISO_LABEL : [%s] \n\e[0m" "${CDLB_ISO_LABEL}"
|
||||
|
||||
mkdir -p "${MNT_MEDIUM}" "${MNT_ROOTFS}"
|
||||
|
||||
### Mount the live medium (ISO) read-only, unless already mounted --------------------------------------------------------------
|
||||
### Mount the live medium (ISO) read-only, unless already mounted. -------------------------------------------------------------
|
||||
if ! mountpoint -q "${MNT_MEDIUM}"; then
|
||||
|
||||
if [ -n "${CDLB_ISO_LABEL}" ] && [ -e "/dev/disk/by-label/${CDLB_ISO_LABEL}" ]; then
|
||||
@@ -82,10 +86,8 @@ if ! mountpoint -q "${MNT_MEDIUM}"; then
|
||||
### Skip non-block entries early.
|
||||
[ -b "${_dev}" ] || continue
|
||||
|
||||
### Try ISO9660 first, then UDF; only unmount on failure
|
||||
if mount -r -t iso9660 "${_dev}" "${MNT_MEDIUM}" 2>/dev/null \
|
||||
|| mount -r -t udf "${_dev}" "${MNT_MEDIUM}" 2>/dev/null
|
||||
then
|
||||
### Try ISO9660 first, then UDF; only unmount on failure.
|
||||
if mount -r -t iso9660 "${_dev}" "${MNT_MEDIUM}" 2>/dev/null || mount -r -t udf "${_dev}" "${MNT_MEDIUM}" 2>/dev/null; then
|
||||
|
||||
mountpoint -q "${MNT_MEDIUM}" 2>/dev/null && break
|
||||
|
||||
@@ -102,20 +104,25 @@ fi
|
||||
if ! mountpoint -q "${MNT_MEDIUM}"; then
|
||||
|
||||
log "No live medium mounted, defer to default live-boot path."
|
||||
printf "\e[91m[FATAL] No live medium mounted, defer to default live-boot path. \n\e[0m"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
printf "\e[92m[INFO] MNT_MEDIUM : [%s] \n\e[0m" "${MNT_MEDIUM}"
|
||||
|
||||
### Locate the encrypted root container on the medium. -------------------------------------------------------------------------
|
||||
if [ ! -f "${MNT_MEDIUM}/${CDLB_LUKS_FS}" ]; then
|
||||
|
||||
log "Encrypted root not found at: [${MNT_MEDIUM}/${CDLB_LUKS_FS}]"
|
||||
printf "\e[91m[FATAL] Encrypted root not found at: [%s/%s] \n\e[0m" "${MNT_MEDIUM}" "${CDLB_LUKS_FS}"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
### Create/read FIFO compatible with cryptsetup-initramfs (if present). This allows 'cryptroot-unlock' to feed the passphrase
|
||||
### over SSH (dropbear).
|
||||
printf "\e[92m[INFO] CISS LUKS FS : [%s/%s] \n\e[0m" "${MNT_MEDIUM}" "${CDLB_LUKS_FS}"
|
||||
|
||||
### Create/read FIFO compatible with cryptsetup-initramfs. This allows 'cryptroot-unlock' to feed the passphrase over SSH. -----
|
||||
mkdir -p /lib/cryptsetup
|
||||
[ -p /lib/cryptsetup/passfifo ] || mkfifo /lib/cryptsetup/passfifo
|
||||
|
||||
@@ -127,16 +134,18 @@ attempts=0
|
||||
while true; do
|
||||
|
||||
attempts=$((attempts+1))
|
||||
echo "Unlock '${CDLB_LUKS_FS}' (try ${attempts}): use 'cryptroot-unlock' over SSH or enter on console" >/dev/console 2>/dev/null || true
|
||||
|
||||
## Non-blocking read from FIFO (Dropbear and cryptroot-unlock path).
|
||||
printf "\e[93m[INFO] Unlock: [%s] Attempt: [%s] Use 'cryptroot-unlock' over SSH or enter on console: \n\e[0m" \
|
||||
"${CDLB_LUKS_FS}" "${attempts}" >/dev/console 2>/dev/null || true
|
||||
|
||||
### Non-blocking read from FIFO (Dropbear and cryptroot-unlock path). --------------------------------------------------------
|
||||
if timeout 5 cat /lib/cryptsetup/passfifo | cryptsetup open --type luks --readonly "${LOOP}" crypt_liveiso --key-file - 2>/dev/null; then
|
||||
|
||||
break
|
||||
|
||||
fi
|
||||
|
||||
### Interactive fallback on the console.
|
||||
### Interactive fallback on the console. -------------------------------------------------------------------------------------
|
||||
if cryptsetup open --type luks --readonly "${LOOP}" crypt_liveiso; then
|
||||
|
||||
break
|
||||
@@ -145,16 +154,17 @@ while true; do
|
||||
|
||||
done
|
||||
|
||||
### Mount the decrypted payload as SquashFS under '/run/live/rootfs'. ----------------------------------------------------------
|
||||
mount -r -t squashfs /dev/mapper/crypt_liveiso "${MNT_ROOTFS}" || { log "mount squashfs failed"; exit 1; }
|
||||
### Expose the decrypted root device for live-boot overlay. The live-boot components will pick this up in '9990-overlay.sh'. ---
|
||||
echo "/dev/mapper/crypt_liveiso" >| /run/ciss-rootdev
|
||||
|
||||
### Ensure live-boot keeps using our medium (bind-mount for consistency). ------------------------------------------------------
|
||||
mount --bind "${MNT_MEDIUM}" "${MNT_MEDIUM}" 2>/dev/null || true
|
||||
chmod 0644 /run/ciss-rootdev 2>/dev/null || true
|
||||
|
||||
log "Encrypted squashfs is mounted at: [${MNT_ROOTFS}] (device=/dev/mapper/crypt_liveiso)"
|
||||
|
||||
printf "\e[92m[INFO] Encrypted squashfs is mounted at: [%s] (device=/dev/mapper/crypt_liveiso) \n\e[0m" "${MNT_ROOTFS}"
|
||||
export CISS_ROOT_DEV="/dev/mapper/crypt_liveiso"
|
||||
export CISS_ROOT_DIR=""
|
||||
|
||||
log "Decrypted root device exposed at [/run/ciss-rootdev] -> [/dev/mapper/crypt_liveiso]"
|
||||
|
||||
printf "\e[92m[INFO] Decrypted root device exposed at: [/run/ciss-rootdev] -> [/dev/mapper/crypt_liveiso] \n\e[0m"
|
||||
|
||||
printf "\e[92m[INFO] Successfully applied: [/usr/lib/live/boot/0024-ciss-crypt-squash] \n\e[0m"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user