#!/bin/sh
#
# Sample /linuxrc script for an init-ramdisk to be used for activating EVMS
# volumes. See the INSTALL.initrd file in the EVMS package for instructions
# on creating an init-ramdisk image to use with this script.

PATH="/bin:/sbin:/usr/bin:/usr/sbin"

# Mount /proc.
echo "/linuxrc: Mounting /proc"
mount -t proc none /proc


# Mount /sys if a 2.6 kernel is running.
grep sysfs /proc/filesystems > /dev/null 2>&1
if [ $? -eq 0 ]; then
	echo "/linuxrc: Mounting /sys"
	mount -t sysfs none /sys
fi


# Mount devfs
# You should uncomment these two lines if you are running devfs but do not
# have the kernel automatically mount it on /dev.
# mount -t devfs none /dev
# mounted_devfs=1


# Run the devfs deamon, if devfs is present.
if [ -e /dev/.devfsd ]; then
	echo "/linuxrc: Running devfsd"
	devfsd /dev
fi


# Load modules
#
# By default, the sample init-ramdisk does not contain any kernel modules.
# It assumes that the kernel contains static support necessary to run all
# the tools on the init-ramdisk.
#
# If you compiled kernel features as modules that you will need during the
# init-ramdisk, you need to copy those modules to the init-ramdisk in the
# /lib/modules/ directory. You also need to add appropriate commands below
# to load those modules. The modules should be loaded before running EVMS.
#
# Some examples are provided here. If you didn't install any kernel modules,
# simply leave these commented-out.
#
# NOTE: The version of insmod used by Busybox is not yet compatible with the
#       new 2.6 kernel module format. If you are running a 2.6 kernel and
#       want to load modules from this initrd, you will need to copy your
#       systems version of "insmod" to this initrd.
#
# Device-Mapper modules
# insmod dm-mod
# insmod dm-mirror
# insmod dm-bbr
# insmod dm-sparse
#
# MD/Software-RAID modules
# insmod md
# insmod linear
# insmod raid0
# insmod raid1
# insmod xor
# insmod raid5
# insmod multipath


# Get the EVMS root volume name from the kernel command line. 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 "Configuring Your Boot-Loader" in
# the INSTALL file in the EVMS package.
for name in `cat /proc/cmdline`; do
	echo $name | grep '^root=' > /dev/null
	if [ $? -eq 0 ]; then
		vol=`expr "$name" : '.*=\(.*\)'`
		break
	fi
done


# Activate EVMS volumes.
echo "/linuxrc: Running evms_activate"
if [ -n "$vol" ]; then
	# Get the device number for the root volume and set the
	# kernel's root-device.
	dev=`evms_activate -q --devnum $vol`
	echo "/linuxrc: Setting root device to: $vol: $dev"
	echo $dev > /proc/sys/kernel/real-root-dev
else
	# Don't have the root volume name - activate the volumes anyway.
	evms_activate
fi


# Stop the devfs daemon
if [ -e /dev/.devfsd ]; then
	echo "/linuxrc: Stopping devfsd"
	killall devfsd
fi


# Unmount devfs (if we manually mounted above).
if [ -n "$mounted_devfs" ]; then
	umount /dev
fi


# Unmount /sys
grep sysfs /proc/mounts > /dev/null 2>&1
if [ $? -eq 0 ]; then
	echo "/linuxrc: Unmounting /sys"
	umount /sys
fi


# Unmount /proc
echo "/linuxrc: Unmounting /proc"
umount /proc

