Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
lvmcreate_initrd not working - solution for some...
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
shon
n00b
n00b


Joined: 21 Oct 2004
Posts: 2
Location: Poland

PostPosted: Thu Oct 21, 2004 7:54 pm    Post subject: lvmcreate_initrd not working - solution for some... Reply with quote

I just spend two days trying to make an RAID->LVM->root system (with many thanks to this topic).
The HOWTO works great, usually until you get to the wretched lvmcreate_initrd script.

it didn't work for me because of 2 reasons:
1. The easy one - I had lvm2 package emerged and it doesn't contain it. lvm-user does. Just to make things a little bit more complicated it's blocked by lvm2 and vice-versa so it is
Code:

emerge unmerge lvm2
emerge lvm-user

do your stuff (below) and later if you want to get back to lvm2 (i want!) do
Code:

emerge unmerge lvm-user
emerge lvm2

okay, that was the easy part, now the hard part
2. for me the lvmcreate_initrd didn't work because of this:

cp: cannot stat `(0xffffe000)': No such file or directory

what the hell? okay, here's what happens. The wretched script tries to use ldd to guess what libraries does it need on the ramdisk. when it checks /sbin/vgchange it gives him a strange linux-gate.so.1 => (0xffffe000) thing, which apparently is not a link to a library (it doesn't point to anything after "=>") but some kernel part (!!??), at least according to this and this.
So what do we do? I took the easy way - modify the damn lvmcreate_initrd so it doesn't try to find this thing, just go about it's normal way. here's the modified script:
Code:

#!/bin/sh
#
#  Copyright (C) 1997 - 2000  Heinz Mauelshagen, Sistina Software
#
#  June 1999
#  December 1999
#  January 2000
#  January 2001
#
#  LVM is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  LVM is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with LVM; see the file COPYING.  If not, write to
#  the Free Software Foundation, 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.
#

#
# Changelog
#
#   16/11/1999 - corrected -N type with mke2fs
#   19/12/1999 - use correct ramdisk size
#                strip shared library to save space
#   04/01/2000 - support /proc mount, because lvm_dir_cache now uses it
#   12/02/2001 - always create enough inodes in ramdisk for dev files
#   [AED]      - check all INITRDFILES for library dependencies
#              - make commands quiet and avoid redirecting errors to /dev/null
#              - use cleanup function for all errors, interrupts, normal exit
#   12/02/2001 - copy and strip shared libraries before putting on ramdisk
#   [AED]      - allow specification of /dev directory (in case of devfs)
#              - calculate ramdisk size from libraries, devices, INITRDFILES
#              - add verbose progress messages
#              - copy actual executables if we are using wrapper scripts
#   12/02/2001 - support monolithic kernels
#   14/02/2001 - add usage and command-line switches. Lots of other changes
#              - from Andreas Dilger
#   05/04/2001 - Ignore errors from depmod because we might be a monolithic
#                kernel
#   10/31/2001 - Added devfs support
#


cmd=`basename $0`

TMPMNT=/tmp/mnt.$$
TMPLIB=/tmp/lib.$$
USEMOD=1

PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH

usage () {
   echo "Create an initial ramdisk image for LVM root filesystem"
   echo "$cmd: [-h] [-i] [-M] [-v] [-V] [kernel version]"
   echo "      -h|--help     print this usage message"
   echo "      -i|--iop      specify LVM IOP version to use"
   echo "      -M|--nomod    do not set up module support in initrd"
   echo "      -D|--devfs    force use of devfs"
   echo "      -v|--verbose  verbose progress messages"
   echo "      -V|--version  print script version and exit"
}

verbose () {
   [ "$VERBOSE" ] && echo "`echo $cmd | tr '[a-z0-9/_]' ' '` -- $1" || true
}

cleanup () {
  [ "`mount | grep $DEVRAM`" ] && verbose "unmounting $DEVRAM" && umount $DEVRAM
  [ -f $DEVRAM ] && verbose "removing $DEVRAM" && rm $DEVRAM
  [ -d $TMPMNT ] && verbose "removing $TMPMNT" && rmdir $TMPMNT
  [ -d $TMPLIB ] && verbose "removing $TMPLIB" && rm -r $TMPLIB
  verbose "exit with code $1"
  exit $1
}

trap "
  verbose 'Caught interrupt'
  echo 'Bye bye...'
  cleanup 1
" 1 2 3 15


create_fstab () {
   if [ $DEV ]; then
      cat << FSTAB > $TMPMNT/etc/fstab
/dev/ram   /      ext2   defaults   0   0
proc      /proc      proc   defaults   0   0
FSTAB
   else
      cat << FSTAB > $TMPMNT/etc/fstab
/dev/ram   /      ext2   defaults   0   0
proc      /proc      proc   defaults   0   0
devfs      /dev/      devfs   defaults   0   0
FSTAB
   fi
   chmod 644 $TMPMNT/etc/fstab
}

create_linuxrc () {
   echo "#!/bin/sh" > $TMPMNT/linuxrc
   [ "$LVMMOD" ] && echo "/sbin/modprobe $LVMMOD" >> $TMPMNT/linuxrc
   cat << LINUXRC >> $TMPMNT/linuxrc
/bin/mount /proc
/sbin/vgscan
/sbin/vgchange -a y
/bin/umount /proc
LINUXRC
   chmod 555 $TMPMNT/linuxrc
}

#
# Main
#
echo "Logical Volume Manager 1.0.7 by Heinz Mauelshagen  28/03/2003"

VERSION=`uname -r`

while [ $# -gt 0 ]; do
   case $1 in
   -h|--help) usage; exit 0;;
   -i|--iop) IOP=$2; shift;;
   -M|--nomod) USEMOD="";;
   -D|--devfs) DEV="";;
   -V|--version) exit 0;;
   -d|-v|--debug|--verbose) VERBOSE="y";;
   [2-9].[0-9]*.[0-9]*) VERSION=$1;;
   *) echo "$cmd -- invalid option '$1'"; usage; exit 0;;
   esac
   shift
done

INITRD=${INITRD:-"/boot/initrd-lvm-$VERSION.gz"}
MODULES=/lib/modules/$VERSION
DEVRAM=/tmp/initrd.$$
DEV=${DEV-"/dev"}

echo "$cmd -- make LVM initial ram disk $INITRD"
echo ""

# Try to see if we have devfsd running. At this point $DEV is either
# "/dev" (no devfs) or "" (devfs). If it is, reset $DEV.
if [ "$DEV" = "/dev" ] && [ -a /dev/.devfsd ]; then
   verbose "devfsd running, assuming -D."
   DEV=""
fi

# The size of the ramdisk is automatically calculated unless this is set
#INITRDSIZE=
INITRDFILES="/sbin/vgchange /sbin/vgscan /bin/bash /bin/mount /bin/umount /bin/sh /bin/rm"

if [ "$USEMOD" ]; then
   # Check for an LVM module, otherwise it must be compiled into the kernel
   if [ -r $MODULES/kernel/drivers/md/lvm-mod.o ]; then
      LVMMOD="lvm-mod"
      INITRDFILES="$INITRDFILES $MODULES/kernel/drivers/md/$LVMMOD.o"
   elif [ -r $MODULES/block/lvm-mod.o ]; then
      LVMMOD="lvm-mod"
      INITRDFILES="$INITRDFILES $MODULES/block/$LVMMOD.o"
   elif [ -r $MODULES/block/lvm.o ]; then
      LVMMOD="lvm"
      INITRDFILES="$INITRDFILES $MODULES/block/$LVMMOD.o"
   fi

   if [ -x "/sbin/modprobe" ]; then
      INITRDFILES="$INITRDFILES /sbin/modprobe"
   elif [ "$LVMMOD" ]; then
      echo "$cmd -- have $LVMMOD but not /sbin/modprobe."
      cleanup 1
   fi
   if [ -x "/sbin/insmod" ]; then
      INITRDFILES="$INITRDFILES /sbin/insmod"
   elif [ "$LVMMOD" ]; then
      echo "$cmd -- have $LVMMOD but not /sbin/insmod."
      cleanup 1
   fi
   if [ -r "$MODULES/modules.dep" ]; then
      INITRDFILES="$INITRDFILES $MODULES/modules.dep"
   fi
fi

# If we have LVM wrapper scripts in /sbin, we need to fix this by including
# the actual executables into the initrd as well.
if [ -x /sbin/lvmiopversion ]; then
   # Use the IOP version, if specified.  Otherwise, if we are building for
   # the current kernel or there is only one IOP version installed, use it.
   if [ "$IOP" ]; then
      IOP="/lib/lvm-iop$IOP"
   elif [ "$VERSION" = "`uname -r`" ]; then
      IOP="/lib/lvm-iop`lvmiopversion`"
   elif [ `ls -d /lib/lvm-iop* | wc -w` -eq 1 ]; then
      IOP="`ls -d /lib/lvm-iop*`"
   fi
   for FILE in $INITRDFILES; do
   case $FILE in
   /sbin/vg*|/sbin/lv*|/sbin/pv*)
      if [ "`file $FILE 2> /dev/null | grep script`" ]; then
         verbose "$FILE is a wrapper script, resolving."
         if [ -z "$IOP" ]; then
            echo "$cmd -- need to set LVM IOP for kernel $VERSION with '-i'."
            cleanup 1
         fi
         NEWFILE="$IOP/`basename $FILE`"
    if [ -x $NEWFILE ]; then
       INITRDFILES="$INITRDFILES $NEWFILE"
         else
       echo "$cmd -- can't find $NEWFILE, your initrd may not work."
    fi
      fi ;;
   esac
   done
   INITRDFILES="$INITRDFILES /sbin/lvmiopversion"
fi

# Figure out which shared libraries we actually need in our initrd
echo "$cmd -- finding required shared libraries"
verbose "INITRDFILES: `echo $INITRDFILES`"
SHLIBS=`ldd $INITRDFILES 2>/dev/null | awk '{if (/=>/) { print $3 }}' | sort -u`
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR figuring out needed shared libraries"
   exit 1
fi

verbose "need: `echo $SHLIBS`"

# Copy shared libraries to a temp directory before stripping, so that we don't
# run out of room on the ramdisk while stripping the libraries.
echo "$cmd -- stripping shared libraries"
mkdir $TMPLIB
for LIB in $SHLIBS; do
   if [ $LIB == "(0xffffe000)" ]; then
       continue
    fi
   verbose "copy $LIB to $TMPLIB$LIB"
   mkdir -p `dirname $TMPLIB$LIB`
   cp $LIB $TMPLIB$LIB
   if [ $? -ne 0 ]; then
      echo "$cmd -- ERROR copying shared library $LIB to ram disk"
      cleanup 1
   fi
   verbose "strip $TMPLIB$LIB"
   strip $TMPLIB$LIB
   if [ $? -ne 0 ]; then
      echo "$cmd -- ERROR stripping shared library $LIB"
      cleanup 1
   fi
done

# Calculate the number of inodes needed, and the size of the ramdisk image.
# Don't forget that inodes take up space too, as does the filesystem metadata.
echo "$cmd -- calculating initrd filesystem parameters"
verbose "counting files in: $DEV $TMPLIB \$INITRDFILES"
NUMINO="`find $DEV $TMPLIB $INITRDFILES | wc -w`"
verbose "minimum: $NUMINO inodes + filesystem reserved inodes"
NUMINO=`expr $NUMINO + 64`
if [ -z "$INITRDSIZE" ]; then
   echo "$cmd -- calculating loopback file size"
   verbose "finding size of: $DEV $TMPLIB \$INITRDFILES"
   INITRDSIZE="`du -ck $DEV $TMPLIB $INITRDFILES | tail -1 | cut -f 1`"
   verbose "minimum: $INITRDSIZE kB for files + inodes + filesystem metadata"
   INITRDSIZE=`expr $INITRDSIZE + $NUMINO / 8 + 512`  # enough for ext2 fs + a bit
fi

echo "$cmd -- making loopback file ($INITRDSIZE kB)"
verbose "using $DEVRAM as a temporary loopback file"
dd if=/dev/zero of=$DEVRAM count=$INITRDSIZE bs=1024 > /dev/null 2>&1
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating loopback file"
   cleanup 1
fi

# Ext2 can only have 8 * blocksize inodes per group, so we may need to
# increase the number of groups created if there are lots of inodes.
if [ $NUMINO -gt $INITRDSIZE ]; then
   if [ $NUMINO -gt 8192 ]; then
      verbose "too many inodes for one group - need to create more groups"
      BPG=`expr $INITRDSIZE \* 8192 / $NUMINO`
      INODE_OPT="-g `expr $BPG + 8 - $BPG % 8` -N $NUMINO"
   else
      INODE_OPT="-N $NUMINO"
   fi
else
   INODE_OPT="-i `expr $INITRDSIZE \* 1024 / $NUMINO`"
fi

echo "$cmd -- making ram disk filesystem ($NUMINO inodes)"
verbose "mke2fs -F -m0 -L LVM-$VERSION $INODE_OPT $DEVRAM $INITRDSIZE"
[ "$VERBOSE" ] && OPT_Q="" || OPT_Q="-q"
mke2fs $OPT_Q -F -m0 -L LVM-$VERSION $INODE_OPT $DEVRAM $INITRDSIZE
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR making ram disk filesystem"
   echo "$cmd -- ERROR you need to use mke2fs >= 1.14 or increase INITRDSIZE"
   cleanup 1
fi

verbose "creating mountpoint $TMPMNT"
mkdir $TMPMNT
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR making $TMPMNT"
   cleanup 1
fi

echo "$cmd -- mounting ram disk filesystem"
verbose "mount -o loop $DEVRAM $TMPMNT"
mount -oloop $DEVRAM $TMPMNT
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR mounting $DEVRAM on $TMPMNT"
   cleanup 1
fi

verbose "creating /etc /proc /lib in $TMPMNT"
mkdir $TMPMNT/etc $TMPMNT/proc $TMPMNT/lib $TMPMNT/dev
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating directories in $TMPMNT"
   cleanup 1
fi
verbose "removing $TMPMNT/lost+found"
rmdir $TMPMNT/lost+found

if [ "$USEMOD" ]; then
   #
   # create new modules configuration to avoid kmod complaining
   # about nonexsisting modules.
   #
   MODCONF=/etc/modules.conf
   [ ! -r $MODCONF -a -r /etc/conf.modules ] && MODCONF=/etc/conf.modules
   echo "$cmd -- creating new $MODCONF"
   verbose "all block and char modules will be turned off"
   MAJ=0
   while [ $MAJ -lt 256 ]; do
      echo "alias block-major-$MAJ   off"
      echo "alias char-major-$MAJ   off"
      MAJ=`expr $MAJ + 1`
   done > $TMPMNT/$MODCONF


   # to ensure, that modprobe doesn complain about timestamps
   echo "$cmd -- creating new modules.dep"
   depmod -a $VERSION
   if [ $? -ne 0 ]; then
      echo "$cmd -- ERROR running depmod"
      cleanup 1
   fi
fi

# copy necessary files to ram disk
[ "$VERBOSE" ] && OPT_Q="-v" || OPT_Q="--quiet"

if [ $DEV ]; then
   echo "$cmd -- copying device files to ram disk"
   verbose "find $DEV | cpio -pdm $TMPMNT"
   (cd $DEV; find . | cpio -pdm $OPT_Q $TMPMNT/dev)
   if [ $? -ne 0 ]; then
      echo "$cmd -- ERROR cpio to ram disk"
      cleanup 1
   fi
fi

echo "$cmd -- copying initrd files to ram disk"
verbose "find \$INITRDFILES | cpio -pdm $OPT_Q $TMPMNT"
find $INITRDFILES | cpio -pdm $OPT_Q $TMPMNT
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR cpio to ram disk"
   cleanup 1
fi

echo "$cmd -- copying shared libraries to ram disk"
verbose "find $TMPLIB | cpio -pdm $OPT_Q $TMPMNT"
(cd $TMPLIB; find * | cpio -pdm $OPT_Q $TMPMNT)
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR copying shared libraries to ram disk"
   cleanup 1
fi

echo "$cmd -- creating new /linuxrc"
create_linuxrc
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating linuxrc"
   cleanup
   exit 1
fi

echo "$cmd -- creating new /etc/fstab"
create_fstab
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating /etc/fstab"
   cleanup 1
fi

echo "$cmd -- ummounting ram disk"
umount $DEVRAM
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR umounting $DEVRAM"
   cleanup 1
fi

echo "$cmd -- creating compressed initrd $INITRD"
verbose "dd if=$DEVRAM bs=1k count=$INITRDSIZE | gzip -9"
dd if=$DEVRAM bs=1k count=$INITRDSIZE 2>/dev/null | gzip -9 > $INITRD
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating $INITRD"
   cleanup 1
fi

cleanup 0


basically just adding a stupid
Code:

   if [ $LIB == "(0xffffe000)" ]; then
       continue
    fi

in the right place.

For me this at least made the lvmcreate_initrd finish its job properly. it's still to be seen if it helps me to put the system together...

I hope this helps some of you with similar problems. I couldn't find a solution to this in the forum or anywhere so I thought I share. Tell me if it works[/code][/url]
Back to top
View user's profile Send private message
gilgamar
n00b
n00b


Joined: 03 Nov 2006
Posts: 1

PostPosted: Fri Nov 03, 2006 10:17 pm    Post subject: omg your a genius Reply with quote

that error was bugging me for a while. thanks it worked so far... but now i got new errors... lilo is giving me issues about the names in /proc/partitions not matching up with the names in /dev/.. know anything about that?
Back to top
View user's profile Send private message
dougm
n00b
n00b


Joined: 30 Sep 2003
Posts: 64
Location: France

PostPosted: Fri Nov 10, 2006 11:49 am    Post subject: I've got a better solution Reply with quote

Rather than just hacking the init script to not use ldd, I've already fixed it to correctly use ldd. I've been meaning to send this to the lvm guys in the form of a pacth o get it updated, but here it is for now:
Code:
#!/bin/bash
#
# lvm2create_initrd
#
# Miguel Cabeca
# cabeca (at) ist (dot) utl (dot) pt
#
# Inspiration to write this script came from various sources
#
# Original LVM lvmcreate_initrd: ftp://ftp.sistina.com/pub/LVM/1.0/
# Kernel initrd.txt: http://www.kernel.org/
# EVMS INSTALL.initrd & linuxrc: http://evms.sourceforge.net/
# Jeffrey Layton's lvm2create_initrd: http://poochiereds.net/svn/lvm2create_initrd/
# Christophe Saout's initrd & linuxrc: http://www.saout.de/misc/
#
# This script was only tested with kernel 2.6 with everything required to boot
# the root filesystem built-in (not as modules). Ex: SCSI or IDE, RAID, device mapper
# It does not support devfs as it is deprecated in the 2.6 kernel series
#
# It needs lvm2 tools, busybox, pivot_root, MAKEDEV
#
# It has been tested on Debian sid (unstable) only
#
# Changelog
# 26/02/2004   Initial release -- Miguel Cabeca
# 27/02/2004   Removed the BUSYBOXSYMLINKS var. The links are now determined at runtime.
#      some changes in init script to call a shell if something goes wrong. -- Miguel Cabeca
# 19/04/2004    Several small changes. Pass args to init so single user mode works. Add some
#               PATH entries to /sbin/init shell script so chroot works without /usr mounted. Remove
#               mkdir /initrd so we don't cause problems if root filesystem is corrupted. -- Jeff Layton
# 15/05/2004   initial support for modules, create lvm.conf from lvm dumpconfig, other cleanups -- Jeff Layton
#
# Copyright Miguel Cabeca, Jeffrey Layton, 2004
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# $Id: lvm2create_initrd,v 1.1 2004/06/07 16:20:05 agk Exp $

TMPMNT=/tmp/mnt.$$
DEVRAM=/tmp/initrd.$$

# set defaults
BINFILES=${BINFILES:-"/sbin/lvm /bin/bash /bin/busybox /sbin/pivot_root"}
BASICDEVICES=${BASICDEVICES:-"std consoleonly fd"}
BLOCKDEVICES=${BLOCKDEVICES:-"md hda hdb hdc hdd sda sdb sdc sdd"}
MAKEDEV=${MAKEDEV:-"gentoo"}

# Uncomment this if you want to disable automatic size detection
#INITRDSIZE=4096

PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH

usage () {
   echo "Create an initial ramdisk image for LVM2 root filesystem"
   echo "$cmd: [-h] [-v] [-c lvm.conf] [-m modulelist] [-e extrafiles] -r [raiddevs] [-R mdadm.conf] [-M style] [kernel version]"
   echo "      -h|--help      print this usage message"
   echo "      -v|--verbose   verbose progress messages"
   echo "      -c|--lvmconf   path to lvm.conf (/etc/lvm/lvm.conf)"
   echo "      -m|--modules   modules to copy to initrd image"
   echo "      -e|--extra     extra files to add to initrd"
   echo "      -r|--raid      raid devices to start in initrd"
   echo "      -R|--raidconf  location of mdadm.conf file to include"
   echo "      -M|--makedev   set MAKEDEV type (debian or redhat)"
}

verbose () {
   [ "$VERBOSE" ] && echo "`echo $cmd | tr '[a-z0-9/_]' ' '` -- $1" || true
}

cleanup () {
  [ "`mount | grep $DEVRAM`" ] && verbose "unmounting $DEVRAM" && umount $DEVRAM
  [ -f $DEVRAM ] && verbose "removing $DEVRAM" && rm $DEVRAM
  [ -d $TMPMNT ] && verbose "removing $TMPMNT" && rmdir $TMPMNT
  verbose "exit with code $1"
  exit $1
}

trap "
  verbose 'Caught interrupt'
  echo 'Bye bye...'
  cleanup 1
" 1 2 3 15

create_init () {
   cat << 'INIT' > $TMPMNT/sbin/init
#!/bin/bash

# include in the path some dirs from the real root filesystem
# for chroot, blockdev
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/lib/lvm-200:/initrd/bin:/initrd/sbin"
PRE="initrd:"

do_shell(){
    /bin/echo
    /bin/echo "*** Entering LVM2 rescue shell. Exit shell to continue booting. ***"
    /bin/echo
    /bin/bash
}

echo "$PRE Remounting / read/write"
mount -t ext2 -o remount,rw /dev/ram0 /


# We need /proc for device mapper
echo "$PRE Mounting /proc"
mount -t proc none /proc

# plug in modules listed in /etc/modules
if [ -f /etc/modules ]; then
    echo -n "$PRE plugging in kernel modules:"
    cat /etc/modules |
    while read module; do
        echo -n " $module"
        modprobe $module
    done
    echo '.'
fi

# start raid devices if raid_autostart file exists
if [ -f /etc/raid_autostart ]; then
    if [ ! -f /etc/mdadm/mdadm.conf ]; then
        mdoptions='--super-minor=dev'
    fi
    cat /etc/raid_autostart|
    while read dev; do
       echo "Starting RAID device $dev"
        /sbin/mdadm --assemble $dev $mdoptions
    done
fi

# Create the /dev/mapper/control device for the ioctl
# interface using the major and minor numbers that have been allocated
# dynamically.

echo -n "$PRE Finding device mapper major and minor numbers "

MAJOR=$(sed -n 's/^ *\([0-9]\+\) \+misc$/\1/p' /proc/devices)
MINOR=$(sed -n 's/^ *\([0-9]\+\) \+device-mapper$/\1/p' /proc/misc)
if test -n "$MAJOR" -a -n "$MINOR" ; then
   mkdir -p -m 755 /dev/mapper
   mknod -m 600 /dev/mapper/control c $MAJOR $MINOR
fi

echo "($MAJOR,$MINOR)"

# Device-Mapper dynamically allocates all device numbers. This means it is possible
# that the root volume specified to LILO or Grub may have a different number when the
# initrd runs than when the system was last running. In order to make sure the
# correct volume is mounted as root, the init script must determine what the
# desired root volume name is by getting the LVM2 root volume name from the kernel command line. In order for
# this to work correctly, "lvm2root=/dev/Volume_Group_Name/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.
for arg in `cat /proc/cmdline`; do
   echo $arg | grep '^lvm2root=' > /dev/null
   if [ $? -eq 0 ]; then
      rootvol=${arg#lvm2root=}
      break
   fi
done

echo "$PRE Activating LVM2 volumes"


# run a shell if we're passed lvm2rescue on commandline
grep lvm2rescue /proc/cmdline 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
    lvm vgchange --ignorelockingfailure -P -a y
    do_shell
else
    lvm vgchange --ignorelockingfailure -a y
fi

echo "$PRE Mounting root filesystem $rootvol ro"
mkdir /rootvol
if ! mount -t auto -o ro $rootvol /rootvol; then
   echo "\t*FAILED*";
   do_shell
fi

echo "$PRE Umounting /proc"
umount /proc

echo "$PRE Changing roots"
cd /rootvol
if ! pivot_root . initrd ; then
   echo "\t*FAILED*"
   do_shell
fi

echo "$PRE Proceeding with boot..."

exec chroot . /bin/sh -c "umount /initrd; blockdev --flushbufs /dev/ram0 ; exec /sbin/init $*" < dev/console > dev/console 2>&1

INIT
   chmod 555 $TMPMNT/sbin/init
}

# create lvm.conf file from dumpconfig. Just use filter options
create_lvmconf () {
    echo 'devices {' > $TMPMNT/etc/lvm/lvm.conf
    lvm dumpconfig | grep 'filter=' >> $TMPMNT/etc/lvm/lvm.conf
    echo '}' >> $TMPMNT/etc/lvm/lvm.conf
}

#
# Main
#

cmd=`basename $0`

VERSION=`uname -r`

while [ $# -gt 0 ]; do
   case $1 in
   -h|--help) usage; exit 0;;
   -v|--verbose)  VERBOSE="y";;
   -c|--lvmconf)  LVMCONF=$2; shift;;
   -m|--modules)  MODULES=$2; shift;;
   -e|--extra)    EXTRAFILES=$2; shift;;
   -r|--raid)     RAID=$2; shift;;
   -R|--raidconf) RAIDCONF=$2; shift;;
   -M|--makedev)  MAKEDEV=$2; shift;;
   [2-9].[0-9]*.[0-9]*) VERSION=$1;;
   *) echo "$cmd -- invalid option '$1'"; usage; exit 0;;
   esac
   shift
done

INITRD=${INITRD:-"/boot/initrd-lvm2-$VERSION.gz"}

echo "$cmd -- make LVM initial ram disk $INITRD"
echo ""

if [ -n "$RAID" ]; then
    BINFILES="$BINFILES /sbin/mdadm"
    RAIDCONF=${RAIDCONF:-"/etc/mdadm/mdadm.conf"}
    if [ -r $RAIDCONF ]; then
   EXTRAFILES="$EXTRAFILES $RAIDCONF"
    else
        echo "$cmd -- WARNING: No $RAIDCONF! Your RAID device minor numbers must match their superblock values!"
    fi
fi

# add modprobe if we declared any modules
if [ -n "$MODULES" ]; then
    BINFILES="$BINFILES /sbin/modprobe /sbin/insmod /sbin/rmmod"
fi

for a in $BINFILES $EXTRAFILES; do
    if [ ! -r "$a" ] ; then
   echo "$cmd -- ERROR: you need $a"
   exit 1;
    fi;
done

# Figure out which shared libraries we actually need in our initrd
echo "$cmd -- finding required shared libraries"
verbose "BINFILES: `echo $BINFILES`"
LIBFILES=`ldd $BINFILES 2>/dev/null |grep -v linux-gate |grep -v : | awk '{if (/=>/) { print $3 } else if (/\//) { print $1 }}' | sort -u`
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR figuring out needed shared libraries"
   exit 1
fi

verbose "Shared libraries needed: `echo $LIBFILES`"

INITRDFILES="$BINFILES $LIBFILES $MODULES $EXTRAFILES"

# tack on stuff for modules if we declared any and the files exist
if [ -n "$MODULES" ]; then
    if [ -f "/etc/modprobe.conf" ]; then
   INITRDFILES="$INITRDFILES /etc/modprobe.conf"
    fi
    if [ -f "/lib/modules/modprobe.conf" ]; then
   INITRDFILES="$INITRDFILES /lib/modules/modprobe.conf"
    fi
fi

# Calculate the the size of the ramdisk image.
# Don't forget that inodes take up space too, as does the filesystem metadata.
echo "$cmd -- calculating initrd filesystem parameters"
if [ -z "$INITRDSIZE" ]; then
   echo "$cmd -- calculating loopback file size"
   verbose "finding size"
   INITRDSIZE="`du -Lck $INITRDFILES | tail -1 | cut -f 1`"
   verbose "minimum: $INITRDSIZE kB for files + inodes + filesystem metadata"
   INITRDSIZE=`expr $INITRDSIZE + 512`  # enough for ext2 fs + a bit
fi

echo "$cmd -- making loopback file ($INITRDSIZE kB)"
verbose "using $DEVRAM as a temporary loopback file"
dd if=/dev/zero of=$DEVRAM count=$INITRDSIZE bs=1024 > /dev/null 2>&1
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating loopback file"
   cleanup 1
fi

echo "$cmd -- making ram disk filesystem"
verbose "mke2fs -F -m0 -L LVM-$VERSION $DEVRAM $INITRDSIZE"
[ "$VERBOSE" ] && OPT_Q="" || OPT_Q="-q"
mke2fs $OPT_Q -F -m0 -L LVM-$VERSION $DEVRAM $INITRDSIZE
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR making ram disk filesystem"
   echo "$cmd -- ERROR you need to use mke2fs >= 1.14 or increase INITRDSIZE"
   cleanup 1
fi

verbose "creating mountpoint $TMPMNT"
mkdir $TMPMNT
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR making $TMPMNT"
   cleanup 1
fi

echo "$cmd -- mounting ram disk filesystem"
verbose "mount -o loop $DEVRAM $TMPMNT"
mount -oloop $DEVRAM $TMPMNT
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR mounting $DEVRAM on $TMPMNT"
   cleanup 1
fi

verbose "creating basic set of directories in $TMPMNT"
(cd $TMPMNT; mkdir bin dev etc lib proc sbin var)
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating directories in $TMPMNT"
   cleanup 1
fi

# Add some /dev files. We have to handle different types of MAKEDEV invocations
# here, so this is rather messy.
RETCODE=0
echo "$cmd -- adding required /dev files"
verbose "BASICDEVICES: `echo $BASICDEVICES`"
verbose "BLOCKDEVICES: `echo $BLOCKDEVICES`"
[ "$VERBOSE" ] && OPT_Q="-v" || OPT_Q=""
case "$MAKEDEV" in
debian)
    (cd $TMPMNT/dev; /dev/MAKEDEV $OPT_Q $BASICDEVICES $BLOCKDEVICES)
    RETCODE=$?
    ;;
redhat)
    (cd $TMPMNT/dev; /dev/MAKEDEV $OPT_Q -d $TMPMNT/dev -m 2)
    RETCODE=$?
    ;;
gentoo)
    (cd $TMPMNT/dev; /usr/sbin/MAKEDEV $OPT_Q $BASICDEVICES $BLOCKDEVICES)
    RETCODE=$?
    ;;
*)
    echo "$cmd -- ERROR: $MAKEDEV is not a known MAKEDEV style."
    RETCODE=1
    ;;
esac


if [ $RETCODE -ne 0 ]; then
   echo "$cmd -- ERROR adding /dev files"
   cleanup 1
fi


# copy necessary files to ram disk
echo "$cmd -- copying initrd files to ram disk"
[ "$VERBOSE" ] && OPT_Q="-v" || OPT_Q="--quiet"
verbose "find \$INITRDFILES | cpio -pdmL $OPT_Q $TMPMNT"
find $INITRDFILES | cpio -pdmL $OPT_Q $TMPMNT
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR cpio to ram disk"
   cleanup 1
fi


echo "$cmd -- creating symlinks to busybox"
shopt -s extglob
[ "$VERBOSE" ] && OPT_Q="-v" || OPT_Q=""
BUSYBOXSYMLINKS=`busybox 2>&1| awk '/^Currently defined functions:$/ {i++;next} i'|tr ',\t\n' ' '`
for link in ${BUSYBOXSYMLINKS//@(linuxrc|init|busybox)}; do
   ln -s $OPT_Q busybox $TMPMNT/bin/$link;
done
shopt -u extglob

echo "$cmd -- creating new $TMPMNT/sbin/init"
create_init
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating init"
   cleanup
   exit 1
fi

# copy LVMCONF into place or create a stripped down one from lvm dumpconfig
mkdir -p $TMPMNT/etc/lvm
if [ -n "$LVMCONF" ]; then
    echo "$cmd -- copying $LVMCONF to $TMPMNT/etc/lvm/lvm.conf"
    if [ -f "$LVMCONF" ]; then
        cp $LVMCONF $TMPMNT/etc/lvm/lvm.conf
    else
        echo "$cmd -- ERROR: $LVMCONF does not exist!"
   cleanup
   exit 1
    fi
else
    echo "$cmd -- creating new $TMPMNT/etc/lvm/lvm.conf"
    create_lvmconf
fi

if [ -n "$RAID" ]; then
    RAIDLIST="$TMPMNT/etc/raid_autostart"
    echo "$cmd -- creating $RAIDLIST file."
    for device in $RAID; do
        echo $device >> $RAIDLIST
    done
fi

# create modules.dep and /etc/modules files if needed
if [ -n "$MODULES" ]; then
    echo "$cmd -- creating $MODDIR/modules.dep file and $TMPMNT/etc/modules"
    depmod -b $TMPMNT $VERSION
    for module in $MODULES; do
        basename $module | sed 's/\.k\{0,1\}o$//' >> $TMPMNT/etc/modules
    done
fi

verbose "removing $TMPMNT/lost+found"
rmdir $TMPMNT/lost+found

echo "$cmd -- ummounting ram disk"
umount $DEVRAM
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR umounting $DEVRAM"
   cleanup 1
fi

echo "$cmd -- creating compressed initrd $INITRD"
verbose "dd if=$DEVRAM bs=1k count=$INITRDSIZE | gzip -9"
dd if=$DEVRAM bs=1k count=$INITRDSIZE 2>/dev/null | gzip -9 > $INITRD
if [ $? -ne 0 ]; then
   echo "$cmd -- ERROR creating $INITRD"
   cleanup 1
fi


cat << FINALTXT
--------------------------------------------------------
Your initrd is ready in $INITRD

Don't forget to set root=/dev/ram0 in kernel parameters
Don't forget to set lvm2root=/dev/VG/LV in kernel parameters, where LV is your root volume
If you use lilo try adding/modifying an entry similar to this one in lilo.conf:

image=/boot/vmlinuz-lvm2-$VERSION
        label="ramdisk_LVM"
        initrd=/boot/initrd-lvm2-$VERSION.gz
        append="root=/dev/ram0 lvm2root=/dev/system/root <other parameters>"

If using grub try adding/modifying an entry similar to this one in menu.lst

title ramdisk LVM
        kernel /boot/vmlinuz-lvm2-$VERSION root=/dev/ram0 lvm2root=/dev/system/root <other parameters>
        initrd /boot/initrd-lvm2-$VERSION.gz

You can also pass lvm2rescue to the kernel to get a shell
--------------------------------------------------------
FINALTXT

cleanup 0


Back to top
View user's profile Send private message
dougm
n00b
n00b


Joined: 30 Sep 2003
Posts: 64
Location: France

PostPosted: Fri Nov 10, 2006 11:52 am    Post subject: Reply with quote

Oh, and I almost forgot. You absolutely HAVE to make sure you create the folder /initrd in your root volume so that the initrd image can pivot itself away....
Back to top
View user's profile Send private message
xen-dom0
n00b
n00b


Joined: 25 May 2007
Posts: 17

PostPosted: Fri May 25, 2007 6:38 pm    Post subject: Reply with quote

dougm wrote:
Oh, and I almost forgot. You absolutely HAVE to make sure you create the folder /initrd in your root volume so that the initrd image can pivot itself away....


Thx for the hint - maybe the lvmcreate_initrd script can do something like 'mkdir -p /initrd' - would have saved me a reboot :wink:
Another reboot was required due to the shared libs. I'm using the amd64 platform and the ldd output looks like:
Code:

xendom0 linux # ldd /bin/bash
        libncurses.so.5 => /lib/libncurses.so.5 (0x00002b6f8c93e000)
        libdl.so.2 => /lib/libdl.so.2 (0x00002b6f8ca99000)
        libc.so.6 => /lib/libc.so.6 (0x00002b6f8cb9d000)
        /lib64/ld-linux-x86-64.so.2 (0x00002b6f8c821000)

The lvmcreate_initrd script now fetches the /lib/lib... files and when using the initrd the /lib64/lib... files are missing. I solved this by hard coding the 64bit libs in the script...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum