Bug#678687: initramfs scripts fail with LABEL= or UUID=

Rodolfo García Peñas kix at debian.org
Sat Nov 2 17:03:42 UTC 2013


Hi,

I think I have a patch. Could you try it? I am not using LVM.

I added a new function in the initramfs script, to change the device given to a /dev/mapper device (if exists), so now LVM can boot the resume partition independently if is /dev/mapper/x /dev/dm-x or /dev/otherthing. This patch supports UUID and LABEL devices, the script translate it to /dev device.

I changed the severity to critical because if LVM cannot handle other devices names than /dev/mapper and the image is stored in /dev/dm-x, the system cannot boot. The user needs edit the boot configuration and set the flag "noresume", else the system won't boot forever.

Cheers,
kix
-- 
 .''`.  Rodolfo García Peñas (kix) <kix at debian.org>
: :'  : Proud Debian Developer
`. `'`  4096R / 3F48 0B8C C385 AD41 9E28  006A 7B1F 5490 72B7 4923
 `-     Debian - when you have better things to do than fixing systems
-------------- next part --------------
#!/bin/sh -x

PREREQ="mdadm mdrun multipath"

prereqs()
{
	echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
esac

label_to_dev()
{
	local dev="$1"

	local link1
	local link2

	if [ -d /dev/disk/by-label ]; then
		dev="${dev#LABEL=}"
		if [ "$dev" != "$1" ]; then
			link1="/dev/disk/by-label/"${dev}
			if [ -e $link1 ]; then
				link2=$(readlink -f "$link1")
				echo $link2
				return 0
			fi
		fi
	fi
	
	return 1
}

uuid_to_dev()
{
	local dev="$1"

	local link1
	local link2

	if [ -d /dev/disk/by-uuid ]; then
		dev="${dev#UUID=}"
		if [ "$dev" != "$1" ]; then
			link1="/dev/disk/by-uuid/"${dev}
			if [ -e $link1 ]; then
				link2=$(readlink -f "$link1")
				echo $link2
				return 0
			fi
		fi
	fi
	
	return 1
}

# Get the /dev/mapper device for a /dev given
device_to_mapper()
{
	local dev="$1"

	local link1
	local link2
	local path

	if [ -d /dev/mapper ]; then
		link1=$(readlink -f "$dev")

		for path in /dev/mapper/*; do
			link2=$(readlink -f "$path")
			if [ "$link1" = "$link2" ]; then
				echo "$path"
				return 0
			fi
		done
	fi

	return 1
}

activate_vg()
{
	local dev="$1"
	local ndev

	# Make sure that we have a non-empty argument
	if [ -z "$dev" ]; then
		return 1
	fi

	# Take care of lilo boot arg, risky activating of all vg
	case "$dev" in
	fe[0-9]*)
		lvm vgchange -aly --ignorelockingfailure
		exit 0
		;;
	# FIXME: check major
	/dev/root)
		lvm vgchange -aly --ignorelockingfailure
		exit 0
		;;
	esac

	# Make sure that we have a d-m path
	ndev=$(label_to_dev "$dev")
	if [ $? = 0 ]; then
		dev=$ndev
	fi

	ndev=$(uuid_to_dev "$dev")
	if [ $? = 0 ]; then
		dev=$ndev
	fi

	ndev=$(device_to_mapper "$dev")
	if [ $? != 0 ]; then
		return 1
	fi

	eval $(dmsetup splitname --nameprefixes --noheadings --rows "$ndev")

	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
	fi
}

if [ ! -e /sbin/lvm ]; then
	exit 0
fi

modprobe -q dm-mod

activate_vg "$ROOT"
activate_vg "$resume"

exit 0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-lvm-maintainers/attachments/20131102/5bc02588/attachment.sig>


More information about the pkg-lvm-maintainers mailing list