]> git.pld-linux.org Git - projects/geninitrd.git/blobdiff - mod-lvm.sh
Mount rootfs from initramfs with rootfsflags options.
[projects/geninitrd.git] / mod-lvm.sh
index e6841c0ae98a220595f63f24756f9410f57a02c5..0e33c6c10f1af4b6ac11fb2606c7b3d536267de5 100644 (file)
@@ -36,7 +36,7 @@ setup_mod_lvm() {
        if is_yes "$USE_LVM" && [ -z "$LVMTOOLSVERSION" ]; then
                LVMTOOLSVERSION=$(LC_ALL=C $lvm vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
                if [ -z "$LVMTOOLSVERSION" ]; then
-                       die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
+                       die "Can't determine LVM tools version (is /sys mounted?). Please set LVMTOOLSVERSION and rerun $PROGRAM."
                fi
        fi
 }
@@ -117,6 +117,10 @@ find_modules_lvm() {
 # generate initrd fragment for lvm
 # @access      public
 initrd_gen_lvm() {
+       if ! is_yes "$have_lvm"; then
+               return
+       fi
+
        debug "Adding LVM support to initrd"
        inst_d /tmp /newroot
        inst_exec $lvm /bin/lvm.static
@@ -180,12 +184,31 @@ initrd_gen_lvm() {
                        export ROOTVG="$VGVOLUMES"
                        export SUSPENDVG=$SUSPENDVG
                EOF
+
+               # need awk for "s/--/-/g" subst when parsing kernel root commandline
+               busybox_applet awk
                add_linuxrc <<-'EOF'
                        # parse rootdev from kernel commandline if it begins with /
                        case "$ROOT" in
                                /*)
+
+                               # rewrite:
+                               # /dev/mapper/sys-rootfs -> /dev/sys/rootfs
+                               # /dev/mapper/blodnatt-blah--bleh -> /dev/blodnatt/blah-bleh
+                               # /dev/mapper/vg--meaw-root -> /dev/vg-meaw/root
+                               case "$ROOT" in
+                                       /dev/mapper/*-*)
+                                               # change "--" to / (as "/" is impossible in LV name)
+                                               local dev=$(awk -vdev="${ROOT#/dev/mapper/}" 'BEGIN{gsub(/--/, "/", dev); print dev}')
+                                               local VG=$(awk -vdev="$dev" 'BEGIN{split(dev, v, "-"); gsub("/", "-", v[1]); print v[1]}')
+                                               local LV=$(awk -vdev="$dev" 'BEGIN{split(dev, v, "-"); gsub("/", "-", v[2]); print v[2]}')
+                                               ROOT=/dev/$VG/$LV
+                                       ;;
+                               esac
+
                                if [ "$ROOT" != "$ROOTDEV" ]; then
                                        ROOTDEV=$ROOT
+
                                        echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
                                        local tmp=${ROOTDEV#/dev/}
                                        if [ "$tmp" != "$ROOTDEV" ]; then
@@ -233,11 +256,6 @@ initrd_gen_lvm() {
                        if [ "$major" -a "$minor" ]; then
                                # Pass it to kernel
                                echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
-                       else
-                               echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
-                               echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
-                               echo 2>&1 ""
-                               sh
                        fi
                EOF
        fi
This page took 0.030067 seconds and 4 git commands to generate.