From ea20a441f8fecc9fa84e0e1f12c4b71bf436f872 Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Fri, 21 Apr 2006 23:00:28 +0000 Subject: Hook updates and changes... git-svn-id: http://projects.archlinux.org/svn/initramfs/mkinitcpio@7 880c04e9-e011-0410-abf7-b926e227c9cd --- hooks/base | 9 +++ hooks/encrypt | 17 +++++ hooks/filesystems | 25 +++++++ hooks/ide | 23 +++++++ hooks/raid | 17 +++++ hooks/resume | 13 ++++ hooks/sata | 34 ++++++++++ hooks/scsi | 34 ++++++++++ hooks/usb | 7 ++ install/base | 32 +++++++++ install/encrypt | 15 +++++ install/filesystems | 18 +++++ install/ide | 22 ++++++ install/ide-auto | 22 ++++++ install/resume | 16 +++++ install/sata | 21 ++++++ install/sata-auto | 20 ++++++ install/scsi | 20 ++++++ install/scsi-auto | 19 ++++++ install/udev | 18 +++++ install/usb | 18 +++++ install/usb-auto | 17 +++++ mkinitcpio | 189 +++------------------------------------------------- 23 files changed, 446 insertions(+), 180 deletions(-) create mode 100644 hooks/base create mode 100644 hooks/encrypt create mode 100644 hooks/filesystems create mode 100644 hooks/ide create mode 100644 hooks/raid create mode 100644 hooks/resume create mode 100644 hooks/sata create mode 100644 hooks/scsi create mode 100644 hooks/usb create mode 100644 install/base create mode 100644 install/encrypt create mode 100644 install/filesystems create mode 100644 install/ide create mode 100644 install/ide-auto create mode 100644 install/resume create mode 100644 install/sata create mode 100644 install/sata-auto create mode 100644 install/scsi create mode 100644 install/scsi-auto create mode 100644 install/udev create mode 100644 install/usb create mode 100644 install/usb-auto diff --git a/hooks/base b/hooks/base new file mode 100644 index 0000000..706fb85 --- /dev/null +++ b/hooks/base @@ -0,0 +1,9 @@ +# vim:set ft=sh: +run_hook () +{ + if [ -e "/sys/bus/pci" ]; then + msg -n "Loading base modules..." + /bin/modprobe -a -q $(/bin/cat /sys/bus/pci/devices/*/modalias) >/dev/null 2>&1 & + msg "done." + fi +} diff --git a/hooks/encrypt b/hooks/encrypt new file mode 100644 index 0000000..8b4c80b --- /dev/null +++ b/hooks/encrypt @@ -0,0 +1,17 @@ +# vim: set ft=sh: +run_hook () +{ + echo "" + echo "A password is required to access the root filesystem:" + echo -n "password: " + if /bin/cryptsetup.static isLuks ${root} >/dev/null 2>&1; then + /bin/cryptsetup.static luksOpen ${root} root + else + /bin/cryptsetup create root ${root} + fi + + if [ $? != 0 ]; then + echo "ERROR: Password Verification Failed" + exit 1 + fi +} diff --git a/hooks/filesystems b/hooks/filesystems new file mode 100644 index 0000000..c676832 --- /dev/null +++ b/hooks/filesystems @@ -0,0 +1,25 @@ +# vim: set ft=sh: +run_hook () +{ + msg -n ":: Loading root filesystem module..." + if [ "x${rootfstype}" != "x" ]; then + FSTYPE="${rootfstype}" + else + if [ "x${root}" != "x" ]; then + msg "Attempting to create root device '${root}'" + dev_t=$( /bin/parseblock "${root}" ) + if [ "x${dev_t}" != "x" ]; then + /bin/mknod "${root}" b ${dev_t} + eval $( /bin/fstype < "${root}" ) + else + FSTYPE="unknown" + echo "ERROR: Failed to parse block device '${root}'" + fi + else + FSTYPE="unknown" + echo "ERROR: root fs cannot be detected. Try using the rootfstype= kernel parameter." + fi + fi + msg " ${FSTYPE}" + /bin/modprobe -q "${FSTYPE}" >/dev/null 2>&1 +} diff --git a/hooks/ide b/hooks/ide new file mode 100644 index 0000000..0a81062 --- /dev/null +++ b/hooks/ide @@ -0,0 +1,23 @@ +# vim: set ft=sh: +run_hook () +{ + if [ -e /proc/ide ]; then + msg -n "Loading ide modules..." + /bin/modprobe -q ide-generic >/dev/null 2>&1 + for d in /proc/ide/*; do + unit=${d#/proc/ide/} + if [ -e "${d}/media" -a ! -d "/sys/block/${unit}" ]; then + read m < "${d}/media" + case "${m}" in + disk) /bin/modprobe -q ide-disk >/dev/null 2>&1;; + cdrom) /bin/modprobe -q ide-cd >/dev/null 2>&1;; + tape) /bin/modprobe -q ide-tape >/dev/null 2>&1;; + floppy) /bin/modprobe -q ide-floppy >/dev/null 2>&1;; + esac + fi + done + msg "done" + else + msg "No ide devices detected..." + fi +} diff --git a/hooks/raid b/hooks/raid new file mode 100644 index 0000000..a81c172 --- /dev/null +++ b/hooks/raid @@ -0,0 +1,17 @@ +# vim: set ft=sh: + +# kinit handles md/raid assembly +# we just need modules + +install () +{ + MODULES=" $(find "${MODULEDIR}/kernel/drivers/md/" -name *.ko) md raid0 raid1 raid2 raid5 raid6" + BINARIES="" + FILES="" +} + +run_hook () +{ + #TODO + /bin/modprobe -aq raid0 raid1 raid2 raid5 raid6 +} diff --git a/hooks/resume b/hooks/resume new file mode 100644 index 0000000..bec926e --- /dev/null +++ b/hooks/resume @@ -0,0 +1,13 @@ +# vim:set ft=sh: +run_hook () +{ + fmtdevice () { echo "${1}:${2}"; } + if [ -e /sys/power/resume ]; then + if [ -e "${resume}" ]; then + dev_t=$( /bin/parseblock "${resume}" ) + fmtdevice ${dev_t} > /sys/power/resume + fi + + [ -e /proc/suspend2 ] && echo "" > /proc/suspend2/do_resume + fi +} diff --git a/hooks/sata b/hooks/sata new file mode 100644 index 0000000..fb6ed90 --- /dev/null +++ b/hooks/sata @@ -0,0 +1,34 @@ +# vim: set ft=sh: +run_hook () +{ + if [ -e /sys/bus/scsi/devices/ ]; then + msg -n "Loading scsi modules..." + for d in /sys/bus/scsi/devices/*; do + if [ -e "${d}/type" ]; then + read m < "${d}/type" + case "$m" in + 0) /bin/modprobe -q sd_mod 2>&1 >/dev/null ;; + # this below is take from the Arch udev rules + 1) read vendor < "${d}/vendor" + if [ "${vendor}" = "Onstream" ]; then + read model < "${d}/model" + case "$model" in + ADR*) /bin/modprobe -q st >/dev/null 2>&1;; + *) /bin/modprobe -q osst >/dev/null 2>&1;; + esac + else + /bin/modprobe -q st >/dev/null 2>&1 + fi + ;; + 2|3) /bin/modprobe -q sg >/dev/null 2>&1;; + 4|5) /bin/modprobe -q sr_mod >/dev/null 2>&1;; + 6) /bin/modprobe -q sg >/dev/null 2>&1;; + 7) /bin/modprobe -q sd_mod >/dev/null 2>&1;; + 8|9) /bin/modprobe -q sg >/dev/null 2>&1;; + 14) /bin/modprobe -q sd_mod >/dev/null 2>&1;; + esac + fi + done + msg "done." + fi +} diff --git a/hooks/scsi b/hooks/scsi new file mode 100644 index 0000000..fb6ed90 --- /dev/null +++ b/hooks/scsi @@ -0,0 +1,34 @@ +# vim: set ft=sh: +run_hook () +{ + if [ -e /sys/bus/scsi/devices/ ]; then + msg -n "Loading scsi modules..." + for d in /sys/bus/scsi/devices/*; do + if [ -e "${d}/type" ]; then + read m < "${d}/type" + case "$m" in + 0) /bin/modprobe -q sd_mod 2>&1 >/dev/null ;; + # this below is take from the Arch udev rules + 1) read vendor < "${d}/vendor" + if [ "${vendor}" = "Onstream" ]; then + read model < "${d}/model" + case "$model" in + ADR*) /bin/modprobe -q st >/dev/null 2>&1;; + *) /bin/modprobe -q osst >/dev/null 2>&1;; + esac + else + /bin/modprobe -q st >/dev/null 2>&1 + fi + ;; + 2|3) /bin/modprobe -q sg >/dev/null 2>&1;; + 4|5) /bin/modprobe -q sr_mod >/dev/null 2>&1;; + 6) /bin/modprobe -q sg >/dev/null 2>&1;; + 7) /bin/modprobe -q sd_mod >/dev/null 2>&1;; + 8|9) /bin/modprobe -q sg >/dev/null 2>&1;; + 14) /bin/modprobe -q sd_mod >/dev/null 2>&1;; + esac + fi + done + msg "done." + fi +} diff --git a/hooks/usb b/hooks/usb new file mode 100644 index 0000000..5766ef9 --- /dev/null +++ b/hooks/usb @@ -0,0 +1,7 @@ +# vim: set ft=sh: +run_hook () +{ + msg -n "Loading usb modules..." + /bin/modprobe -aq $(/bin/cat /sys/bus/usb/devices/*/modalias) >/dev/null 2>&1 + msg "done." +} diff --git a/install/base b/install/base new file mode 100644 index 0000000..9cd2030 --- /dev/null +++ b/install/base @@ -0,0 +1,32 @@ +# vim:set ft=sh: + +install () +{ + add_dir "/proc" + add_dir "/sys" + add_dir "/dev" + + add_nod "/dev/null" 644 c 1 3 + add_nod "/dev/zero" 644 c 1 5 + add_nod "/dev/console" 644 c 5 1 + + for f in /lib -name klibc-*.so; do + add_file $f + done + + for f in /usr/lib/klibc/bin/*; do + add_file $f /bin/$(basename $f) + done + + add_file "/lib/initramfs/init" "/init" + add_file "${CONFIG}" "/config" +} + +help () +{ +cat </dev/null |\ - sed "s|insmod \(.*\)|\1|" | grep "${1}" | sort -u -} - -all_modules () -{ - find ${MODULEDIR} -name *.ko 2>/dev/null |\ - grep "${1}" | sort -u -} - -msg() { [ "${QUIET}" = "n" ] && echo "${@}"; } -err() { [ echo "ERROR: ${@}" >2; } - -add_dir() -{ - local dir - dir="$(dirname ${1})" - if [ "x${dir}" != "x" -a "${dir}" != "/" ]; then - dir="${dir}" #this got stripped off above... put it back - - if ! grep "dir ${dir} " "${FILELIST}" 2>&1 > /dev/null; then - add_dir "${dir}" - msg " adding dir ${dir}" - echo "dir ${dir} 755 0 0" >> "${FILELIST}" - fi - fi -} - -# add_devnode /dev/foo type major minor [permissions] -add_devnode() -{ - if [ $# -ge 4 ]; then - local perms - perms="${5:-644}" - add_dir "${1}" - if ! grep "nod ${1}" "${FILELIST}" 2>&1 > /dev/null; then - msg " adding device node ${1}" - echo "nod ${1} ${perms} 0 0 ${2} ${3} ${4}" >> "${FILELIST}" - fi - else - err "invalid device node format: $@" >2 - return 1 - fi -} - -add_symlink () -{ - local fil dest dir - if [ -L ${1} ]; then - fil="${1}" - dest="${fil##$BASEDIR}" - add_dir "${dest}" - if ! grep "slink ${fil} " "${FILELIST}" 2>&1 > /dev/null; then - msg " adding symlink ${dest}" - echo "slink ${dest} ${fil} $(stat -c '%a %u %g' ${fil})" >> "${FILELIST}" - fi - else - err "ERROR: file '${1}' is not a symlink" >2 - return 1 - fi -} - -add_file () -{ - local fil lnk dir dest - if [ -e "${1}" ]; then - fil="${1}" - lnk=$(readlink -f "${fil}") - if [ -n "${lnk}" ]; then - add_symlink "${fil}" - fil="${lnk}" - fi - if [ $# -eq 2 ]; then - dest="${2}" - else - dest="${fil##$BASEDIR}" - fi - - add_dir "${dest}" - - if ! grep "file ${fil} " "${FILELIST}" 2>&1 > /dev/null; then - msg " adding file ${dest}" - echo "file ${dest} ${fil} $(stat -c '%a %u %g' ${fil})" >> "${FILELIST}" - fi - else - err "file '${1}' does not exist" >2 - return 1 - fi -} - -HAS_MODULES="n" -add_module() -{ - local fil path mod deps - #cleanup - remove .ko, replace - and _ with [-_] to match either - fil=$(basename "${1}" | sed -e "s|[-_]|\[-_\]|g" -e "s|\.ko$||g") - - for path in $(find "${MODULEDIR}" -type f -name "${fil}.ko"); do - for mod in $(modinfo -F depends "${path}" | tr ',' ' '); do - if [ "x${mod}" != "x" ]; then - add_module "${mod}" - HAS_MODULES="y" - fi - done - add_file "${path}" - done -} - -add_binary() -{ - local bin type lib - bin=$(which "${1}") - if [ $? -ne 0 ]; then - bin="${1}" - fi - - if [ ! -f "${bin}" ]; then - err "'${bin}' is not a file" >2 - return 1 - fi - - if [ $? -eq 0 ]; then - type=$(file -b "${bin}") - case "${type}" in - *script*) - msg " adding '${type}' script, ensure proper interp exists..." - add_file "${bin}" - ;; - *executable*) - add_file "${bin}" - #note, this will also handle 'not a dynamic executable' spit out by - # static binaries... the deps will produce nothing - for lib in $(ldd ${bin} 2>/dev/null | sed "s|.*=>\(.*\)|\1|"); do - if [ "x${lib}" != "x" ]; then - #remove TLS libraries - notls=$(echo ${lib} | sed 's|/lib/tls.*/\(lib.*\)|/lib/\1|') - [ -e "${notls}" ] && lib="${notls}" - [ -f "${lib}" ] && add_file "${lib}" - fi - done - ;; - *) - err "unknown type '${type}' for binary '${bin}'" >2 - return 1 - ;; - esac - fi -} - -function parse_hook() -{ - local mod bin fil - for mod in $MODULES; do - if [ "x${mod}" != "x" ]; then - add_module "${mod}" - fi - done - - for bin in $BINARIES; do - if [ "x${bin}" != "x" ]; then - add_binary "${bin}" - fi - done - - for fil in $FILES; do - if [ "x${fil}" != "x" ]; then - add_file "${fil}" - fi - done -} - #parse 'global' hook, as defined in ${CONFIG} parse_hook @@ -271,9 +98,11 @@ for hook in $HOOKS; do unset BINARIES unset FILES install () { msg "${hook}: no install function..."; } - source "${HOOKDIR}/${hook}" - install - parse_hook + if grep "install ()" "${INSTDIR}/${hook}" /dev/null 2>&1; then + source "${INSTDIR}/${hook}" + install + parse_hook + fi #quick test to check for existance... need a better way... # note, this will only pick up valid run_hooks - a space is required if grep "run_hook ()" "${HOOKDIR}/${hook}" 2>&1>/dev/null; then @@ -289,7 +118,7 @@ fi if [ "x$GENIMG" != "x" ]; then if ! gen_init_cpio ${FILELIST} | gzip -9 > "${GENIMG}"; then - err "ERROR: Failed to create '${GENIMG}' image" >2 + err "Failed to create '${GENIMG}' image" >2 fi if [ "x${SAVELIST}" == "x" ]; then -- cgit v1.2.3-24-g4f1b