[baseimage]: kdump support (#3722)

* In the event of a kernel crash, we need to gather as much information
as possible to understand and identify the root cause of the crash.
Currently, the kernel does not provide much information, which make
kernel crash investigation difficult and time consuming.

Fortunately, there is a way in the kernel to provide more information
in the case of a kernel crash. kdump is a feature of the Linux kernel
that creates crash dumps in the event of a kernel crash. This PR
will add kermel kdump support.

An extension to the CLI utilities config and show is provided to
configure and manage kdump:
 - enable / disable kdump functionality
 - configure kdump (how many kernel crash logs can be saved, memory
   allocated for capture kernel)
 - view kernel crash logs
This commit is contained in:
Olivier Singla 2019-11-09 02:08:42 -05:00 committed by lguohan
parent be3421c352
commit c70d8bca9f
9 changed files with 126 additions and 2 deletions

View File

@ -272,7 +272,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
locales \ locales \
cgroup-tools \ cgroup-tools \
ipmitool \ ipmitool \
ndisc6 ndisc6 \
makedumpfile
if [[ $CONFIGURED_ARCH == amd64 ]]; then if [[ $CONFIGURED_ARCH == amd64 ]]; then
@ -289,6 +290,10 @@ sudo LANG=c chroot $FILESYSTEM_ROOT chmod 600 /etc/shadow
sudo LANG=c chroot $FILESYSTEM_ROOT chmod 644 /etc/passwd sudo LANG=c chroot $FILESYSTEM_ROOT chmod 644 /etc/passwd
sudo LANG=c chroot $FILESYSTEM_ROOT chmod 644 /etc/group sudo LANG=c chroot $FILESYSTEM_ROOT chmod 644 /etc/group
# Needed to install kdump-tools
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "mkdir -p /etc/initramfs-tools/conf.d"
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "echo 'MODULES=most' >> /etc/initramfs-tools/conf.d/driver-policy"
#Adds a locale to a debian system in non-interactive mode #Adds a locale to a debian system in non-interactive mode
sudo sed -i '/^#.* en_US.* /s/^#//' $FILESYSTEM_ROOT/etc/locale.gen && \ sudo sed -i '/^#.* en_US.* /s/^#//' $FILESYSTEM_ROOT/etc/locale.gen && \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT locale-gen "en_US.UTF-8" sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT locale-gen "en_US.UTF-8"

View File

@ -160,6 +160,10 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libnss-tacplus_*.deb || \
sudo LANG=C chroot $FILESYSTEM_ROOT pam-auth-update --remove tacplus sudo LANG=C chroot $FILESYSTEM_ROOT pam-auth-update --remove tacplus
sudo sed -i -e '/^passwd/s/ tacplus//' $FILESYSTEM_ROOT/etc/nsswitch.conf sudo sed -i -e '/^passwd/s/ tacplus//' $FILESYSTEM_ROOT/etc/nsswitch.conf
# Install a custom version of kdump-tools (and its dependencies via 'apt-get -y install -f')
sudo DEBIAN_FRONTEND=noninteractive dpkg --root=$FILESYSTEM_ROOT -i $debs_path/kdump-tools_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=truechroot $FILESYSTEM_ROOT apt-get -q --no-install-suggests --no-install-recommends --force-no install
# Copy crontabs # Copy crontabs
sudo cp -f $IMAGE_CONFIGS/cron.d/* $FILESYSTEM_ROOT/etc/cron.d/ sudo cp -f $IMAGE_CONFIGS/cron.d/* $FILESYSTEM_ROOT/etc/cron.d/

13
rules/kdump-tools.mk Normal file
View File

@ -0,0 +1,13 @@
# kdump-tools package
KDUMP_TOOLS_VERSION_BASE = 1.6.1
KDUMP_TOOLS_VERSION = $(KDUMP_TOOLS_VERSION_BASE)-1
export KDUMP_TOOLS_VERSION_BASE
export KDUMP_TOOLS_VERSION
KDUMP_TOOLS = kdump-tools_$(KDUMP_TOOLS_VERSION)_all.deb
$(KDUMP_TOOLS)_SRC_PATH = $(SRC_PATH)/kdump-tools
SONIC_MAKE_DEBS += $(KDUMP_TOOLS)
SONIC_STRETCH_DEBS += $(KDUMP_TOOLS)
export KDUMP_TOOLS

View File

@ -614,6 +614,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(SONIC_DEVICE_DATA) \ $(SONIC_DEVICE_DATA) \
$(PYTHON_CLICK) \ $(PYTHON_CLICK) \
$(IFUPDOWN2) \ $(IFUPDOWN2) \
$(KDUMP_TOOLS) \
$(LIBPAM_TACPLUS) \ $(LIBPAM_TACPLUS) \
$(LIBNSS_TACPLUS)) \ $(LIBNSS_TACPLUS)) \
$$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) \ $$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) \

View File

@ -289,7 +289,9 @@ RUN apt-get update && apt-get install -y \
rrdtool \ rrdtool \
# For smartmontools 6.6-1 # For smartmontools 6.6-1
automake1.11 \ automake1.11 \
libselinux1-dev libselinux1-dev \
# For kdump-tools
liblzo2-dev
# For smartmontools 6.6-1 # For smartmontools 6.6-1
RUN apt-get -t stretch-backports install -y debhelper RUN apt-get -t stretch-backports install -y debhelper

32
src/kdump-tools/Makefile Normal file
View File

@ -0,0 +1,32 @@
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e
MAIN_TARGET = $(KDUMP_TOOLS)
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
# Remove any stale files
rm -rf ./makedumpfile_$(KDUMP_TOOLS_VERSION_BASE).orig.tar.gz ./makedumpfile_$(KDUMP_TOOLS_VERSION).debian.tar.xz
rm -rf ./makedumpfile-$(KDUMP_TOOLS_VERSION_BASE)
# Get makedumpfile release
wget http://deb.debian.org/debian/pool/main/m/makedumpfile/makedumpfile_$(KDUMP_TOOLS_VERSION_BASE).orig.tar.gz
wget http://deb.debian.org/debian/pool/main/m/makedumpfile/makedumpfile_$(KDUMP_TOOLS_VERSION).debian.tar.xz
tar -f makedumpfile_$(KDUMP_TOOLS_VERSION_BASE).orig.tar.gz -x
pushd ./makedumpfile-$(KDUMP_TOOLS_VERSION_BASE)
tar -f ../makedumpfile_$(KDUMP_TOOLS_VERSION).debian.tar.xz -x
git init
git add -f *
git commit -m "unmodified kdump-tools source"
# Apply patches
stg init
stg import -s ../patch/series
# Build source and Debian packages
fakeroot debian/rules binary-indep
popd
# Move the newly-built .deb packages to the destination directory
mv $* $(DEST)/

View File

@ -0,0 +1,41 @@
From 7e6c0d5b0c7299154f75f281c02cf02cf85fb80e Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.drung@profitbricks.com>
Date: Thu, 2 Mar 2017 19:52:23 +0100
Subject: [PATCH] Generate initramfs for installed kernels in chroot
The postinst script from kdump-tools creates an initramfs for the
running kernel. When running inside a chroot, the running kernel (from
the host) might differ from the kernels that are available in the
chroot.
Thus generate the initramfs only when the running kernel is installed in
the system. Otherwise generate the initramfs for all installed kernels.
Bug-Debian: #856594
---
debian/kdump-tools.postinst | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/debian/kdump-tools.postinst b/debian/kdump-tools.postinst
index 4b6c6be..f604c8e 100755
--- a/debian/kdump-tools.postinst
+++ b/debian/kdump-tools.postinst
@@ -33,7 +33,15 @@ update_param() {
case "$1" in
configure)
# create smaller initrd.img files for kdump use
- /etc/kernel/postinst.d/kdump-tools $(uname -r) > /dev/null 2>&1
+ if test -d /lib/modules/$(uname -r); then
+ /etc/kernel/postinst.d/kdump-tools $(uname -r) > /dev/null 2>&1
+ else
+ # Running kernel not installed. Running in chroot?
+ for kernel_release in $(ls /lib/modules/); do
+ /etc/kernel/postinst.d/kdump-tools $kernel_release > /dev/null 2>&1
+ kdump-config symlinks $kernel_release
+ done
+ fi
# Customize crashkernel= value according to architecture
ARCH="$(arch)"
--
2.9.3

View File

@ -0,0 +1,24 @@
--- a/debian/kdump-config.orig 2019-10-24 09:38:19.006679000 -0700
+++ b/debian/kdump-config 2019-10-24 12:16:23.791899000 -0700
@@ -639,8 +639,8 @@
{
KDUMP_STAMP=`date +"%Y%m%d%H%M"`
KDUMP_STAMPDIR=$(define_stampdir $KDUMP_STAMP)
- KDUMP_CORETEMP="$KDUMP_STAMPDIR/dump-incomplete"
- KDUMP_COREFILE="$KDUMP_STAMPDIR/dump.$KDUMP_STAMP"
+ KDUMP_CORETEMP="$KDUMP_STAMPDIR/kdump-incomplete"
+ KDUMP_COREFILE="$KDUMP_STAMPDIR/kdump.$KDUMP_STAMP"
KDUMP_DMESGFILE="$KDUMP_STAMPDIR/dmesg.$KDUMP_STAMP"
# If we use NFS, verify that we can mount the FS
@@ -755,8 +755,8 @@
KDUMP_STAMP=`date +"%Y%m%d%H%M"`
KDUMP_STAMPDIR=$(define_stampdir $KDUMP_STAMP)
- KDUMP_CORETEMP="$KDUMP_STAMPDIR/dump-incomplete"
- KDUMP_COREFILE="$KDUMP_STAMPDIR/dump.$KDUMP_STAMP"
+ KDUMP_CORETEMP="$KDUMP_STAMPDIR/kdump-incomplete"
+ KDUMP_COREFILE="$KDUMP_STAMPDIR/kdump.$KDUMP_STAMP"
KDUMP_TMPDMESG="/tmp/dmesg.$KDUMP_STAMP"
KDUMP_DMESGFILE="$KDUMP_STAMPDIR/dmesg.$KDUMP_STAMP"
ERROR=0

View File

@ -0,0 +1,2 @@
0001-Generate-initramfs-for-installed-kernels-in-chroot.patch
0002-core-file-prefixed-by-kdump.patch