diff options
author | Aaron Griffin <aaron@archlinux.org> | 2006-04-22 01:00:28 +0200 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2006-04-22 01:00:28 +0200 |
commit | ea20a441f8fecc9fa84e0e1f12c4b71bf436f872 (patch) | |
tree | 1f2ff1cec1b0629f4ba5639729c9438bcdaf7d44 | |
parent | acc783c8af5514083e542fe7d91be6a1c5920ad7 (diff) | |
download | mkinitcpio-ea20a441f8fecc9fa84e0e1f12c4b71bf436f872.tar.gz mkinitcpio-ea20a441f8fecc9fa84e0e1f12c4b71bf436f872.tar.xz |
Hook updates and changes...
git-svn-id: http://projects.archlinux.org/svn/initramfs/mkinitcpio@7 880c04e9-e011-0410-abf7-b926e227c9cd
-rw-r--r-- | hooks/base | 9 | ||||
-rw-r--r-- | hooks/encrypt | 17 | ||||
-rw-r--r-- | hooks/filesystems | 25 | ||||
-rw-r--r-- | hooks/ide | 23 | ||||
-rw-r--r-- | hooks/raid | 17 | ||||
-rw-r--r-- | hooks/resume | 13 | ||||
-rw-r--r-- | hooks/sata | 34 | ||||
-rw-r--r-- | hooks/scsi | 34 | ||||
-rw-r--r-- | hooks/usb | 7 | ||||
-rw-r--r-- | install/base | 32 | ||||
-rw-r--r-- | install/encrypt | 15 | ||||
-rw-r--r-- | install/filesystems | 18 | ||||
-rw-r--r-- | install/ide | 22 | ||||
-rw-r--r-- | install/ide-auto | 22 | ||||
-rw-r--r-- | install/resume | 16 | ||||
-rw-r--r-- | install/sata | 21 | ||||
-rw-r--r-- | install/sata-auto | 20 | ||||
-rw-r--r-- | install/scsi | 20 | ||||
-rw-r--r-- | install/scsi-auto | 19 | ||||
-rw-r--r-- | install/udev | 18 | ||||
-rw-r--r-- | install/usb | 18 | ||||
-rw-r--r-- | install/usb-auto | 17 | ||||
-rw-r--r-- | mkinitcpio | 189 |
23 files changed, 446 insertions, 180 deletions
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 <<HELPEOF + This hook sets up all initial directories and installs base + klibc utilities and libraries. DO NOT remove this one unless + you know what you're doing. +HELPEOF +} diff --git a/install/encrypt b/install/encrypt new file mode 100644 index 0000000..e2087e4 --- /dev/null +++ b/install/encrypt @@ -0,0 +1,15 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" aes-i586 $(find "${MODULEDIR}/kernel/drivers/md" -name dm*.ko) " + BINARIES="cryptsetup.static" + FILES="" +} + +help () +{ +cat<<HELPEOF + This hook allows for an encrypted root device. +HELPEOF +} diff --git a/install/filesystems b/install/filesystems new file mode 100644 index 0000000..c012d1b --- /dev/null +++ b/install/filesystems @@ -0,0 +1,18 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" $(all_modules '/kernel/fs') " + BINARIES="" + FILES="" + SCRIPT="filesystems" +} + +help () +{ +cat<<HELPEOF + This hook is responsible for loading filesystems for the root device. + Detection will be done at runtime. If you would like to minimize the + modules installed in the image, use the -auto flavor. +HELPEOF +} diff --git a/install/ide b/install/ide new file mode 100644 index 0000000..1afedd9 --- /dev/null +++ b/install/ide @@ -0,0 +1,22 @@ +# vim: set ft=sh: + +install () +{ + MODULES="" + for m in $(all_modules | grep "/ide/"); + do + MODULES="$MODULES $(basename $m)" + done + BINARIES="" + FILES="" + SCRIPT="ide" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an ide root device. + Detection will take place at runtime. To minimize the modules + in the image, use the -auto flavor. +HELPEOF +} diff --git a/install/ide-auto b/install/ide-auto new file mode 100644 index 0000000..8a5a247 --- /dev/null +++ b/install/ide-auto @@ -0,0 +1,22 @@ +# vim: set ft=sh: + +install () +{ + MODULES="" + for m in $(auto_modules | grep "/ide/"); + do + MODULES="$MODULES $(basename $m)" + done + BINARIES="" + FILES="" + SCRIPT="ide" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an ide root device. + Detection will take place at runtime. To minimize the modules + in the image, use the -auto flavor. +HELPEOF +} diff --git a/install/resume b/install/resume new file mode 100644 index 0000000..b214b61 --- /dev/null +++ b/install/resume @@ -0,0 +1,16 @@ +# vim:set ft=sh: +install () +{ + MODULES="" + BINARIES="" + FILES="" + SCRIPT="resume" +} + +help () +{ +cat<<HELPEOF + This hook initializes support for resuming from Disk + and/or Memory. Supports suspend2 if found. +HELPEOF +} diff --git a/install/sata b/install/sata new file mode 100644 index 0000000..3c33376 --- /dev/null +++ b/install/sata @@ -0,0 +1,21 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" $(all_modules "scsi/.*ata") " + for m in $MODULES; do + [ "$m" == "ata_piix" ] && MODULES="$MODULES piix" + done + BINARIES="" + FILES="" + SCRIPT="sata" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an sata root device. + Detection will take place at runtime. To minimize the modules + in the image, use the -auto flavor. +HELPEOF +} diff --git a/install/sata-auto b/install/sata-auto new file mode 100644 index 0000000..d3e89b6 --- /dev/null +++ b/install/sata-auto @@ -0,0 +1,20 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" $(auto_modules "scsi/.*ata") " + for m in $MODULES; do + [ "$m" == "ata_piix" ] && MODULES="$MODULES piix" + done + BINARIES="" + FILES="" + SCRIPT="sata" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an sata root device. + Detection will take place at runtime. +HELPEOF +} diff --git a/install/scsi b/install/scsi new file mode 100644 index 0000000..3e6fa2f --- /dev/null +++ b/install/scsi @@ -0,0 +1,20 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" $(all_modules "/scsi/" | grep -v "ata") + $(all_modules "/block/") + $(all_modules "/fusion/")" + BINARIES="" + FILES="" + SCRIPT="scsi" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an scsi root device. + Detection will take place at runtime. To minimize the modules + in the image, use the -auto flavor. +HELPEOF +} diff --git a/install/scsi-auto b/install/scsi-auto new file mode 100644 index 0000000..45b93ef --- /dev/null +++ b/install/scsi-auto @@ -0,0 +1,19 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" $(auto_modules "/scsi/" | grep -v "ata") + $(auto_modules "/block/") + $(auto_modules "/fusion/")" + BINARIES="" + FILES="" + SCRIPT="scsi" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an scsi root device. + Detection will take place at runtime. +HELPEOF +} diff --git a/install/udev b/install/udev new file mode 100644 index 0000000..58b2448 --- /dev/null +++ b/install/udev @@ -0,0 +1,18 @@ +# vim:set ft=sh: + +install () +{ + MODULES="" + BINARIES="" + FILES=" /etc/udev/rules.d/udev.rules /etc/udev/udev.conf " + add_file /lib/initramfs/udevd /bin/udevd +} + +help () +{ +cat <<HELPEOF + This hook will use udev to create your root device node. + It is recommended to use this hook if you are using any + non ide/sata block device. +HELPEOF +} diff --git a/install/usb b/install/usb new file mode 100644 index 0000000..b7d1de8 --- /dev/null +++ b/install/usb @@ -0,0 +1,18 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" $(all_modules "/usb/") usb_storage usbhid" + BINARIES="" + FILES="" + SCRIPT="usb" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an usb root device. + Detection will take place at runtime. To minimize the modules + in the image, use the -auto flavor. +HELPEOF +} diff --git a/install/usb-auto b/install/usb-auto new file mode 100644 index 0000000..33932a2 --- /dev/null +++ b/install/usb-auto @@ -0,0 +1,17 @@ +# vim: set ft=sh: + +install () +{ + MODULES=" $(auto_modules "/usb/") usb_storage usbhid" + BINARIES="" + FILES="" + SCRIPT="usb" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for an usb root device. + Detection will take place at runtime. +HELPEOF +} @@ -8,9 +8,10 @@ # variables should be quoted and bracketed "${SOMEVAR}" # inline execution should be done with $() instead of backticks # use "x${var}" = "x" to test for nulls/empty strings -# incase of embedded spaces, quote all path names and string comaprissons +# incase of embedded spaces, quote all path names and string comarpisons # # TODO +# hook help: help() function in install script, "-h base" # Settings @@ -18,6 +19,7 @@ BASEDIR="" KERNELVERSION="$(uname -r)" CONFIG="mkinitcpio.conf" HOOKDIR="hooks" +INSTDIR="install" SAVELIST="" GENIMG="" APPEND="" @@ -88,181 +90,6 @@ else touch "${FILELIST}" fi -# Helper functions, just to make syntax clearer -auto_modules () -{ - aliases=$(find /sys/devices/ -name modalias -exec cat {} \;) - modprobe --show-depends -a $aliases 2>/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 |