]> git.pld-linux.org Git - projects/geninitrd.git/commitdiff
Resolve /dev/dm-0 to LVM names (/dev/sys/rootfs) which we get when using LABEL or...
authorElan Ruusamäe <glen@pld-linux.org>
Fri, 20 Oct 2006 16:05:26 +0000 (16:05 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Fri, 20 Oct 2006 16:05:26 +0000 (16:05 +0000)
svn-id: @7883

geninitrd

index d89a1aa4eb98c531e1a1fc83bef9df48ab93e039..1c2b099c51ff4a53356e033deed326f4e813ff37 100755 (executable)
--- a/geninitrd
+++ b/geninitrd
@@ -306,7 +306,7 @@ find_root() {
                                exit 1
                        fi
                        uuid=${rootdev#"UUID="}
-                       for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
+                       for dev in $(awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions); do
                                if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
                                        if [ -n "$verbose" ] ; then
                                                echo "Using $dev as device for rootfs"
@@ -510,6 +510,31 @@ find_modules_ide() {
        fi
 }
 
+# resolve /dev/dm-0 to lvm2 node
+# which they got from /proc/partitions when rootfs is UUID=
+_lvm2_node_resolve() {
+       local node="$1"
+
+       # redirect output to tmpfile so we won't get subshell
+       local tmp ret
+       tmp=$(mktemp) || exit 1
+
+       lvdisplay -c 2>/dev/null|awk -F: '{print $1}' > $tmp
+       while read dev; do
+               count=$(ls -Ll $dev $node | awk '{print $5, $6}' | sort -u | wc -l)
+               if [ "$count" = 1 ]; then
+                       ret="$dev"
+                       break
+               fi
+       done < $tmp
+       rm -f $tmp
+
+       if [ -z "$ret" ]; then
+               ret=$node
+       fi
+       echo "$ret"
+}
+
 # return true if node is lvm node
 _check_lvm() {
        local node="$1"
@@ -528,6 +553,7 @@ _check_lvm() {
                return 0
        fi
 
+       node=$(_lvm2_node_resolve $node)
        /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
        rc=$?
        if [ $rc -gt 127 ]; then
@@ -548,8 +574,9 @@ find_modules_for() {
        if [ -z "$1" ]; then
                echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
                exit
+       fi
 
-       elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
+       if is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
                if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
                        echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
                        echo "Please install correct pci-database package and rerun $0." >&2
@@ -614,6 +641,8 @@ find_modules_for() {
                findmodule "-$loopFs"
                BASICMODULES="$BASICMODULES -${loopFs}"
        elif _check_lvm "$1"; then
+               node=$(_lvm2_node_resolve "$1")
+
                if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
                        echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
                        echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
@@ -628,7 +657,7 @@ find_modules_for() {
                        fi
                fi
                if [ -z "$PVDEVICES" ] ; then
-                       VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
+                       VGVOLUME=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
                        PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
                fi
                if [ -n "$PVDEVICES" ] ; then
@@ -1329,6 +1358,7 @@ initrd_gen_lvm() {
                echo "umount /dev" >> "$s"
                echo "umount /proc" >> "$s"
        else
+               org_rootdev=$(_lvm2_node_resolve "$org_rootdev")
                echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
                echo "global {" > "$MNTIMAGE/etc/lvm.conf"
                echo "  locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
This page took 0.281156 seconds and 4 git commands to generate.