1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lvm2create_initrd submitted by Jeff Layton <jtlayton@poochiereds.net>

sourced from http://poochiereds.net/svn/lvm2/
This commit is contained in:
Alasdair Kergon 2004-06-07 16:20:05 +00:00
parent 30bab85be1
commit 8c670f8349
7 changed files with 1024 additions and 0 deletions

View File

@ -1,5 +1,6 @@
Version 2.00.17 -
=============================
Add lvm2create_initrd script from http://poochiereds.net/svn/lvm2/
Fix rounding of large diplayed sizes.
Suppress decimal point when using units of sectors/bytes.
Additional kernel target checks before pvmove & snapshot creation.

View File

@ -0,0 +1,6 @@
all:
echo "Nothing to do for make all"
manpage:
pod2man --center="create LVM2 initrd" --name='lvm2create_initrd' --section=8 -r 'lvm2create_initrd' ./lvm2create_initrd.pod > lvm2create_initrd.8

View File

@ -0,0 +1,40 @@
http://poochiereds.net/svn/lvm2/
This is the lvm2create_initrd script written by Miguel Cabeca, with some small
modifications by myself.
Here are some other requirements and tips for using it:
1) this script uses busybox on the initrd image, hence busybox needs to be
installed when you create your initrd.
2) Make sure /etc/lvm/lvm.conf is set up correctly before running this. In
particular, if you're using LVM on RAID, make sure that you have a filter that
excludes the RAID component devices (this may not be necessary with the latest
patch by Luca Berra, but it doesn't hurt).
3) This initrd image does not support modules. If you need to plug in any
kernel modules during the initrd phase, then you'll need to hand-modify the
image.
4) The generated initrd image supports an 'lvm2rescue' mode as well. If you add
the parameter 'lvmrescue' on the kernel command line, it will run a shell at
the end of the initrd 'init' script. This can be helpful when trying to fix a
corrupt root volume or root LVM2 volume group.
5) No userspace md tools are installed, so if you're using LVM on RAID, then
you'll probably want to mark your RAID partitions as type 'fd' so that the
kernel will start them automagically (or hand-modify the image).
6) I'm not sure if devfs will work with this or not. udev, however does work,
and is recommended. Because the dm-* devices use dynamically allocated major
and minor numbers, kernel upgrades and the like can renumber your devices. To
fix this, you need to run a 'vgscan --mknodes' prior to fscking and mounting
your rootfs. Doing this with a static /dev creates a problem though -- you
will be modifying the root filesystem before it has been fsck'ed. udev gets
around this by mounting a ramdisk over /dev, but you'll probably need to add
a startup script that creates devices in /dev. The lvm2udev script in this
directory is an example of such a beast.
--
Jeffrey Layton <jtlayton@poochiereds.net>

View File

@ -0,0 +1,476 @@
#!/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$
TMPMNT=/tmp/mnt.$$
DEVRAM=/tmp/initrd.$$
# set defaults
BINFILES=${BINFILES:-"/lib/lvm-200/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:-"debian"}
# 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 | awk '{if (/=>/) { print $3 }}' | 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=$?
;;
*)
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

View File

