hsavmcore: add dracut modules and systemd services for kdump initramfs

* Provide a dracut module and a systemd service for Fedora, RHEL and SLES.
* Provide a systemd service for Ubuntu.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Philipp Rudo <prudo@linux.ibm.com>
Acked-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Alexander Egorenkov
2020-10-28 14:57:37 +01:00
committed by Jan Höppner
parent 9fb2568134
commit f8d3e5069a
10 changed files with 583 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
# Setup
## Configure crashkernel
```shell
sudo grubby --args "crashkernel=512M" --update-kernel=ALL
sudo reboot
```
## Production kernel's root file system
- kdump mounts the production kernel's root file system under **/sysroot**.
## Dependencies
```shell
sudo dnf install -y fuse fuse-devel systemd-devel
```
## Build hsavmcore
```shell
make -C s390-tools/hsavmcore
```
## Install hsavmcore
```shell
sudo cp s390-tools/hsavmcore/hsavmcore /usr/sbin/
```
## Create swap file
```shell
sudo dd if=/dev/zero of=/var/crash/swap.img bs=1M count=1024
sudo mkswap /var/crash/swap.img
```
## Install hsavmcore.conf
### Test configuration
- Doesn't require HSA support
#### HSA cache in file
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /sysroot/var/crash
use_hsa_mem = 0
mount_debugfs = 1
hsa_size = 0x1ffff000
release_hsa = 0
bind_mount_vmcore = 1
EOF
```
#### HSA cache in memory
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /sysroot/var/crash
use_hsa_mem = 1
mount_debugfs = 1
hsa_size = 0x1ffff000
release_hsa = 0
bind_mount_vmcore = 1
swap = /sysroot/var/crash/swap.img
EOF
```
### Production configuration
- Works only on s390x
#### HSA cache in file
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /sysroot/var/crash
use_hsa_mem = 0
mount_debugfs = 1
hsa_size = -1
release_hsa = 1
bind_mount_vmcore = 1
EOF
```
#### HSA cache in memory
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /sysroot/var/crash
use_hsa_mem = 1
mount_debugfs = 1
hsa_size = -1
release_hsa = 1
bind_mount_vmcore = 1
swap = /sysroot/var/crash/swap.img
EOF
```
## Install new dracut module
```shell
sudo cp -r s390-tools/hsavmcore/initramfs/fedora-rhel/dracut/modules.d/99hsavmcore /lib/dracut/modules.d/
```
## Add the new dracut module as a dependency to the dracut module *kdumpbase*
```shell
sudo sed -e 's#local _dep="base shutdown"#local _dep="base shutdown hsavmcore"#' \
-i /lib/dracut/modules.d/99kdumpbase/module-setup.sh
```
## Rebuild kdump initramfs
```shell
sudo kdumpctl rebuild
```
## Enable swap LVM in kdump
- Required if you want to use a swap device in kdump
```shell
sudo sed -e 's#^KDUMP_COMMANDLINE_APPEND="\(.*\)"$#KDUMP_COMMANDLINE_APPEND="\1 rd.lvm.lv=rhel/swap"#' \
-i /etc/sysconfig/kdump
```
## Reload kdump
```shell
sudo kdumpctl reload
```
# Test
```shell
echo N | sudo tee /sys/module/kernel/parameters/crash_kexec_post_notifiers
echo c | sudo tee /proc/sysrq-trigger
```

View File

@@ -0,0 +1,20 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=hsavmcore Service
After=initrd.target initrd-parse-etc.service sysroot.mount
After=dracut-initqueue.service dracut-pre-mount.service dracut-mount.service dracut-pre-pivot.service
Before=kdump-capture.service
Before=initrd-cleanup.service
[Service]
Type=notify
ExecStart=/usr/sbin/hsavmcore -c /etc/hsavmcore.conf
StandardInput=null
StandardOutput=syslog
StandardError=syslog+console

View File

