Package: kexec-tools
Version: 1:2.0.3-2
Severity: wishlist
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu saucy ubuntu-patch

Hi Khalid,

In Ubuntu, the attached patch was applied to the kexec-tools package to
support automatic handling of kernel crashes.  You may be interested to
consider including this in Debian as well.

This adds a dependency on makedumpfile, and it's possible that this
duplicates the kdump-tools package that's currently in the Debian archive.
So perhaps this should be redirected there instead?

The Ubuntu changelog entry for this kexec-tools package change is:

    - Add and install kdump init script and initramfs snippet; depend on
      initramfs-tools and call update-initramfs.
    - Also call update-grub after update-initramfs if /boot/grub/grub.cfg
      exists.
    - Depend on makedumpfile (on appropriate architectures), for use in 
      the initramfs script.

Thanks for considering the patch.

-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slanga...@ubuntu.com                                     vor...@debian.org
=== modified file 'debian/control'
--- debian/control	2013-01-13 19:39:31 +0000
+++ debian/control	2013-05-03 00:45:09 +0000
@@ -8,7 +8,7 @@
 
 Package: kexec-tools
 Architecture: i386 amd64 ppc64 powerpc ia64 s390 arm armel armhf sh4
-Depends: ${shlibs:Depends}, ${misc:Depends}, debconf
+Depends: ${shlibs:Depends}, ${misc:Depends}, debconf, initramfs-tools, makedumpfile [i386 amd64 powerpc ia64]
 Description: tools to support fast kexec reboots
  This package provides tools to load a kernel into memory and then
  "reboot" directly into that kernel using the kexec system call,

=== added file 'debian/kdump.init.d'
--- debian/kdump.init.d	1970-01-01 00:00:00 +0000
+++ debian/kdump.init.d	2013-05-02 16:24:49 +0000
@@ -0,0 +1,83 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:		kdump
+# Required-Start:	$local_fs
+# Required-Stop:	$local_fs
+# Should-Start:
+# Should-Stop:
+# Default-Start:	0 1 2 3 4 5
+# Default-Stop:		6
+# Short-Description: Load crashkernel image with kexec
+# Description:
+### END INIT INFO
+
+PATH=/usr/sbin:/usr/bin:/sbin:/bin
+
+. /lib/lsb/init-functions
+
+KVER="`uname -r`"
+KERNEL_IMAGE="/boot/vmlinuz-$KVER"
+INITRD="/boot/initrd.img-$KVER"
+
+# Without makedumpfile, there will be no vmcore on crash, so no point
+test -x /usr/bin/makedumpfile || exit 0
+if [ ! -e "$KERNEL_IMAGE" -o ! -e "$INITRD" ]; then
+	exit 0;
+fi
+
+
+do_start () {
+	test -x /sbin/kexec || exit 0
+
+	# We have to be booted with crashkernel= to work. See
+	# /boot/grub/menu.lst
+	grep -q crashkernel= /proc/cmdline || exit 0
+
+	# Remove crashkernel, vga, video and splash options
+	APPEND=""
+	for x in `cat /proc/cmdline`; do
+		case $x in
+			splash*|vga*|video*|crashkernel*|quiet)
+				;;
+			*)
+				APPEND="$APPEND $x"
+				;;
+		esac
+	done
+
+	# Append kdump_needed for initramfs to know what to do, and add
+	# maxcpus=1 to keep things sane.
+	APPEND="$APPEND kdump_needed maxcpus=1 irqpoll reset_devices"
+
+	# --elf32-core-headers is needed for 32-bit systems (ok
+	# for 64-bit ones too).
+	log_action_begin_msg "Loading crashkernel"
+	kexec -p "$KERNEL_IMAGE" --initrd="$INITRD" --append="$APPEND"
+	log_action_end_msg $?
+}
+
+run_apport_on_vmcore()
+{
+    if [ -e /var/crash/vmcore -a -x /usr/share/apport/kernel_crashdump ]; then
+	/usr/share/apport/kernel_crashdump || true
+    fi
+}
+
+case "$1" in
+  start)
+	run_apport_on_vmcore
+	do_start
+	;;
+  restart|reload|force-reload)
+	echo "Error: argument '$1' not supported" >&2
+	exit 3
+	;;
+  stop)
+	# No-op
+	;;
+  *)
+	echo "Usage: $0 start|stop" >&2
+	exit 3
+	;;
+esac
+exit 0