@ -0,0 +1,281 @@
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "lvm2create_initrd 8"
.TH lvm2create_initrd 8 "2004-06-05" "lvm2create_initrd" "create LVM2 initrd"
.SH "NAME"
lvm2create_initrd \- create initrd image for booting to root\e\-on\e\-LVM2
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
\&\fBlvm2create_initrd\fR [ \fB\-h|\-\-help\fR ] [ \fB\-v|\-\-verbose\fR ] [ \fB\-c|\-\-lvmconf\fR \fI/path/to/lvm.conf\fR ] [ \fB\-m|\-\-modules\fR "\fImodule1 module2 ...\fR" ] [ \fB\-e|\-\-extra\fR "\fIfile1 file2 ...\fR" ] [ \fB\-r|\-\-raid\fR "\fI/dev/md1 /dev/md2 ...\fR" ]
[ \fB\-R|\-\-raidconf\fR \fI/path/to/mdadm.conf\fR ] [ \fB\-M|\-\-makedev\fR \fIstyle\fR ]
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
lvm2create_initrd creates an initial ramdisk (initrd) image suitable for booting to system that has an \s-1LVM2\s0 volume as its root filesystem.
.PP
To boot to such a setup, you'll
either need a bootloader that understands \s-1LVM2\s0 volumes, or you'll need a
filesystem on a regular volume to act as a boot partition (typically mounted
on /boot).
.PP
The resulting initrd image is fairly full\-featured. It can harbor and load
kernel modules, start \s-1MD\s0 devices, and boot to a shell to perform rescue
operations.
.Sh "Booting to your initrd Image:"
.IX Subsection "Booting to your initrd Image:"
The filesystem image created is an ext2fs filesystem, hence your kernel must have
ext2fs built into it statically in order to boot to the image.
.PP
Once you create your initrd image, you must pass the correct options to the kernel when
you boot using it. Your kernel command line should look something like this:
.PP
\&\fBroot=/dev/ram0 lvm2root=/dev/rootvg/root [ lvm2rescue ]\fR
.PP
of course there may be other options.
.IP "\fBroot=/dev/ram0\fR" 4
.IX Item "root=/dev/ram0"
This option is required. It tells the kernel that the root filesystem should initially
be set to the ramdisk (/dev/ram0).
.IP "\fBlvm2root=/dev/rootvg/root\fR" 4
.IX Item "lvm2root=/dev/rootvg/root"
This option is also required. It tells the initrd image which \s-1LVM2\s0 device the root filesystem is located on.
.IP "\fBlvm2rescue\fR" 4
.IX Item "lvm2rescue"
Causes the initrd image to run a shell prior to mounting the root filesystem. This is
helpful in disaster situations where your initrd image is accessable, but there is
a problem with the root filesystem (corrupted image, incorrect device setup, etc.). This
option is (of course) optional.
.SH "OPTIONS"
.IX Header "OPTIONS"
Most of parameters that can be set via command-line options can also be set
via environment variables. Options specified on the command-line always take
precedence.
.IP "\fB\-h|\-\-help\fR" 4
.IX Item "-h|--help"
Display short help text and exit. If used, other options are ignored.
.IP "\fB\-v|\-\-verbose\fR" 4
.IX Item "-v|--verbose"
Turn on extra verbosity for debugging, etc.
.IP "\fB\-c|\-\-lvmconf\fR \fI/path/to/lvm.conf\fR" 4
.IX Item "-c|--lvmconf /path/to/lvm.conf"
Specify an lvm.conf file to include in the image. This is useful if you have
special device filters or other options you wish to use during the initrd
stage. If this option is not
included, then a lvm.conf file is created that contains only the current
device filter from an \fBlvm dumpconfig\fR. This can also be set via the \fB$LVMCONF\fR
environment variable.
.ie n .IP "\fB\-m|\-\-modules\fR ""\fI/path/to/module1.ko /path/to/module2.ko ...\fR""" 4
.el .IP "\fB\-m|\-\-modules\fR ``\fI/path/to/module1.ko /path/to/module2.ko ...\fR''" 4
.IX Item "-m|--modules ""/path/to/module1.ko /path/to/module2.ko ..."""
Specify modules to include and plug in during the initrd phase. This option
takes a quoted, space-separated list of modules. Full pathnames are required.
These modules are loaded into the kernel early in the initrd phase of the boot
process. The current modprobe.conf file is also copied to the initrd image
as well. This can also be specified via the \fB$MODULES\fR environment variable.
.ie n .IP "\fB\-e|\-\-extra\fR ""\fI/path/to/file1 /path/to/file2 ...\fR""" 4
.el .IP "\fB\-e|\-\-extra\fR ``\fI/path/to/file1 /path/to/file2 ...\fR''" 4
.IX Item "-e|--extra ""/path/to/file1 /path/to/file2 ..."""
Extra files that should be included in the initrd image. These files will be
copied to the same location in the initrd image that they are in the current
filesystem. Again full pathnames are required. This can also be specified via
the \fB$EXTRAFILES\fR environment variable.
.ie n .IP "\fB\-r|\-\-raid\fR ""\fI/dev/md1 /dev/md2...\fR""" 4
.el .IP "\fB\-r|\-\-raid\fR ``\fI/dev/md1 /dev/md2...\fR''" 4
.IX Item "-r|--raid ""/dev/md1 /dev/md2..."""
\&\s-1RAID\s0 devices to be started prior to scanning for \s-1LVM2\s0 volume groups. If this
option is used then then \fBmdadm\fR program must be installed. This can also be
specified via the \fB$RAID\fR environment variable.
.ie n .IP "\fB\-R|\-\-raidconf\fR ""\fI/path/to/mdadm.conf\fR""" 4
.el .IP "\fB\-R|\-\-raidconf\fR ``\fI/path/to/mdadm.conf\fR''" 4
.IX Item "-R|--raidconf ""/path/to/mdadm.conf"""
Location of a mdadm.conf file to include. If this is not specified, then no
files are included, and any devices specified with the \fB\-r\fR option above
must have minor numbers that match their superblock values. This can also be
specified via the \fB$RAIDCONF\fR environment variable.
.IP "\fB\-M|\-\-makedev\fR \fIstyle\fR" 4
.IX Item "-M|--makedev style"
Set \s-1MAKEDEV\s0 invocation style. The script currently supports 2 styles of
\&\s-1MAKEDEV\s0 programs \fIdebian\fR and \fIredhat\fR. The default is \fIdebian\fR. Set
to \fIredhat\fR if using the RedHat/Fedora binary \s-1MAKEDEV\s0 program. Please send
a bug report to maintainer if your distrib doesn't work with any of the
current options.
.SH "ENVIRONMENT VARIABLES"
.IX Header "ENVIRONMENT VARIABLES"
Most of the options to this script can be set via environment variables. In
situations where both are set, then the command-line options take precedence.
.IP "\fB$LVMCONF\fR" 4
.IX Item "$LVMCONF"
Same as \-c option.
.IP "\fB$MODULES\fR" 4
.IX Item "$MODULES"
Same as \-m option.
.IP "\fB$EXTRAFILES\fR" 4
.IX Item "$EXTRAFILES"
Same as \-e option.
.IP "\fB$RAID\fR" 4
.IX Item "$RAID"
Same as \-r option.
.IP "\fB$RAIDCONF\fR" 4
.IX Item "$RAIDCONF"
Same as \-R option.
.IP "\fB$MAKEDEV\fR" 4
.IX Item "$MAKEDEV"
Same as \-M option.
.IP "\fB$BASICDEVICES\fR" 4
.IX Item "$BASICDEVICES"
Overrides the default value of \f(CW$BASICDEVICES\fR in the script (which is \*(L"std consoleonly fd\*(R"). These values are passed to the \fB\s-1MAKEDEV\s0\fR program to create device
entries in the initrd image.
.IP "\fB$BLOCKDEVICES\fR" 4
.IX Item "$BLOCKDEVICES"
Overrides the default value of \f(CW$BLOCKDEVICES\fR in the script (which is \*(L"md hda hdb hdc hdd sda sdb sdc sdd\*(R"). This value is passed to the \fB\s-1MAKEDEV\s0\fR program to
create device entries in the initrd image.
.IP "\fB$BINFILES\fR" 4
.IX Item "$BINFILES"
Overrides the default value of \f(CW$BINFILES\fR (which is \*(L"/lib/lvm\-200/lvm /bin/bash /bin/busybox /sbin/pivot_root\*(R"). The difference between using this and adding
a file to the \f(CW$EXTRAFILES\fR list above is that libraries that these depend upon are also included. You can still use \f(CW$EXTRAFILES\fR to achieve the same effect, but
you must resolve library dependencies youself.
.IP "\fB$INITRDSIZE\fR" 4
.IX Item "$INITRDSIZE"
Force a particular size for your initrd image. The default is to total up the size of
the included files and to add 512K as a buffer.
.SH "BUGS"
.IX Header "BUGS"
I don't like having to specify a \-M option to set the \s-1MAKEDEV\s0 style, but I know
of no way to reliably detect what type of \s-1MAKEDEV\s0 is being used. We'll probably
have to add other \s-1MAKEDEV\s0 styles in the future as this script is tested on
other distributions.
.SH "AUTHORS"
.IX Header "AUTHORS"
The script was originally written by Miguel Cabeca, with significant
improvements by Jeffrey Layton. Comments, bug reports and patches should be
sent to Jeffrey Layton at \fBjtlayton@poochiereds.net\fR.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fB\s-1MAKEDEV\s0\fR(8), \fBmdadm\fR(8), \fBbusybox\fR(8), \fBlvm.conf\fR(5)

View File

@ -0,0 +1,187 @@
=head1 NAME
lvm2create_initrd - create initrd image for booting to root\-on\-LVM2
=head1 SYNOPSIS
B<lvm2create_initrd> [ B<-h|--help> ] [ B<-v|--verbose> ] [ B<-c|--lvmconf> I</path/to/lvm.conf> ] [ B<-m|--modules> "I<module1 module2 ...>" ] [ B<-e|--extra> "I<file1 file2 ...>" ] [ B<-r|--raid> "I</dev/md1 /dev/md2 ...>" ]
[ B<-R|--raidconf> I</path/to/mdadm.conf> ] [ B<-M|--makedev> I<style> ]
=head1 DESCRIPTION
lvm2create_initrd creates an initial ramdisk (initrd) image suitable for booting to system that has an LVM2 volume as its root filesystem.
To boot to such a setup, you'll
either need a bootloader that understands LVM2 volumes, or you'll need a
filesystem on a regular volume to act as a boot partition (typically mounted
on /boot).
The resulting initrd image is fairly full-featured. It can harbor and load
kernel modules, start MD devices, and boot to a shell to perform rescue
operations.
=head2 Booting to your initrd Image:
The filesystem image created is an ext2fs filesystem, hence your kernel must have
ext2fs built into it statically in order to boot to the image.
Once you create your initrd image, you must pass the correct options to the kernel when
you boot using it. Your kernel command line should look something like this:
B<root=/dev/ram0 lvm2root=/dev/rootvg/root [ lvm2rescue ]>
of course there may be other options.
=over
=item B<root=/dev/ram0>
This option is required. It tells the kernel that the root filesystem should initially
be set to the ramdisk (/dev/ram0).
=item B<lvm2root=/dev/rootvg/root>
This option is also required. It tells the initrd image which LVM2 device the root filesystem is located on.
=item B<lvm2rescue>
Causes the initrd image to run a shell prior to mounting the root filesystem. This is
helpful in disaster situations where your initrd image is accessable, but there is
a problem with the root filesystem (corrupted image, incorrect device setup, etc.). This
option is (of course) optional.
=back
=head1 OPTIONS
Most of parameters that can be set via command-line options can also be set
via environment variables. Options specified on the command-line always take
precedence.
=over
=item B<-h|--help>
Display short help text and exit. If used, other options are ignored.
=item B<-v|--verbose>
Turn on extra verbosity for debugging, etc.
=item B<-c|--lvmconf> I</path/to/lvm.conf>
Specify an lvm.conf file to include in the image. This is useful if you have
special device filters or other options you wish to use during the initrd
stage. If this option is not
included, then a lvm.conf file is created that contains only the current
device filter from an B<lvm dumpconfig>. This can also be set via the B<$LVMCONF>
environment variable.
=item B<-m|--modules> "I</path/to/module1.ko /path/to/module2.ko ...>"
Specify modules to include and plug in during the initrd phase. This option
takes a quoted, space-separated list of modules. Full pathnames are required.
These modules are loaded into the kernel early in the initrd phase of the boot
process. The current modprobe.conf file is also copied to the initrd image
as well. This can also be specified via the B<$MODULES> environment variable.
=item B<-e|--extra> "I</path/to/file1 /path/to/file2 ...>"
Extra files that should be included in the initrd image. These files will be
copied to the same location in the initrd image that they are in the current
filesystem. Again full pathnames are required. This can also be specified via
the B<$EXTRAFILES> environment variable.
=item B<-r|--raid> "I</dev/md1 /dev/md2...>"
RAID devices to be started prior to scanning for LVM2 volume groups. If this
option is used then then B<mdadm> program must be installed. This can also be
specified via the B<$RAID> environment variable.
=item B<-R|--raidconf> "I</path/to/mdadm.conf>"
Location of a mdadm.conf file to include. If this is not specified, then no
files are included, and any devices specified with the B<-r> option above
must have minor numbers that match their superblock values. This can also be
specified via the B<$RAIDCONF> environment variable.
=item B<-M|--makedev> I<style>
Set MAKEDEV invocation style. The script currently supports 2 styles of
MAKEDEV programs I<debian> and I<redhat>. The default is I<debian>. Set
to I<redhat> if using the RedHat/Fedora binary MAKEDEV program. Please send
a bug report to maintainer if your distrib doesn't work with any of the
current options.
=back
=head1 ENVIRONMENT VARIABLES
Most of the options to this script can be set via environment variables. In
situations where both are set, then the command-line options take precedence.
=over
=item B<$LVMCONF>
Same as -c option.
=item B<$MODULES>
Same as -m option.
=item B<$EXTRAFILES>
Same as -e option.
=item B<$RAID>
Same as -r option.
=item B<$RAIDCONF>
Same as -R option.
=item B<$MAKEDEV>
Same as -M option.
=item B<$BASICDEVICES>
Overrides the default value of $BASICDEVICES in the script (which is "std consoleonly fd"). These values are passed to the B<MAKEDEV> program to create device
entries in the initrd image.
=item B<$BLOCKDEVICES>
Overrides the default value of $BLOCKDEVICES in the script (which is "md hda hdb hdc hdd sda sdb sdc sdd"). This value is passed to the B<MAKEDEV> program to
create device entries in the initrd image.
=item B<$BINFILES>
Overrides the default value of $BINFILES (which is "/lib/lvm-200/lvm /bin/bash /bin/busybox /sbin/pivot_root"). The difference between using this and adding
a file to the $EXTRAFILES list above is that libraries that these depend upon are also included. You can still use $EXTRAFILES to achieve the same effect, but
you must resolve library dependencies youself.
=item B<$INITRDSIZE>
Force a particular size for your initrd image. The default is to total up the size of
the included files and to add 512K as a buffer.
=back
=head1 BUGS
I don't like having to specify a -M option to set the MAKEDEV style, but I know
of no way to reliably detect what type of MAKEDEV is being used. We'll probably
have to add other MAKEDEV styles in the future as this script is tested on
other distributions.
=head1 AUTHORS
The script was originally written by Miguel Cabeca, with significant
improvements by Jeffrey Layton. Comments, bug reports and patches should be
sent to Jeffrey Layton at S<B<jtlayton@poochiereds.net>>.
=head1 SEE ALSO
B<MAKEDEV>(8), B<mdadm>(8), B<busybox>(8), B<lvm.conf>(5)

View File

@ -0,0 +1,33 @@
#!/bin/sh
# $Id$
# simple startup script to create lvm2 devices if /dev is a mountpoint, there
# are active dm- devices, and an executable /sbin/vgscan.
# this script is licensed under GPLv2.
# See http://www.gnu.org/licenses/gpl.html
case $1 in
start)
# is /dev a mountpoint?
mountpoint -q /dev
DEVMNTPOINT=$?
# check to see if there are active dm entries under /sys
ls /sys/block/dm-*/dev 1>/dev/null 2>&1
ACTIVEDMDEVS=$?
# mknodes if conditions are right
if [ $DEVMNTPOINT -eq 0 -a $ACTIVEDMDEVS -eq 0 -a -x /sbin/vgscan ]; then
/sbin/vgscan --mknodes --ignorelockingfailure
fi
;;
stop)
exit 0
;;
*)
echo "usage:"
echo " $0 start|stop"
;;
esac