From 0cee55d5a1b60cc67a623f0b107a950633ed72fc Mon Sep 17 00:00:00 2001 From: Jybz Date: Sat, 20 Apr 2024 22:22:14 +0200 Subject: Updated to support encrypted persistent partition and fix mga#25924. - origin: https://svnweb.mageia.org/packages/cauldron/dracut/current/SOURCES/0511-mgalive-A-module-to-mount-Mageia-Live-media.patch?r1=1368035&r2=1469756 - mgalive: support encrypted persistent partitions (mga#25191) - mgalive: fix boot failure on some machines (mga#25924) --- modules.d/90mgalive/mgalive-root.sh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'modules.d') diff --git a/modules.d/90mgalive/mgalive-root.sh b/modules.d/90mgalive/mgalive-root.sh index 9d3f86a..8991749 100755 --- a/modules.d/90mgalive/mgalive-root.sh +++ b/modules.d/90mgalive/mgalive-root.sh @@ -2,6 +2,12 @@ . /lib/dracut-lib.sh +can_decrypt=0 +if [ -f /lib/dracut-crypt-lib.sh ] ; then + . /lib/dracut-crypt-lib.sh + can_decrypt=1 +fi + [ -f /tmp/root.info ] && . /tmp/root.info PATH=/usr/sbin:/usr/bin:/sbin:/bin @@ -21,6 +27,19 @@ basedev=$(echo $livedev | sed -e 's,\(/dev/sd[a-z]\)1,\1,g' -e 's,\(/dev/mmcblk[ # Make it available to draklive-install and mgalive-shutdown echo $basedev > /run/mgalive/basedev +# Unlock any encrypted partitions on the base device +if [ $can_decrypt -eq 1 ] ; then + for dev in $(blkid -t TYPE=crypto_LUKS -o device | grep $basedev) ; do + ask_for_password \ + --ply-cmd "cryptsetup open -T1 $dev crypt_${dev##/dev/}" \ + --ply-prompt "Password ($dev)" \ + --ply-tries 3 \ + --tty-cmd "cryptsetup open -T3 $dev crypt_${dev##/dev/}" \ + --tty-tries 1 + done +fi + + # Get the base directory for locating the loopback file. In normal use this is # the root directory, but a multi-boot USB stick may want to override this. basedir=$(getarg mgalive.basedir) @@ -30,7 +49,7 @@ basedir=$(getarg mgalive.basedir) # stick may want to override this. overlay=$(getarg mgalive.overlay) if [ -z "$overlay" ] ; then - overlay=$(blkid -t LABEL=mgalive-persist -o device | grep $basedev) + overlay=$(blkid -t LABEL=mgalive-persist -o device | grep $basedev'\|'/dev/mapper) else overlay=$livedev$overlay fi @@ -41,7 +60,8 @@ info "mgalive basedir is $basedir/" info "mgalive overlay is $overlay" media=$livedev -if [ -z "$(blkid $livedev)" ] ; then +ps=$(partx -go START $livedev) +if [ $ps -ne 0 ] ; then if strstr "$(blkid $basedev)" "iso9660" ; then # This happens when we boot from a USB stick with a isohybrid partition # scheme where the first sector is unclaimed, so the first partition starts @@ -53,7 +73,6 @@ if [ -z "$(blkid $livedev)" ] ; then # If we mount the raw device, we can't then also mount a partition # on that device. So to enable persistence, we need to extend the # first partition to claim the full range of the iso9660 filesystem. - ps=$(partx -go START $livedev) pe=$(partx -go END $livedev) if [ $ps -eq 1 ] ; then info "Extending $livedev to cover sector 0" -- cgit v1.2.1