@@ -430,36 +430,58 @@ mountroot() {
430430 # Make sure the device has been created by udev before we try to mount
431431 udevadm settle
432432
433- # find the right partition
434- for partname in $partlist ; do
435- part=$( find /dev -name $partname | tail -1)
436- [ -z " $part " ] && continue
437- path=$( readlink -f $part )
438- [ -n " $path " ] && break
439- done
433+ # Check for LVM volume group in kernel cmdline and activate LVM
434+ vg=" "
435+ if grep -q lvm_vg= /proc/cmdline; then
436+ for x in $( cat /proc/cmdline) ; do
437+ case ${x} in
438+ lvm_vg=* )
439+ vg=${x#* =}
440+ ;;
441+ esac
442+ done
443+ fi
440444
441- # On systems with A/B partition layout, current slot is provided via cmdline parameter.
442- ab_slot_suffix=$( grep -o ' androidboot\.slot_suffix=..' /proc/cmdline | tail -1 | cut -d " =" -f2)
443- if [ -z " $path " ] && [ ! -z " $ab_slot_suffix " ] ; then
444- tell_kmsg " Searching for A/B data partition on slot $ab_slot_suffix ."
445+ # Activate LVM volume groups if present
446+ if [ -n " $vg " ]; then
447+ tell_kmsg " Activating LVM volume groups"
448+ lvm vgscan --mknodes
449+ lvm vgchange -ay
450+
451+ if [ -n " $vg " ]; then
452+ # Check if the volume group actually exists
453+ if lvm vgs " $vg " > /dev/null 2>&1 ; then
454+ tell_kmsg " Volume group $vg found"
455+ else
456+ tell_kmsg " WARNING: Volume group $vg specified but not found"
457+ vg=" "
458+ fi
459+ fi
460+ fi
445461
462+ # First check if LVM volume group has userdata
463+ if [ -n " $vg " ] && [ -e " /dev/$vg /userdata" ]; then
464+ tell_kmsg " Using LVM userdata volume at /dev/$vg /userdata"
465+ path=" /dev/$vg /userdata"
466+ else
467+ # Find the right partition for userdata
446468 for partname in $partlist ; do
447- part=$( find /dev -name " $partname$ab_slot_suffix " | tail -1)
469+ part=$( find /dev -name $partname | tail -1)
448470 [ -z " $part " ] && continue
449471 path=$( readlink -f $part )
450472 [ -n " $path " ] && break
451473 done
452- fi
453474
454- # override with a possible cmdline parameter
455- if grep -q datapart= /proc/cmdline; then
456- for x in $( cat /proc/cmdline) ; do
457- case ${x} in
458- datapart=* )
459- path=${x#* =}
460- ;;
461- esac
462- done
475+ # Override with a possible cmdline parameter
476+ if grep -q datapart= /proc/cmdline; then
477+ for x in $( cat /proc/cmdline) ; do
478+ case ${x} in
479+ datapart=* )
480+ path=${x#* =}
481+ ;;
482+ esac
483+ done
484+ fi
463485 fi
464486
465487 if [ -z " $path " ]; then
@@ -517,6 +539,16 @@ mountroot() {
517539 fi
518540 fi
519541
542+ # Override systempart with LVM rootfs if volume group is provided
543+ if [ -n " $vg " ] && [ -e " /dev/$vg /rootfs" ]; then
544+ tell_kmsg " Overriding systempart with LVM rootfs at /dev/$vg /rootfs"
545+ _syspart=" /dev/$vg /rootfs"
546+ # Keep existing options if they were set, otherwise use rw
547+ if [ -z " $_syspart_options " ]; then
548+ _syspart_options=rw
549+ fi
550+ fi
551+
520552 # We need to add the slot suffix to $_syspart for A/B devices
521553 if [ -n " $_syspart " ] && [ ! -e " $_syspart " ] && [ ! -z " $ab_slot_suffix " ]; then
522554 tell_kmsg " A/B slot system detected! Slot suffix is $ab_slot_suffix "
0 commit comments