diff options
Diffstat (limited to 'sys-apps/kexec-tools/files/kexec.init-2.0.3')
-rw-r--r-- | sys-apps/kexec-tools/files/kexec.init-2.0.3 | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/sys-apps/kexec-tools/files/kexec.init-2.0.3 b/sys-apps/kexec-tools/files/kexec.init-2.0.3 new file mode 100644 index 000000000000..6ae811291133 --- /dev/null +++ b/sys-apps/kexec-tools/files/kexec.init-2.0.3 @@ -0,0 +1,119 @@ +#!/sbin/runscript +# Copyright 1999-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/sys-apps/kexec-tools/files/kexec.init-2.0.3,v 1.1 2012/03/18 07:46:02 jlec Exp $ + +depend() { + need localmount +} + +image_path() { + local x= kver=$(uname -r) karch=$(uname -m) + BOOTPART="${BOOTPART:-/boot}" + for x in "${KNAME:-bzImage}" vmlinuz \ + bzImage-${kver} vmlinuz-${kver} \ + kernel-genkernel-${karch}-${kver} \ + kernel-${kver} kernel-${karch}; do + if [[ -e "${BOOTPART}/${x}" ]] ; then + echo "${BOOTPART}/${x}" + return 0 + fi + done + + return 1 +} + +initrd_path() { + local x= kver=$(uname -r) karch=$(uname -m) + BOOTPART="${BOOTPART:-/boot}" + for x in "${INITRD:-initrd}" \ + initrd.img-${kver} initrd-${kver}.img \ + initrd-${kver} initramfs-${kver}.img \ + initramfs-genkernel-${karch}-${kver} ; do + if [[ -e "${BOOTPART}/${x}" ]] ; then + echo "${BOOTPART}/${x}" + return 0 + fi + done + + return 1 +} + +load_image() { + if [[ "${KNAME}" = "-" ]]; then + ebegin "Disabling kexec" + kexec -u + eend $? + return $? + fi + + BOOTPART="${BOOTPART:-/boot}" + local img="$(image_path)" initrd="$(initrd_path)" mounted=false initrdopt= + + if [[ -z "${img}" ]] || [[ -z "${initrd}" ]]; then + # If we cannot find our image, try mounting ${BOOTPART} + if ! grep -q " ${BOOTPART} " /proc/mounts; then + ebegin "Mounting ${BOOTPART}" + mount "${BOOTPART}" && mounted=true + eend $? || return $? + img="$(image_path)" + initrd="$(initrd_path)" + fi + fi + + if [[ -z "${img}" ]]; then + eerror "No kernel image found in ${BOOTPART}!" + ${mounted} && umount "${BOOTPART}" + return 1 + else + ebegin "Loading kernel image ${img} for kexec" + fi + + [[ -n "${ROOTPART}" ]] || \ + ROOTPART="$(readlink -f "$(sed -n '/^\/[^ ]* \/ / s,^\([^ ]*\).*,\1,p' /proc/mounts)")" + + [[ -n "${KPARAM}" ]] || KEXEC_OPT_ARGS+=" --reuse-cmdline" + + [[ -n "${initrd}" ]] && [[ -e "${initrd}" ]] && initrdopt="--initrd=${initrd}" + + einfo " Setting kexec with ${KEXEC_OPT_ARGS} -l ${img} root=${ROOTPART} ${KPARAM} ${initrdopt}" + kexec ${KEXEC_OPT_ARGS} -l "${img}" --append="root=${ROOTPART} ${KPARAM}" ${initrdopt} + local res=$? + + ${mounted} && umount "${BOOTPART}" + eend ${res} + return ${res} +} + +start() { + if [[ "${LOAD_DURING_SHUTDOWN:-yes}" = "yes" ]]; then + image_path > /dev/null || \ + ewarn "Cannot find kernel image. Please make sure a valid kernel image is present before reboot." + return 0 + else + ebegin "Configuring kexec" + load_image + eend $? + fi +} + +stop() { + [[ "${LOAD_DURING_SHUTDOWN:-yes}" != "yes" ]] && return 0 + + if ! yesno $RC_REBOOT; then + einfo "Not rebooting, so disabling" + kexec -u + return 0 + fi + + if [[ -f /nokexec ]]; then + einfo "Not using kexec during reboot" + rm -f /nokexec + kexec -u + return 0 + fi + + ebegin "Configuring kexec" + load_image + eend $? +} |