@@ -0,0 +1,37 @@
#!/usr/bin/bash
. $dracutfunctions
if ! [[ -d "${initdir}/tmp" ]]; then
mkdir -p "${initdir}/tmp"
fi
check() {
[[ $debug ]] && set -x
#kdumpctl sets this explicitly
if [ -z "$IN_KDUMP" ]
then
return 1
fi
return 0
}
depends() {
local _dep="base shutdown"
echo $_dep
return 0
}
installkernel() {
hostonly='' instmods fuse
}
install() {
inst "/usr/sbin/hsavmcore" "/usr/sbin/hsavmcore"
inst "/etc/hsavmcore.conf" "/etc/hsavmcore.conf"
inst "$moddir/hsavmcore.service" "$systemdsystemunitdir/hsavmcore.service"
mkdir -p "$initdir/$systemdsystemunitdir/initrd.target.wants"
ln_r "$systemdsystemunitdir/hsavmcore.service" "$systemdsystemunitdir/initrd.target.wants/hsavmcore.service"
inst_hook pre-mount 30 "$moddir/setup-fuse.sh"
}

View File

@@ -0,0 +1,3 @@
#!/bin/sh
modprobe fuse

View File

@@ -0,0 +1,141 @@
# Setup
## Configure crashkernel
```shell
sudo vim /etc/default/grub
sudo sed -e 's/GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 crashkernel=512M"/' \
-i /etc/default/grub
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
sudo reboot
```
## Production kernel's root file system
- kdump mounts the production kernel's root file system under **/kdump/mnt1**.
## Dependencies
```shell
sudo zypper install -y fuse fuse-devel systemd-devel
```
## Build hsavmcore
```shell
make -C s390-tools/hsavmcore
```
## Install hsavmcore
```shell
sudo cp s390-tools/hsavmcore/hsavmcore /usr/sbin/
```
## Create swap file
```shell
sudo dd if=/dev/zero of=/var/crash/swap.img bs=1M count=1024
sudo mkswap /var/crash/swap.img
```
## Install hsavmcore.conf
### Test configuration
- Doesn't require HSA support
#### HSA cache in file
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /kdump/mnt1/var/crash
use_hsa_mem = 0
mount_debugfs = 1
hsa_size = 0x1ffff000
release_hsa = 0
bind_mount_vmcore = 1
EOF
```
#### HSA cache in memory
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /kdump/mnt1/var/crash
use_hsa_mem = 1
mount_debugfs = 1
hsa_size = 0x1ffff000
release_hsa = 0
bind_mount_vmcore = 1
swap = /kdump/mnt1/var/crash/swap.img
EOF
```
### Production configuration
- Works only on s390x
#### HSA cache in file
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /kdump/mnt1/var/crash
use_hsa_mem = 0
mount_debugfs = 1
hsa_size = -1
release_hsa = 1
bind_mount_vmcore = 1
EOF
```
#### HSA cache in memory
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /kdump/mnt1/var/crash
use_hsa_mem = 1
mount_debugfs = 1
hsa_size = -1
release_hsa = 1
bind_mount_vmcore = 1
swap = /kdump/mnt1/var/crash/swap.img
EOF
```
## Install new dracut module
```shell
sudo cp -r s390-tools/hsavmcore/initramfs/sles/dracut/modules.d/99hsavmcore /usr/lib/dracut/modules.d/
```
## Add the new dracut module as a dependency to the dracut module *kdump*
```shell
sudo sed -e 's/_modules\[drm\]=/_modules[drm]=\n _modules[hsavmcore]=/' \
-i /usr/lib/dracut/modules.d/99kdump/module-setup.sh
```
## Rebuild kdump initramfs
```shell
sudo mkdumprd -f
```
## Reload kdump
```shell
systemctl enable kdump
systemctl restart kdump
```
# Test
```shell
echo c | sudo tee /proc/sysrq-trigger
```

View File

@@ -0,0 +1,21 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# See systemd.special(7) for details
[Unit]
Description=hsavmcore Service
Before=kdump-save.service
ConditionPathExists=/etc/initrd-release
ConditionPathExists=/proc/vmcore
[Service]
Type=notify
ExecStart=/usr/sbin/hsavmcore -c /etc/hsavmcore.conf
StandardInput=null
StandardOutput=syslog
StandardError=syslog+console

View File