=== added file 'debian/kdump.initramfs'
--- debian/kdump.initramfs	1970-01-01 00:00:00 +0000
+++ debian/kdump.initramfs	2013-05-02 16:24:49 +0000
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+PREREQ=""
+prereqs()
+{
+	echo "$PREREQ"
+}
+case $1 in
+# get pre-requisites
+prereqs)
+	prereqs
+	exit 0
+	;;
+esac
+
+KVER="`uname -r`"
+CRASHFILE="/var/crash/vmcore"
+MAKEDUMPFILE="/usr/bin/makedumpfile"
+LOG="$rootmnt/var/crash/vmcore.log"
+VMCORE="/proc/vmcore"
+
+# Check that this is a kexec kernel.
+grep -q kdump_needed /proc/cmdline || exit 0
+
+# Do NOT exit the script after this point, or the system will start
+# booting inside the crash kernel.
+
+. ./scripts/functions
+
+# Unconditionally mount /dev in the target, in case it's needed.
+mount -n --bind /dev ${rootmnt}/dev
+
+# Check if any additional filesystems need to be mounted in order to run
+# makedumpfile
+# We assume that the system rootfs is now mounted on ${rootmnt}
+for target in /usr /boot /var
+do
+	# We write to /var; everything else should be mounted ro
+	if [ "$target" = /var ]; then
+		opts=
+	else
+		opts=-oro
+	fi
+	if [ -n "$(awk '$2 == "'$target'" { print $2 }' ${rootmnt}/etc/fstab)" ]
+	then
+		chroot ${rootmnt} mount -n $opts $target
+		mounted="$target $mounted"
+	fi
+done
+
+# Make sure makedumpfile assumptions are satisfied.
+while ! test -x "$rootmnt/$MAKEDUMPFILE"; do
+	panic "kdump: Missing $rootmnt/$MAKEDUMPFILE"
+done
+
+log_begin_msg "Saving vmcore from kernel crash"
+
+mount $rootmnt -o remount,rw
+
+mount -n --bind /proc $rootmnt/proc
+
+# Delete it if the copy fails, mainly to keep from filling up filesystems
+# by accident.
+#
+chroot $rootmnt $MAKEDUMPFILE -E -d 31 $VMCORE $CRASHFILE > $LOG 2>&1 || \
+	rm -f $rootmnt/$CRASHFILE
+
+chmod 400 $rootmnt/$CRASHFILE
+
+# Unmount any extra filesystems we had to mount
+for target in $mounted; do
+	umount -n ${rootmnt}$target
+done
+
+mount $rootmnt -o remount,ro
+reboot
+
+log_end_msg

=== modified file 'debian/kexec-tools.postinst'
--- debian/kexec-tools.postinst	2013-01-13 19:39:31 +0000
+++ debian/kexec-tools.postinst	2013-05-02 21:51:40 +0000
@@ -127,6 +127,14 @@
                                                                                                                               
 # ------------------------- Debconf questions end ---------------------
 
+update-initramfs -u
+
+# no triggers in grub2,
+#  see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=481542
+if [ -x /usr/sbin/update-grub ] && [ -e /boot/grub/grub.cfg ]; then
+	update-grub
+fi
+
 #DEBHELPER#
 
 exit 0

=== modified file 'debian/rules'
--- debian/rules	2013-01-13 19:39:31 +0000
+++ debian/rules	2013-05-02 21:43:18 +0000
@@ -19,10 +19,12 @@
 	CFLAGS += -O2
 endif
 
+DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
+
 configure: configure-stamp
 configure-stamp: 
 	dh_testdir
 	# Add here commands to configure the package.
 	autoheader
 	autoconf
 	CPPFLAGS="$(shell dpkg-buildflags --get CPPFLAGS)" CFLAGS="$(shell dpkg-buildflags --get CFLAGS)" LDFLAGS="$(shell dpkg-buildflags --get LDFLAGS)" ./configure --prefix=/usr --sbindir=/sbin --mandir=/usr/share/man --datadir=/usr/share
@@ -64,6 +66,10 @@
 
 	# Add here commands to install the package into debian/tmp.
 	$(MAKE) install DESTDIR=$(CURDIR)/debian/kexec-tools
+ifneq (,$(filter $(DEB_HOST_ARCH),i386 amd64 powerpc ia64))
+	install -D -m755 debian/kdump.initramfs \
+		debian/kexec-tools/usr/share/initramfs-tools/scripts/init-bottom/0_kdump
+endif
 ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
 	[ ! -f $(CURDIR)/debian/kexec-tools/usr/lib/kexec-tools-testing/kexec_test.static ] || strip $(CURDIR)/debian/kexec-tools/usr/lib/kexec-tools-testing/kexec_test.static
 endif
@@ -83,6 +89,7 @@
 	dh_installdebconf
 	dh_installinit --no-start -r --name=kexec -- start 85 6 .
 	dh_installinit --no-start -r --name=kexec-load -- stop 18 6 .
+	dh_installinit --no-start -r --name=kdump -- start 00 2 .
 	dh_installexamples
 	dh_lintian
 	dh_install

Reply via email to