From 65c3bc01fdbc90d0e03be835e8d770f627fa9871 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?J=C3=B6rg=20Kriegel?= Date: Sun, 22 Mar 2009 15:55:18 +0100 Subject: [PATCH] Use run-init instead of kinit Replaced kinit with run-init. The network stuff is mostly done in the new net hook. It is now possible to use network servers like dropbear. This also fixes the the init=... bug FS#8832. --- hooks/filesystems | 6 ++-- hooks/net | 70 ++++++++++++++++++++++++++++++++++++++++++ init | 87 ++++++++++++++++++++++++++++++++-------------------- install/net | 4 +- 4 files changed, 128 insertions(+), 39 deletions(-) create mode 100755 hooks/net diff --git a/hooks/filesystems b/hooks/filesystems index 306277b..1ee213f 100644 --- a/hooks/filesystems +++ b/hooks/filesystems @@ -12,7 +12,7 @@ run_hook () msg -n "Waiting for devices to settle..." /bin/sleep "${rootdelay}" msg "done." - export rootdelay=0 + rootdelay=0 fi eval $(/bin/parseblock "${root}") @@ -23,7 +23,7 @@ run_hook () FSTYPE="unknown" echo "ERROR: Failed to parse block device ids for '${root}'" else - export root="${BLOCKNAME}" + root="${BLOCKNAME}" echo "/bin/mknod \"${BLOCKNAME}\" b ${BLOCKDEVICE}" /bin/mknod "${BLOCKNAME}" b ${BLOCKDEVICE} >/dev/null fi @@ -40,7 +40,7 @@ run_hook () if [ "${FSTYPE}" = "unknown" ]; then echo "ERROR: root fs cannot be detected. Try using the rootfstype= kernel parameter." else - kinit_params="${kinit_params} rootfstype=${FSTYPE}" + rootfstype="${FSTYPE}" /sbin/modprobe -q "${FSTYPE}" >/dev/null 2>&1 fi } diff --git a/hooks/net b/hooks/net new file mode 100755 index 0000000..6a7c4d3 --- /dev/null +++ b/hooks/net @@ -0,0 +1,70 @@ +# vim:set ft=sh: + +run_hook () +{ + local line i address rootserver rootpath + + : > /ip_opts + + if [ -n "${ip}" ]; then + # setup network and save some values + ipconfig "${ip}" | while read line; do + echo ":: ${line}" + if [ "${line#"IP-Config:"}" != "${line}" ]; then + continue + fi + line="$(echo ${line})" + line="$(replace "${line}" " :" ":")" + line="$(replace "${line}" ": " ":")" + line="$(replace "${line}" ":" "=")" + for i in ${line}; do + ### echo "-> ${i}" + case "${i}" in + address=*) + echo "${i}" >> /ip_opts + ;; + rootserver=*) + echo "${i}" >> /ip_opts + ;; + rootpath=*) + echo "${i}" >> /ip_opts + ;; + esac + done + done + + # calculate nfs_server, nfs_path and nfs_option for later nfs mount + if [ "${root}" = "/dev/nfs" -o "${nfsroot}" != "" ]; then + . /ip_opts + + # default rootpath + if [ "${rootpath}" = "" ]; then + rootpath="/tftpboot/${address}" + fi + + # parse nfsroot + line="${nfsroot}" + nfs_server="${line%%:*}" + [ "${nfs_server}" = "${line}" ] && nfs_server="${rootserver}" + line="${line#*:}" + nfs_path="${line%%,*}" + line="${line#"${nfs_path}"}" + [ "${nfs_path}" = "" ] && nfs_path="${rootpath}" + nfs_option="${line#","}" + nfs_path="$(replace "${nfs_path}" "%s" "${address}")" + + # ensure root and filesystem type are set proper for nfs boot + root="/dev/nfs" + rootfstype="nfs" + + ### debug output + + ### echo "-> address='${address}'" + ### echo "-> rootserver='${rootserver}'" + ### echo "-> rootpath='${rootpath}'" + ### echo "-> nfs_server='${nfs_server}'" + ### echo "-> nfs_path='${nfs_path}'" + ### echo "-> nfs_option='${nfs_option}'" + fi + fi +} diff --git a/init b/init index 87dcc77..ba35ee7 100644 --- a/init +++ b/init @@ -1,49 +1,50 @@ #!/bin/sh -msg () { [ "${quiet}" != "y" ] && echo $@; } +msg () { [ "${quiet}" != "y" ] && echo "$@"; } err () { echo "ERROR: $@"; } -msg ":: Loading Initramfs" - /bin/mount -t sysfs none /sys /bin/mount -t proc none /proc +rootdelay="0" # preset delay for convenience read CMDLINE /proc/sys/kernel/modprobe - for cmd in ${CMDLINE}; do - case "${cmd}" in - \#*) break ;; # ignore everything after a # in the commandline - [0123456Ss]) export runlevel="${cmd}" ;; - single) export runlevel="S" ;; #some people use 'single' - #Allow "init=X" to pass-through - init=*) kinit_params="${kinit_params} ${cmd}" ;; - # only export stuff that does work with dash :) - *=*) cmd="$(replace -s= "${cmd}" '.' '_')" - cmd="$(replace -s= "${cmd}" '-' '_')" - export "${cmd}" - ;; - *) cmd="$(replace "${cmd}" '.' '_')" - cmd="$(replace "${cmd}" '-' '_')" - export "${cmd}=y" - ;; - esac + if [ -n "${init}" ]; then + init="${init} ${cmd}" + else + case "${cmd}" in + \#*) break ;; # ignore everything after a # in the commandline + [0123456Ss]) runlevel="${cmd}" ;; + single) runlevel="S" ;; #some people use 'single' + init=*) eval "${cmd}" ;; + # only process stuff that does work with dash :) + *=*) cmd="$(replace -s= "${cmd}" '.' '_')" + cmd="$(replace -s= "${cmd}" '-' '_')" + unset "${cmd%%=*}" + eval "${cmd}" + ;; + *) cmd="$(replace "${cmd}" '.' '_')" + cmd="$(replace "${cmd}" '-' '_')" + unset "${cmd%%=*}" + eval "${cmd}=y" + ;; + esac + fi done +msg ":: Loading Initramfs" + +echo "/sbin/modprobe" > /proc/sys/kernel/modprobe + if [ -n "${disablehooks}" ]; then for d in $(replace "${disablehooks}" ','); do - export "hook_${d}=disabled" + eval "hook_${d}=disabled" done fi if [ -n "${disablemodules}" ]; then for d in $(replace "${disablemodules}" ','); do - export "mod_${d}=disabled" + eval "mod_${d}=disabled" done fi @@ -81,8 +82,6 @@ fi if [ "${rootdelay}" != "0" ]; then msg -n "Waiting for devices to settle..." /bin/sleep "${rootdelay}" - export rootdelay=0 - export kinit_params="$kinit_params rootdelay=0" msg "done." fi @@ -92,7 +91,15 @@ if [ "${break}" = "y" ]; then PS1="ramfs$ " /bin/sh -i fi -if [ ! -b "${root}" ]; then +if [ -z "${rootfstype}" ]; then + # This duplicates code from the filesystem hook + # without this, mkinitcpio would fail for users who use + # neither the udev hook, nor the filesystem hook + eval $(/bin/fstype < ${root}) + rootfstype="${FSTYPE}" +fi + +if [ ! -b "${root}" -a "${rootfstype}" != "nfs" ]; then # This duplicates code from the filesystem hook # without this, mkinitcpio would fail for users who use # neither the udev hook, nor the filesystem hook @@ -104,7 +111,7 @@ if [ ! -b "${root}" ]; then elif [ -z "${BLOCKDEVICE}" ]; then echo "ERROR: Failed to parse block device ids for '${root}'" else - export root="${BLOCKNAME}" + root="${BLOCKNAME}" echo "/bin/mknod \"${BLOCKNAME}\" b ${BLOCKDEVICE}" /bin/mknod "${BLOCKNAME}" b ${BLOCKDEVICE} >/dev/null fi @@ -121,7 +128,7 @@ if [ ! -b "${root}" ]; then fi fi -msg ":: Initramfs Completed - control passing to kinit" +msg ":: Initramfs Completed - control passing to run-init" if [ -f "/message" ]; then msg "$(cat /message)" fi @@ -133,5 +140,17 @@ if [ -n "${udevpid}" ]; then /bin/sleep 0.01 fi +/bin/mkdir /real-root +if [ "${rootfstype}" = "nfs" ]; then + msg ":: /bin/nfsmount" ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" /real-root + /bin/nfsmount ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" /real-root +else + msg ":: /bin/mount -r -t" "${rootfstype}" "${root}" /real-root + /bin/mount -r -t "${rootfstype}" "${root}" /real-root +fi + +/bin/umount /sys +/bin/umount /proc -exec /bin/kinit -- "root=${root}" ${kinit_params} "${runlevel}" > /dev/null 2>&1 +unset HOME OLDPWD PWD #TERM +exec /bin/run-init /real-root ${init:-/sbin/init ${runlevel}} diff --git a/install/net b/install/net index b8b2af7..ec3064e 100644 --- a/install/net +++ b/install/net @@ -2,11 +2,11 @@ install () { - MODULES=" $(checked_modules "/drivers/net/") " + MODULES=" nfs $(checked_modules "/drivers/net/") " BINARIES="" FILES="" - SCRIPT="" + SCRIPT="net" } help () -- 1.6.2