@@ -0,0 +1,47 @@
#!/bin/bash
. /lib/kdump/setup-kdump.functions
kdump_needed() {
# Building a kdump initrd?
if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
return 0
fi
# Is FADUMP active?
if [ "$KDUMP_FADUMP" = "yes" ]; then
return 0
fi
# Do not include kdump by default
return 1
}
check() {
# Get configuration
kdump_get_config || return 1
kdump_needed || return 1
return 0
}
depends() {
echo "systemd"
return 0
}
installkernel() {
hostonly='' instmods fuse
}
install() {
inst_simple /usr/sbin/hsavmcore
inst_simple /etc/hsavmcore.conf
inst "$moddir/hsavmcore.service" "$systemdsystemunitdir/hsavmcore.service"
mkdir -p "$initdir/$systemdsystemunitdir/initrd.target.wants"
ln_r "$systemdsystemunitdir/hsavmcore.service" "$systemdsystemunitdir/initrd.target.wants/hsavmcore.service"
inst_hook pre-mount 30 "$moddir/setup-fuse.sh"
}

View File

@@ -0,0 +1,3 @@
#!/bin/sh
modprobe fuse

View File

@@ -0,0 +1,142 @@
# Setup
## Production kernel's root file system
- kdump mounts the production kernel's root file system under **/**.
## debugfs
- kdump mounts debugfs automatically.
## Dependencies
```shell
sudo apt-get install -y make gcc kdump-tools fuse libfuse-dev libsystemd-dev
```
## Build hsavmcore
```shell
make -C s390-tools/hsavmcore
```
## Install hsavmcore
```shell
sudo cp s390-tools/hsavmcore/hsavmcore /usr/sbin/
```
## Create swap file
```shell
sudo dd if=/dev/zero of=/var/crash/swap.img bs=1M count=1024
sudo mkswap /var/crash/swap.img
```
## Install hsavmcore.conf
### Test configuration
- Doesn't require HSA support
#### HSA cache in file
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /sysroot/var/crash
use_hsa_mem = 0
mount_debugfs = 0
hsa_size = 0x1ffff000
release_hsa = 0
bind_mount_vmcore = 1
EOF
```
#### HSA cache in memory
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /var/crash
use_hsa_mem = 1
mount_debugfs = 0
hsa_size = 0x1ffff000
release_hsa = 0
bind_mount_vmcore = 1
swap = /var/crash/swap.img
EOF
```
### Production configuration
- Works only on s390x
#### HSA cache in file
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /var/crash
use_hsa_mem = 0
mount_debugfs = 0
hsa_size = -1
release_hsa = 1
bind_mount_vmcore = 1
EOF
```
#### HSA cache in memory
```shell
cat <<EOF | sudo tee /etc/hsavmcore.conf
verbose = 2
workdir = /sysroot/var/crash
use_hsa_mem = 1
mount_debugfs = 0
hsa_size = -1
release_hsa = 1
bind_mount_vmcore = 1
swap = /var/crash/swap.img
EOF
```
## Install new dracut module
```shell
sudo cp s390-tools/hsavmcore/initramfs/ubuntu/hsavmcore.service /usr/lib/systemd/system/
```
## Add the new systemd service as a dependency to the service *kdump-tools-dump*
```shell
Wants=network-online.target dbus.socket systemd-resolved.service hsavmcore.service
After=network-online.target dbus.socket systemd-resolved.service hsavmcore.service
sudo sed -e 's/Wants=\(.*\)$/Wants=\1 hsavmcore.service/' \
-e 's/After=\(.*\)$/After=\1 hsavmcore.service/' \
-i /usr/lib/systemd/system/kdump-tools-dump.service
```
## Rebuild kdump initramfs
```shell
sudo rm -rf /var/lib/kdump/initrd*
sudo kdump-config unload
sudo kdump-config load
sudo systemctl restart kdump-tools
```
## Reload kdump
```shell
sudo kdump-config unload
sudo kdump-config load
```
# Test
```shell
echo N | sudo tee /sys/module/kernel/parameters/crash_kexec_post_notifiers
echo c | sudo tee /proc/sysrq-trigger
```

View File

@@ -0,0 +1,22 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=hsavmcore Service
Wants=network-online.target dbus.socket systemd-resolved.service
After=network-online.target dbus.socket systemd-resolved.service
Before=kdump-tools-dump.service
[Install]
WantedBy=kdump-tools-dump.service
[Service]
Type=notify
ExecStart=/usr/sbin/hsavmcore -c /etc/hsavmcore.conf
StandardInput=null
StandardOutput=syslog+console
StandardError=syslog+console