1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mkinitrd/mkinitrd.sh,v 1.2 2005-12-02 15:35:32 niro Exp $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mkinitrd/mkinitrd.sh,v 1.8 2006-01-01 16:05:20 niro Exp $ |
3 |
|
|
4 |
# mkinitrd |
# mkinitrd |
5 |
# |
# |
38 |
PROBE="yes" |
PROBE="yes" |
39 |
MODULES="" |
MODULES="" |
40 |
PREMODS="" |
PREMODS="" |
41 |
|
NOSTRIP=false |
42 |
|
|
43 |
[ -e /etc/sysconfig/mkinitrd ] && . /etc/sysconfig/mkinitrd |
[ -e /etc/conf.d/mkinitrd ] && . /etc/conf.d/mkinitrd |
44 |
|
|
45 |
CONFMODS="$MODULES" |
CONFMODS="${MODULES}" |
46 |
MODULES="" |
MODULES="" |
47 |
|
|
48 |
compress=1 |
compress=1 |
56 |
modulefile=/etc/modules.conf |
modulefile=/etc/modules.conf |
57 |
rc=0 |
rc=0 |
58 |
|
|
59 |
IMAGESIZE=8000 |
IMAGESIZE=4000 |
60 |
PRESCSIMODS="sd_mod" |
PRESCSIMODS="sd_mod" |
61 |
fstab="/etc/fstab" |
fstab="/etc/fstab" |
62 |
|
|
74 |
echo " [--force-ide-probe] [--force-scsi-probe | --omit-scsi-modules]" |
echo " [--force-ide-probe] [--force-scsi-probe | --omit-scsi-modules]" |
75 |
echo " [--image-version] [--force-scsi-probe | --omit-raid-modules]" |
echo " [--image-version] [--force-scsi-probe | --omit-raid-modules]" |
76 |
echo " [--with=<module>] [--force-lvm-probe | --omit-lvm-modules]" |
echo " [--with=<module>] [--force-lvm-probe | --omit-lvm-modules]" |
77 |
echo " [--builtin=<module>] " |
echo " [--builtin=<module>] [--initramfs | --loopback] [--no-strip]" |
78 |
echo " [--fstab=<fstab>] [--nocompress] <initrd-image> <kernel-version>" |
echo " [--fstab=<fstab>] [--nocompress] <initrd-image> <kernel-version>" |
79 |
echo |
echo |
80 |
echo " (ex: $(basename $0) /boot/initrd-2.2.5-15.img 2.2.5-15)" |
echo " (ex: $(basename $0) /boot/initrd-2.2.5-15.img 2.2.5-15)" |
392 |
--allow-missing) allowmissing=yes ;; |
--allow-missing) allowmissing=yes ;; |
393 |
--noresume) noresume=1 ;; |
--noresume) noresume=1 ;; |
394 |
--help) usage -n ;; |
--help) usage -n ;; |
395 |
|
--initramfs) IMAGE_TYPE=initramfs ;; |
396 |
|
--loopback) IMAGE_TYPE=loopback ;; |
397 |
|
--no-strip) NOSTRIP=true ;; |
398 |
*) |
*) |
399 |
if [ -z "${target}" ] |
if [ -z "${target}" ] |
400 |
then |
then |
411 |
shift |
shift |
412 |
done |
done |
413 |
|
|
414 |
|
# enforce loopback method as default |
415 |
|
[[ -z ${IMAGE_TYPE} ]] && IMAGE_TYPE=loopback |
416 |
|
|
417 |
if [ -z "${target}" -o -z "${kernel}" ] |
if [ -z "${target}" -o -z "${kernel}" ] |
418 |
then |
then |
419 |
usage |
usage |
452 |
############################## |
############################## |
453 |
####### get modules ########## |
####### get modules ########## |
454 |
|
|
455 |
echo "Creating initramfs" |
echo "Creating ${IMAGE_TYPE} initrd image" |
456 |
modulefile=/etc/modprobe.conf |
modulefile=/etc/modprobe.conf |
457 |
|
|
458 |
for n in ${PREMODS} |
for n in ${PREMODS} |
652 |
install -d ${DEST}/{bin,dev,etc,lib,loopfs,proc,sys,sysroot} || die |
install -d ${DEST}/{bin,dev,etc,lib,loopfs,proc,sys,sysroot} || die |
653 |
|
|
654 |
# install busybox |
# install busybox |
655 |
|
echo "$(which busybox.mkinitrd)" |
656 |
install -m0755 $(which busybox.mkinitrd) ${DEST}/bin/busybox || die |
install -m0755 $(which busybox.mkinitrd) ${DEST}/bin/busybox || die |
657 |
for i in '[' ash basename cat cut chroot clear cp dirname echo env false find \ |
for i in '[' ash basename cat cut chroot clear cp dirname echo env false find \ |
658 |
grep gunzip gzip ln ls loadkmap losetup mkdir mknod modprobe more mount mv \ |
grep gunzip gzip init ln ls loadkmap losetup mkdir mknod modprobe more mount mv \ |
659 |
ps pwd rm rmdir sh sleep test touch true umount uname \ |
pivot_root ps pwd rm rmdir sh sleep test touch true umount uname \ |
660 |
xargs yes chmod chown |
xargs yes chmod chown |
661 |
do |
do |
662 |
# static links |
# static links |
664 |
done |
done |
665 |
|
|
666 |
# install run-init |
# install run-init |
667 |
|
echo "$(which run-init.mkinitrd)" |
668 |
install -m0755 $(which run-init.mkinitrd) ${DEST}/bin/run-init || die |
install -m0755 $(which run-init.mkinitrd) ${DEST}/bin/run-init || die |
669 |
|
|
670 |
# install insmod.static |
# install insmod.static |
671 |
|
echo "$(which insmod.static)" |
672 |
install -m0755 $(which insmod.static) ${DEST}/bin/insmod || die |
install -m0755 $(which insmod.static) ${DEST}/bin/insmod || die |
673 |
|
|
674 |
# install udev |
# install udev |
712 |
add_initrd 'mount -t proc proc /proc' |
add_initrd 'mount -t proc proc /proc' |
713 |
add_initrd 'mount -t sysfs sysfs /sys' |
add_initrd 'mount -t sysfs sysfs /sys' |
714 |
|
|
715 |
|
[[ ${IMAGE_TYPE} = loopback ]] && add_initrd 'mount -t ramfs -o remount,rw /dev/ram /' |
716 |
|
|
717 |
|
# silencio |
718 |
|
add_initrd 'echo 0 > /proc/sys/kernel/printk' |
719 |
|
|
720 |
add_initrd 'echo "-- Creating inital device nodes ..."' |
add_initrd 'echo "-- Creating inital device nodes ..."' |
721 |
add_initrd 'mount -o mode=0755 -t tmpfs udev /dev' |
add_initrd 'mount -o mode=0755 -t tmpfs udev /dev' |
722 |
add_initrd 'mkdir /dev/pts' |
add_initrd 'mkdir /dev/pts' |
748 |
|
|
749 |
add_initrd 'echo "-- Setting up hotplug ..."' |
add_initrd 'echo "-- Setting up hotplug ..."' |
750 |
add_initrd 'echo "/sbin/hotplug" > /proc/sys/kernel/hotplug' |
add_initrd 'echo "/sbin/hotplug" > /proc/sys/kernel/hotplug' |
751 |
add_initrd 'for i in $(find /lib -type f -name *.ko)' |
|
752 |
add_initrd 'do' |
# loading detected modules with options |
753 |
add_initrd ' echo "-- Loadin module ${i}"' |
for MODULE in ${MODULES} |
754 |
add_initrd ' insmod ${i};' |
do |
755 |
# handle special cases like usb |
text="" |
756 |
add_initrd ' if [ "${i}" = "usb-storage" ]' |
module=$(echo ${MODULE} | sed "s|.*/||" | sed "s/.k\?o$//") |
757 |
add_initrd ' then' |
fullmodule=$(echo ${MODULE} | sed "s|.*/||") |
758 |
add_initrd ' echo "Waiting 8 seconds for usb-driver initialization."' |
|
759 |
add_initrd ' sleep 8' |
options=$(sed -n -e "s/^options[ ][ ]*${module}[ ][ ]*//p" ${modulefile} 2>/dev/null) |
760 |
add_initrd ' fi' |
|
761 |
add_initrd 'done' |
if [ -n "${options}" ] |
762 |
|
then |
763 |
|
echo "Adding module ${module}${text} with options ${options} ..." |
764 |
|
else |
765 |
|
echo "Adding module ${module}${text} ..." |
766 |
|
fi |
767 |
|
|
768 |
|
add_initrd "echo \"-- Loading ${fullmodule} module\"" |
769 |
|
add_initrd "insmod /lib/${fullmodule} ${options}" |
770 |
|
|
771 |
|
# Hack - we need a delay after loading usb-storage to give things |
772 |
|
# time to settle down before we start looking a block devices |
773 |
|
if [ "${module}" = "usb-storage" ] |
774 |
|
then |
775 |
|
add_initrd 'echo Waiting 8 seconds for driver initialization.' |
776 |
|
add_initrd 'sleep 8' |
777 |
|
fi |
778 |
|
if [ "${module}" = "zfcp" -a -f /etc/zfcp.conf ] |
779 |
|
then |
780 |
|
add_initrd 'echo Waiting 2 seconds for driver initialization.' |
781 |
|
add_initrd 'sleep 2' |
782 |
|
cat /etc/zfcp.conf | grep -v "^#" | tr "A-Z" "a-z" | while read DEVICE SCSIID WWPN SCSILUN FCPLUN |
783 |
|
do |
784 |
|
add_initrd "echo -n ${WWPN} > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/port_add" |
785 |
|
add_initrd "echo -n ${FCPLUN} > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/${WWPN}/unit_add" |
786 |
|
add_initrd "echo -n 1 > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/online" |
787 |
|
done |
788 |
|
fi |
789 |
|
done |
790 |
|
|
791 |
# lvm support |
# lvm support |
792 |
if [ -n "${vg_list}" ] |
if [ -n "${vg_list}" ] |
813 |
# software suspend |
# software suspend |
814 |
if [ -z "${noresume}" ] |
if [ -z "${noresume}" ] |
815 |
then |
then |
816 |
add_initrd "resume ${swsuspdev}" |
add_initrd "[ -x /bin/resume ] && resume ${swsuspdev}" |
817 |
fi |
fi |
818 |
|
|
819 |
# raid |
# raid |
828 |
|
|
829 |
add_initrd 'echo "-- Mounting sysroot ..."' |
add_initrd 'echo "-- Mounting sysroot ..."' |
830 |
add_initrd '. /etc/rootdev' |
add_initrd '. /etc/rootdev' |
831 |
add_initrd 'mknod ${device} b ${major} ${minor}' |
add_initrd '[ ! -e ${device} ] && mknod ${device} b ${major} ${minor}' |
832 |
add_initrd 'echo "${device} /sysroot ${rootfs} defaults,ro 0 0" > /etc/fstab' |
add_initrd 'echo "${device} /sysroot ${rootfs} defaults,ro 0 0" > /etc/fstab' |
833 |
add_initrd 'mount /sysroot' |
add_initrd 'mount /sysroot' |
834 |
|
|
835 |
|
# de-silencio |
836 |
|
add_initrd 'echo 3 > /proc/sys/kernel/printk' |
837 |
|
|
838 |
add_initrd 'echo "-- Switching to real sysroot ..."' |
add_initrd 'echo "-- Switching to real sysroot ..."' |
839 |
add_initrd 'umount /sys' |
add_initrd 'umount /sys' |
840 |
add_initrd 'umount /proc' |
add_initrd 'umount /proc' |
841 |
add_initrd 'exec run-init /sysroot /sbin/init $@ </sysroot/dev/console >/sysroot/dev/console' |
|
842 |
|
[[ ${IMAGE_TYPE} = initramfs ]] && add_initrd 'exec run-init /sysroot /sbin/init $@ </sysroot/dev/console >/sysroot/dev/console' |
843 |
|
if [[ ${IMAGE_TYPE} = loopback ]] |
844 |
|
then |
845 |
|
add_initrd 'cd /sysroot' |
846 |
|
add_initrd 'pivot_root . initrd' |
847 |
|
add_initrd "exec /sbin/chroot . sh -c 'umount -n /initrd >/dev/null 2>&1;exec -a init.new /sbin/init'</dev/console >/dev/console 2>&1" |
848 |
|
fi |
849 |
|
|
850 |
chmod +x ${DEST}/init || die |
chmod +x ${DEST}/init || die |
851 |
|
|
860 |
echo "Coping your modules to '${DEST}/lib' ..." |
echo "Coping your modules to '${DEST}/lib' ..." |
861 |
for MODULE in ${MODULES} |
for MODULE in ${MODULES} |
862 |
do |
do |
863 |
if [ -x /usr/bin/strip ] |
if [ -x /usr/bin/strip ] && [[ ${NOSTRIP} = false ]] |
864 |
then |
then |
865 |
/usr/bin/strip -g ${verbose} ${MODULE} -o ${DEST}/lib/$(basename ${MODULE}) || die |
/usr/bin/strip -g ${verbose} ${MODULE} -o ${DEST}/lib/$(basename ${MODULE}) || die |
866 |
else |
else |
869 |
done |
done |
870 |
|
|
871 |
# create the image |
# create the image |
872 |
(cd "${DEST}" ; find . | cpio --quiet --dereference -o -H newc | gzip -9 >${IMAGE}) |
echo "Creating initrd image '${target}' ..." |
873 |
cat ${IMAGE} > ${target} || die |
if [[ ${IMAGE_TYPE} = initramfs ]] |
874 |
|
then |
875 |
|
(cd "${DEST}" ; find . | cpio --quiet -o -H newc | gzip -9 >${IMAGE}) |
876 |
|
cat ${IMAGE} > ${target} || die |
877 |
|
fi |
878 |
|
|
879 |
|
if [[ ${IMAGE_TYPE} = loopback ]] |
880 |
|
then |
881 |
|
MOUNTTMP="$(mktemp -d)" |
882 |
|
|
883 |
|
# create ext2 img |
884 |
|
dd if=/dev/zero of=${IMAGE} bs=1024 count=${IMAGESIZE} &> /dev/null || die |
885 |
|
mke2fs -m 0 -i 1024 -F ${IMAGE} &> /dev/null || die |
886 |
|
mount -o loop ${IMAGE} ${MOUNTTMP} || die |
887 |
|
mv ${DEST}/* ${MOUNTTMP} || die |
888 |
|
umount ${MOUNTTMP} || die |
889 |
|
gzip -9 ${IMAGE} || die |
890 |
|
cat ${IMAGE}.gz > ${target} || die |
891 |
|
[ -d ${MOUNTTMP} ] && rm -rf ${MOUNTTMP} |
892 |
|
|
893 |
|
# create inird dir for pivot_root |
894 |
|
[ ! -d /initrd ] && { install -d /initrd || die; } |
895 |
|
fi |
896 |
|
|
897 |
# clean up |
# clean up |
898 |
[ -d ${DEST} ] && rm -rf ${DEST} |
[ -d ${DEST} ] && rm -rf ${DEST} |
899 |
[ -f ${IMAGE} ] && rm -f ${IMAGE} |
[ -f ${IMAGE} ] && rm -f ${IMAGE} |
900 |
|
|
901 |
|
# all went ok at this point |
902 |
|
exit 0 |