[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#459632: initramfs-tools: Unable to detect LVM correctly if root device does not match /dev/mapper/*



Ok sorry about that, the thing is "redhat name scheme" didn't mean a thing to 
me so I figured the bug has not been reported already.

Here is the solution I've tested :

First patch set : hook-functions and mkinitramfs are modified in order to 
detect the symlink between /dev/vg/lv -> /dev/mapper/vg-lv and include the 
required lvm script in the ramdisk.

Second patch set : lvm and lvm2 scripts do a little bit more tests before 
giving up on lvm activation. If the device does not look like a /dev/mapper/* 
file it converts the root from /dev/vg/lv to /dev/mapper/vg-lv. If things 
looks ok, tests activation with vgchange -t (test mode). If things are ok, 
activates the volume group the usual way.

I've tested this solution using a /dev/lvm/root entry in mtab and 
root=/dev/lvm/root in kernel command line and it's working.

I think the changes should not break anything else. I'm sure you will give my 
small work a check.

Thank you.

Jerome

On Monday 07 January 2008, you wrote:
> On Mon, Jan 07, 2008 at 07:42:49PM +0100, Jerome Vizcaino wrote:
> > The thing is, when detecting the root filesystem device, the script
> > should check if the device is a link and if so, check if the target is of
> > the form /dev/mapper/*
> >
> > Changing the root filesystem to /dev/mapper/lvm-root solved the problem
> > (after I wasted about an hour).
>
> duplicate bug report explained in many other already,
> check out for rh lvm naming scheme and propose a solution.
>
> closing as no usefull info.


--- /usr/share/initramfs-tools/hook-functions.orig	2008-01-07 23:40:30.000000000 +0100
+++ /usr/share/initramfs-tools/hook-functions	2008-01-07 23:46:50.000000000 +0100
@@ -223,7 +223,10 @@
 
 	# findout root block device + fstype
 	eval "$(mount | awk '/ \/ / {print "root=" $1 "\nFSTYPE=" $5; exit}')"
-
+	
+	# If root device is a link, get the real device instead
+	[ -h "$root" ] && [ -h "$root" ] && root=$(readlink "$root")
+	
 	# find out real rootfs on auto type
 	if [ "${FSTYPE}" = "auto" ]; then
 		eval "$(/usr/lib/klibc/bin/fstype ${root})"
--- /usr/sbin/mkinitramfs.orig	2008-01-07 23:48:48.000000000 +0100
+++ /usr/sbin/mkinitramfs	2008-01-07 23:49:34.000000000 +0100
@@ -258,6 +258,9 @@
 	mv ${DESTDIR}/bin/sh.shared ${DESTDIR}/bin/sh
 	# those root need busybox
 	eval "$(mount | awk '/ \/ / {print "r_dev=" $1; exit}')"
+	# root device is a symlink, get the real device
+	[ -h "$r_dev" ] && r_dev=$(readlink "$r_dev")
+
 	if [ "${r_dev#/dev/mapper/}" != "${r_dev}" ] \
 		|| [ "${r_dev#/dev/md}" != "${r_dev}" ]; then
 		echo "Warning: Busybox is required for successful boot!"
--- /usr/share/initramfs-tools/scripts/local-top/lvm2.orig	2008-01-08 00:01:06.000000000 +0100
+++ /usr/share/initramfs-tools/scripts/local-top/lvm2	2008-01-08 22:00:06.000000000 +0100
@@ -37,10 +37,32 @@
 		;;
 	esac
 
+	# Make sure root device is not a symlink
+	[ -h "$vg" ] && vg=$(readlink "$vg")
 	# Make sure that we have a d-m path
 	vg=${vg#/dev/mapper/}
 	if [ "$vg" = "$1" ]; then
-		return 1
+		# Convert RedHat name /dev/vg/lv to /dev/mapper/vg-lv
+		vg=$(echo $vg | sed -e 's#\(.*\)/\([^/]*\)/\(.*\)$#\1/mapper/\2-\3#')
+		# Check if it looks valid
+		if [ "${vg#/dev/mapper/}" = "$vg" ]; then
+			return 1;
+		fi
+		# Remove /dev/mapper
+		vg=${vg#/dev/mapper/}
+	   # Split volume group from logical volume.
+		local test_vg=$(echo ${vg} | sed -e 's#\(.*\)\([^-]\)-[^-].*#\1\2#')
+		# Reduce padded --'s to -'s
+		test_vg=$(echo ${test_vg} | sed -e 's#--#-#g')
+		# Test if it's a valid LVM volume group
+		# This does not activate it, if everything is ok
+		# activation will be done later.
+		vgchange -ay -t $test_vg
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+		# Everything looks fine, vg is in the expected
+		# form for proper script completion
 	fi
 
 	# Make sure that the device includes at least one dash
--- /usr/share/initramfs-tools/scripts/local-top/lvm.orig	2008-01-08 00:01:04.000000000 +0100
+++ /usr/share/initramfs-tools/scripts/local-top/lvm	2008-01-08 22:00:44.000000000 +0100
@@ -37,10 +37,32 @@
 		;;
 	esac
 
+	# Make sure root device is not a symlink
+	[ -h "$vg" ] && vg=$(readlink "$vg")
 	# Make sure that we have a d-m path
 	vg=${vg#/dev/mapper/}
 	if [ "$vg" = "$1" ]; then
-		return 1
+		# Convert RedHat name /dev/vg/lv to /dev/mapper/vg-lv
+		vg=$(echo $vg | sed -e 's#\(.*\)/\([^/]*\)/\(.*\)$#\1/mapper/\2-\3#')
+		# Check if it looks valid
+		if [ "${vg#/dev/mapper/}" = "$vg" ]; then
+			return 1;
+		fi
+		# Remove /dev/mapper
+		vg=${vg#/dev/mapper/}
+	   # Split volume group from logical volume.
+		local test_vg=$(echo ${vg} | sed -e 's#\(.*\)\([^-]\)-[^-].*#\1\2#')
+		# Reduce padded --'s to -'s
+		test_vg=$(echo ${test_vg} | sed -e 's#--#-#g')
+		# Test if it's a valid LVM volume group
+		# This does not activate it, if everything is ok
+		# activation will be done later.
+		vgchange -ay -t $test_vg
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+		# Everything looks fine, vg is in the expected
+		# form for proper script completion
 	fi
 
 	# Make sure that the device includes at least one dash

Reply to: