Magellan Linux

Diff of /trunk/mkinitrd/mkinitrd.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 291 by niro, Fri Dec 2 15:35:32 2005 UTC revision 303 by niro, Thu Dec 15 20:44:55 2005 UTC
# Line 1  Line 1 
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.7 2005-12-15 20:44:55 niro Exp $
3    
4  # mkinitrd  # mkinitrd
5  #  #
# Line 38  VERSION=5.0.8 Line 38  VERSION=5.0.8
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
# Line 55  builtins="" Line 56  builtins=""
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    
# Line 73  usage() Line 74  usage()
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)"
# Line 391  while [ $# -gt 0 ]; do Line 392  while [ $# -gt 0 ]; do
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
# Line 407  while [ $# -gt 0 ]; do Line 411  while [ $# -gt 0 ]; do
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
# Line 445  fi Line 452  fi
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}
# Line 645  echo "Using modules:${MODULES}" Line 652  echo "Using modules:${MODULES}"
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
# Line 656  do Line 664  do
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
# Line 702  add_initrd '#!/bin/sh' Line 712  add_initrd '#!/bin/sh'
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  add_initrd 'echo "-- Creating inital device nodes ..."'  add_initrd 'echo "-- Creating inital device nodes ..."'
718  add_initrd 'mount -o mode=0755 -t tmpfs udev /dev'  add_initrd 'mount -o mode=0755 -t tmpfs udev /dev'
719  add_initrd 'mkdir /dev/pts'  add_initrd 'mkdir /dev/pts'
# Line 733  add_initrd 'touch /dev/.udev' Line 745  add_initrd 'touch /dev/.udev'
745    
746  add_initrd 'echo "-- Setting up hotplug ..."'  add_initrd 'echo "-- Setting up hotplug ..."'
747  add_initrd 'echo "/sbin/hotplug" > /proc/sys/kernel/hotplug'  add_initrd 'echo "/sbin/hotplug" > /proc/sys/kernel/hotplug'
748  add_initrd 'for i in $(find /lib -type f -name *.ko)'  # add_initrd 'for i in $(find /lib -type f -name *.ko)'
749  add_initrd 'do'  # add_initrd 'do'
750  add_initrd ' echo "-- Loadin module ${i}"'  # add_initrd ' echo "-- Loading module ${i}"'
751  add_initrd ' insmod ${i};'  # add_initrd ' insmod ${i};'
752  # handle special cases like usb  # # handle special cases like usb
753  add_initrd ' if [ "${i}" = "usb-storage" ]'  # add_initrd ' if [ "${i}" = "usb-storage" ]'
754  add_initrd ' then'  # add_initrd ' then'
755  add_initrd ' echo "Waiting 8 seconds for usb-driver initialization."'  # add_initrd ' echo "Waiting 8 seconds for usb-driver initialization."'
756  add_initrd ' sleep 8'  # add_initrd ' sleep 8'
757  add_initrd ' fi'  # add_initrd ' fi'
758  add_initrd 'done'  # add_initrd 'done'
759    
760    # loading detected modules with options
761    for MODULE in ${MODULES}
762    do
763     text=""
764     module=$(echo ${MODULE} | sed "s|.*/||" | sed "s/.k\?o$//")
765     fullmodule=$(echo ${MODULE} | sed "s|.*/||")
766    
767     options=$(sed -n -e "s/^options[     ][      ]*${module}[      ][      ]*//p" ${modulefile} 2>/dev/null)
768    
769     if [ -n "${options}" ]
770     then
771     echo "Adding module ${module}${text} with options ${options} ..."
772     else
773     echo "Adding module ${module}${text} ..."
774     fi
775    
776     add_initrd "echo \"-- Loading ${fullmodule} module\""
777     add_initrd "insmod /lib/${fullmodule} ${options}"
778    
779     # Hack - we need a delay after loading usb-storage to give things
780     #        time to settle down before we start looking a block devices
781     if [ "${module}" = "usb-storage" ]
782     then
783     add_initrd 'echo Waiting 8 seconds for driver initialization.'
784     add_initrd 'sleep 8'
785     fi
786     if [ "${module}" = "zfcp" -a -f /etc/zfcp.conf ]
787     then
788     add_initrd 'echo Waiting 2 seconds for driver initialization.'
789     add_initrd 'sleep 2'
790     cat /etc/zfcp.conf | grep -v "^#" | tr "A-Z" "a-z" | while read DEVICE SCSIID WWPN SCSILUN FCPLUN
791     do
792     add_initrd "echo -n ${WWPN} > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/port_add"
793     add_initrd "echo -n ${FCPLUN} > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/${WWPN}/unit_add"
794     add_initrd "echo -n 1 > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/online"
795     done
796     fi
797    done
798    
799  # lvm support  # lvm support
800  if [ -n "${vg_list}" ]  if [ -n "${vg_list}" ]
# Line 785  fi Line 836  fi
836    
837  add_initrd 'echo "-- Mounting sysroot ..."'  add_initrd 'echo "-- Mounting sysroot ..."'
838  add_initrd '. /etc/rootdev'  add_initrd '. /etc/rootdev'
839  add_initrd 'mknod ${device} b ${major} ${minor}'  add_initrd '[ ! -e ${device} ] && mknod ${device} b ${major} ${minor}'
840  add_initrd 'echo "${device} /sysroot ${rootfs} defaults,ro 0 0" > /etc/fstab'  add_initrd 'echo "${device} /sysroot ${rootfs} defaults,ro 0 0" > /etc/fstab'
841  add_initrd 'mount /sysroot'  add_initrd 'mount /sysroot'
842    
843  add_initrd 'echo "-- Switching to real sysroot ..."'  add_initrd 'echo "-- Switching to real sysroot ..."'
844  add_initrd 'umount /sys'  add_initrd 'umount /sys'
845  add_initrd 'umount /proc'  add_initrd 'umount /proc'
846  add_initrd 'exec run-init /sysroot /sbin/init $@ </sysroot/dev/console >/sysroot/dev/console'  
847    [[ ${IMAGE_TYPE} = initramfs ]] && add_initrd 'exec run-init /sysroot /sbin/init $@ </sysroot/dev/console >/sysroot/dev/console'
848    if [[ ${IMAGE_TYPE} = loopback ]]
849    then
850     add_initrd 'cd /sysroot'
851     add_initrd 'pivot_root . initrd'
852     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"
853    fi
854    
855  chmod +x ${DEST}/init || die  chmod +x ${DEST}/init || die
856    
# Line 807  echo "rootfs=${rootfs}" >> ${DEST}/etc/r Line 865  echo "rootfs=${rootfs}" >> ${DEST}/etc/r
865  echo "Coping your modules to '${DEST}/lib' ..."  echo "Coping your modules to '${DEST}/lib' ..."
866  for MODULE in ${MODULES}  for MODULE in ${MODULES}
867  do  do
868   if [ -x /usr/bin/strip ]   if [ -x /usr/bin/strip ] && [[ ${NOSTRIP} = false ]]
869   then   then
870   /usr/bin/strip -g ${verbose} ${MODULE} -o ${DEST}/lib/$(basename ${MODULE}) || die   /usr/bin/strip -g ${verbose} ${MODULE} -o ${DEST}/lib/$(basename ${MODULE}) || die
871   else   else
# Line 816  do Line 874  do
874  done  done
875    
876  # create the image  # create the image
877  (cd "${DEST}" ; find . | cpio --quiet --dereference -o -H newc | gzip -9 >${IMAGE})  echo "Creating initrd image '${target}' ..."
878  cat ${IMAGE} > ${target} || die  if [[ ${IMAGE_TYPE} = initramfs ]]
879    then
880     (cd "${DEST}" ; find . | cpio --quiet -o -H newc | gzip -9 >${IMAGE})
881     cat ${IMAGE} > ${target} || die
882    fi
883    
884    if [[ ${IMAGE_TYPE} = loopback ]]
885    then
886     MOUNTTMP="$(mktemp -d)"
887    
888     # create ext2 img
889     dd if=/dev/zero of=${IMAGE} bs=1024 count=${IMAGESIZE} &> /dev/null || die
890     mke2fs -m 0 -i 1024 -F ${IMAGE} &> /dev/null || die
891     mount -o loop ${IMAGE} ${MOUNTTMP} || die
892     mv ${DEST}/* ${MOUNTTMP} || die
893     umount ${MOUNTTMP} || die
894     gzip -9 ${IMAGE} || die
895     cat ${IMAGE}.gz > ${target} || die
896     [ -d ${MOUNTTMP} ] && rm -rf ${MOUNTTMP}
897    
898     # create inird dir for pivot_root
899     [ ! -d /initrd ] && { install -d /initrd || die; }
900    fi
901    
902  # clean up  # clean up
903  [ -d ${DEST} ] && rm -rf ${DEST}  [ -d ${DEST} ] && rm -rf ${DEST}
904  [ -f ${IMAGE} ] && rm -f ${IMAGE}  [ -f ${IMAGE} ] && rm -f ${IMAGE}
905    
906    # all went ok at this point
907    exit 0

Legend:
Removed from v.291  
changed lines
  Added in v.303