summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Lecher <jlec@gentoo.org>2011-03-27 08:31:50 +0000
committerJustin Lecher <jlec@gentoo.org>2011-03-27 08:31:50 +0000
commit282cd48ea02bae84997c3810ebdc9d49398e1e55 (patch)
tree80ec09c990d33f5a5f0ba64910ff568008aa61f4 /sys-apps/kexec-tools/files
parentMention removal (diff)
downloadhistorical-282cd48ea02bae84997c3810ebdc9d49398e1e55.tar.gz
historical-282cd48ea02bae84997c3810ebdc9d49398e1e55.tar.bz2
historical-282cd48ea02bae84997c3810ebdc9d49398e1e55.zip
Allow bypassing of kexec during reboot, #357095; Proper usage of ASFLAGS, #313611
Package-Manager: portage-2.2.0_alpha28/cvs/Linux x86_64
Diffstat (limited to 'sys-apps/kexec-tools/files')
-rw-r--r--sys-apps/kexec-tools/files/kexec.init-ng101
1 files changed, 101 insertions, 0 deletions
diff --git a/sys-apps/kexec-tools/files/kexec.init-ng b/sys-apps/kexec-tools/files/kexec.init-ng
new file mode 100644
index 000000000000..20a03e3a35bb
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec.init-ng
@@ -0,0 +1,101 @@
+#!/sbin/runscript
+# Copyright 1999-2011 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-ng,v 1.1 2011/03/27 08:31:50 jlec Exp $
+
+depend() {
+ need localmount
+}
+
+image_path() {
+ local x= kver=$(uname -r)
+ for x in "${KNAME:-bzImage}" vmlinuz \
+ bzImage-"${kver}" vmlinuz-"${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)" mounted=false initrdopt=
+
+ if [ -z "${img}" ] ; 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)"
+ fi
+ fi
+
+ if [ -z "${img}" ] ; then
+ eerror "No kernel image found in ${BOOTPART}!"
+ ${mounted} && umount "${BOOTPART}"
+ return 1
+ fi
+
+ ebegin "Loading kernel image ${img} for kexec"
+ if [ -z "${ROOTPART}" ] ; then
+ ROOTPART="$(readlink -f "$(sed -n '/^\/[^ ]* \/ / s,^\([^ ]*\).*,\1,p' /etc/mtab)")"
+ fi
+ if [ -z "${KPARAM}" ] ; then
+ KPARAM="$(sed -e 's/ /\n/g' /proc/cmdline | grep -v -e "^root=" | tr '\n' ' ')"
+ fi
+
+ # Use the default initrd if it exists and none other given
+ if [ -z "${INITRD}" -a -e "${BOOTPART}"/initrd ] ; then
+ INITRD="${BOOTPART}/initrd"
+ fi
+ if [ -e "${INITRD}" ] ; then
+ initrdopt="--initrd=${INITRD}"
+ fi
+
+ kexec -l "${img}" --append="root=${ROOTPART} ${KPARAM}" ${initrdopt}
+ local res=$?
+
+ ${mounted} && umount "${BOOTPART}"
+ eend ${res}
+ return ${res}
+}
+
+start() {
+ [ "${LOAD_DURING_SHUTDOWN:-yes}" = "yes" ] && return 0
+
+ ebegin "Configuring kexec"
+ load_image
+ eend 0
+}
+
+stop() {
+ [ "${LOAD_DURING_SHUTDOWN:-yes}" != "yes" ] && return 0
+
+ ebegin "Configuring kexec"
+ if [ "`/sbin/runlevel|/bin/cut -c 3`" != "6" ]; then
+ einfo "Not rebooting, so disabling"
+ kexec -u
+ return 0
+ fi
+
+ if [ "`/sbin/runlevel|/bin/cut -c 3`" = "6" ] && [ -f /nokexec ]; then
+ einfo "Not using kexec during reboot"
+ rm -f /nokexec
+ kexec -u
+ return 0
+ fi
+
+ load_image
+ eend $?
+}