#!/bin/sh

# evms.linuxrc, Matt Zimmerman <mdz@debian.org>
# Based on doc/linuxrc from the EVMS 2.0.0 distribution

mount -nt proc proc proc

# Get the EVMS root volume name from the kernel command line,
# translate to a device number, and set the kernel's root device. In
# order for this to work correctly, "root=/dev/evms/Root_Volume_Name"
# needs to be passed to the kernel command line (where
# Root_Volume_Name is replaced by your actual root volume's name. See
# the section about LILO and Grub in the INSTALL.initrd file.

for param in $(cat /proc/cmdline); do
    case "$param" in
        root=/dev/evms/*)
            vol=${param#root=}
            break
            ;;
    esac
done

if [ -n "$vol" ]; then
    # Activate EVMS volumes.
    modprobe -k dm-mod
    /sbin/evms_activate

    if ! stat -L -c "%t %T" $vol | read major minor; then
        echo "Unable to determine device number for EVMS root volume!"
    else
        dev=$(($major << 8 + $minor))
        echo $dev > /proc/sys/kernel/real-root-dev
    fi
fi

umount -n proc
