Bug#568838: lvm2: initramfs-tools/scripts/local-top/lvm2 does not wait to detect LVM on devices that need time to appear

StalkR debian-reportbug at stalkr.net
Fri Feb 19 23:20:29 UTC 2010

Package: lvm2
Version: 2.02.54-1
Severity: normal

On my embedded system the root filesystem is on an LVM volume on an SD card.

On a lucky day, the SD card gets recognized soon enough and scripts/local-top/lvm2 achieves to activate logical volume so that the root filesystem can be mounted.

The other days, the SD card does not get recognized soon enough and scripts/local-top/lvm2 fails to activate logical volume (volume group cannot be found), then scripts/local:pre_mountroot() complains that rootfs cannot be found and ironically waits ROOTDELAY for the rootfs to appear... but this cannot happen since lvm2 only is responsible for volume activation.

Just as in pre_mountroot(), I suggest to wait for the logical volume to appear. I attached a patch with a working solution: it scans with lvscan until the logical volume appears or until ROOTDELAY is reached. Note that in case detection fails after ROOTDELAY it does not return and it still tries to activate volume in order to inform the user with the error (unable to find LVM volume).

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: armel (armv5tel)

Kernel: Linux
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages lvm2 depends on:
ii  dmsetup                      2:1.02.39-1 The Linux Kernel Device Mapper use
ii  libc6                        2.10.2-6    Embedded GNU C Library: Shared lib
ii  libdevmapper1.02.1           2:1.02.39-1 The Linux Kernel Device Mapper use
ii  libgcc1                      1:4.4.3-1   GCC support library
ii  libreadline5                 5.2-7       GNU readline and history libraries
ii  lsb-base                     3.2-23      Linux Standard Base 3.2 init scrip

lvm2 recommends no packages.

lvm2 suggests no packages.

-- no debconf information
-------------- next part --------------
--- /usr/share/initramfs-tools/scripts/local-top/lvm2	2009-08-17 19:28:09.000000000 +0200
+++ /usr/share/initramfs-tools/scripts/local-top/lvm2	2010-02-19 23:22:14.000000000 +0100
@@ -45,12 +45,30 @@
 	eval $(dmsetup splitname --nameprefixes --noheadings --rows "$dev")
-	if [ "$DM_VG_NAME" ] && [ "$DM_LV_NAME" ]; then
-		lvm lvchange -aly --ignorelockingfailure "$DM_VG_NAME/$DM_LV_NAME"
-		rc=$?
-		if [ $rc = 5 ]; then
-			echo "Unable to find LVM volume $DM_VG_NAME/$DM_LV_NAME"
-		fi
+	# Make sure that we have non-empty volume group and logical volume
+	if [ -z "$DM_VG_NAME" ] || [ -z "$DM_LV_NAME" ]; then
+		return 1
+	fi
+	# If the logical volume hasn't shown up yet, give it a little while
+	# to deal with LVM on removable devices (inspired from scripts/local)
+	fulldev="/dev/$DM_VG_NAME/$DM_LV_NAME"
+	if [ -z "`lvm lvscan -a --ignorelockingfailure |grep $fulldev`" ]; then
+		# Use default root delay
+		slumber=$(( ${ROOTDELAY:-180} * 10 ))
+		while [ -z "`lvm lvscan -a --ignorelockingfailure |grep $fulldev`" ]; do
+			/bin/sleep 0.1
+			slumber=$(( ${slumber} - 1 ))
+			[ ${slumber} -gt 0 ] || break
+		done
+	fi
+	# Activate logical volume
+	lvm lvchange -aly --ignorelockingfailure "$DM_VG_NAME/$DM_LV_NAME"
+	rc=$?
+	if [ $rc = 5 ]; then
+		echo "Unable to find LVM volume $DM_VG_NAME/$DM_LV_NAME"

More information about the pkg-lvm-maintainers mailing list