Skip to content

Commit 3b3d4f7

Browse files
committed
Add LVM volume group support if lvm_vg= is specified
Support LVM-backed userdata and rootfs partitions via lvm_vg= cmdline parameter. Activate LVM early in boot process and check for volumes in the specified volume group. If found, /dev/$vg/userdata is used for userdata and /dev/$vg/rootfs overrides any systempart= setting.
1 parent d33d262 commit 3b3d4f7

File tree

4 files changed

+57
-23
lines changed

4 files changed

+57
-23
lines changed

build-initrd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ done
4747
[ -z $OUT ] && OUT=./out
4848

4949
# list all packages needed for halium's initrd here
50-
[ -z $INCHROOTPKGS ] && INCHROOTPKGS="initramfs-tools dctrl-tools dmsetup e2fsprogs libc6-dev zlib1g-dev libssl-dev busybox-static parse-android-dynparts"
50+
[ -z $INCHROOTPKGS ] && INCHROOTPKGS="initramfs-tools dctrl-tools dmsetup e2fsprogs libc6-dev lvm2 zlib1g-dev libssl-dev busybox-static parse-android-dynparts"
5151

5252
BOOTSTRAP_BIN="qemu-debootstrap --arch $ARCH --variant=minbase"
5353

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Depends: initramfs-tools,
1313
coreutils,
1414
busybox-static,
1515
e2fsprogs,
16+
lvm2,
1617
${misc:Depends}
1718
Description: tools for mounting an Ubuntu Touch rootfs
1819
This package contains the scripts to boot an Ubuntu Touch device.

hooks/halium

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ copy_exec /bin/chown /bin
2626
copy_exec /bin/mount /bin
2727
copy_exec /sbin/dmsetup /sbin
2828
copy_exec /sbin/dumpe2fs /sbin
29+
copy_exec /sbin/lvm /sbin
2930
copy_exec /lib/$DEB_HOST_MULTIARCH/libz.so.1
3031
copy_exec /usr/lib/$DEB_HOST_MULTIARCH/libcrypto.so
3132
copy_exec /usr/lib/$DEB_HOST_MULTIARCH/libdl.so

scripts/halium

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)