home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd2.bin
/
suse
/
inst-sys
/
sbin
/
lvmcreate_initrd
< prev
next >
Wrap
Text File
|
2000-03-24
|
4KB
|
172 lines
#!/bin/sh
#
# Copyright (C) 1997 - 2000 Heinz Mauelshagen, Germany
#
# June 1999
#
# 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
#
cmd=`basename $0`
VERRSION=$1
[ -z "$VERSION" ] && VERSION=`uname -r`
DEVRAM=/dev/ram1
INITRD=/boot/initrd.gz
INITRDSIZE=8192
INITRDFILES="/sbin/modprobe /sbin/vgchange /sbin/vgscan /bin/bash /bin/sh /bin/rm /sbin/insmod /sbin/modprobe /dev/* /lib/modules/${VERSION}/modules.dep /lib/modules/${VERSION}/block/lvm.o"
TMP=/tmp/mnt.$$
trap "
cd /
umount $DEVRAM
freeramdisk $DEVRAM
echo -e 'Bye bye...\n'
" 1 2 3 15
function create_fstab {
echo "
/dev/ram / ext2 defaults 1 0
none /proc proc defaults 0 0
" > etc/fstab
chmod 644 etc/fstab
}
function create_linuxrc {
echo "#!/bin/sh
/sbin/insmod lvm
/bin/mount /proc
/sbin/vgscan
/sbin/vgchange -a y
/bin/umount /proc" > linuxrc
chmod 555 linuxrc
}
#
# Main
#
echo -e "\nLogical Volume Manager 0.8 by Heinz Mauelshagen 11/11/1999\n"
echo -e "$cmd -- this script creates a LVM initial ram disk in $INITRD\n"
echo "$cmd -- making ram filesystem"
mke2fs -m0 -i 1024 $DEVRAM $INITRDSIZE >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR making ram disk filesystem\n"
exit 1
fi
mkdir -p $TMP/ram >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR making $TMP/ram\n"
exit 1
fi
echo "$cmd -- mounting ram filesystem"
mount -t ext2 $DEVRAM $TMP/ram >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR mounting $DEVRAM on $TMP/ram\n"
exit 1
fi
cd $TMP/ram
mkdir etc proc
#
# create new conf.modules to avoid kmod complaining about nonexsisting modules.
#
echo "$cmd -- creating etc/conf.modules"
i=0
while [ $i -lt 256 ]; do
echo "alias block-major-$i off"
echo "alias char-major-$i off"
let i=i+1
done > etc/conf.modules
# to ensure, that modprobe doesn complain about timestamps
echo "$cmd -- creating new modules.dep"
depmod -a ${VERSION} >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR depmod\n"
exit 1
fi
# copy necessary files to ram disk
echo "$cmd -- copying files to ram disk"
find $INITRDFILES|cpio -pdm $TMP/ram >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR cpio to ram disk\n"
exit 1
fi
# figure out which actual shared libraries we need in our initrd
echo "$cmd -- figuring out shared libraries"
SHLIBS=`ldd sbin/vg* bin/sh|awk '{if(/=>/){print $3}}'|sort -u 2>/dev/null`
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR figuring out needed shared libraries\n"
exit 1
fi
echo "$cmd -- copying shared libraries to ram disk"
find $SHLIBS|cpio -Lpdm $TMP/ram >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR copying needed shared libraries to ram disk\n"
exit 1
fi
for lib in $SHLIBS
do
strip $TMP/ram$lib >/dev/null
done
echo "$cmd -- creating linuxrc"
create_linuxrc >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR creating linuxrc\n"
exit 1
fi
echo "$cmd -- creating etc/fstab"
create_fstab >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR creating etc/fstab\n"
exit 1
fi
cd /
echo "$cmd -- ummounting ram disk"
umount $DEVRAM
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR umounting $DEVRAM\n"
exit 1
fi
echo "$cmd -- creating compressed initrd in $INITRD"
dd if=$DEVRAM bs=1k count=$INITRDSIZE | gzip -9 > $INITRD 2>/dev/null
if [ $? -ne 0 ]; then
echo -e "$cmd -- ERROR creating $INITRD\n"
exit 1
fi
freeramdisk $DEVRAM