Files
kdumpst/save-dumps.sh.in
Guilherme G. Piccoli a3ab8c421b all: Refactor the whole kdump/pstore folder setting
This is somewhat a big refactor. The early design of kdump/pstore was
meant to support the A/B scheme of Steam Deck and a dracut-based initrd
only. In this scheme, we had a DEVNODE (like nvme partition or a devlink)
that represented the device node to be mounted early in boot when kdump
was in use. Also, we had a folder defined in the config file on top of
such dev node, and a temporary file used to "carry" the composition of
the full kdump path across boot time scripts. Yeah, kinda complex setup.

We are now moving to a more generic approach, and for that, the design
choice was a more convenient/simple one for the common cases, that
requires some operations to properly work on SteamOS dracut-based initrd.
Now we have only a single path on config file, which should be accessible
in a R/W filesystem by both scripts executed in the systemd service. No
devnode information or temp file is used anymore.

But with that, comes the need of discovering the proper devnode and base
folder for kdump'ing early in boot, from the initrd. Using the findmnt
tool we manage to derive all the necessary data during the initrd
preparation phase. Also, while at it we manage to fix an "inconsistency"
of our dracut initrd creation script: installkernel() should be responsible
to deal with DRM modules removal, not install().

On top of this (already big) change, now our dracut initrd excludes not
only amdgpu driver/FWs, but radeon, nvidia and i915 as well. And due to
our refactor of the mount point information (using findmnt to collect info
during dracut initrd creation), we also allow now arbitrary filesystem
drivers to be included, i.e., we don't hardcode/limit for ext4 only.

Again, mea culpa for not splitting this in multiple atomic/simple commits,
the burden to keep a pretty git log is starting to consume precious time.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
2023-03-31 15:34:42 -03:00

123 lines
3.5 KiB
Bash

load_kdump_config
MAIN_FOLDER="${MOUNT_FOLDER}"
if [ ! -d "${MAIN_FOLDER}" ]; then
logger "kdump: invalid folder (${MAIN_FOLDER}) - aborting..."
exit 1
fi
LOGS_FOUND=0
KDUMP_TMP_FOLDER="${MAIN_FOLDER}/.tmp"
# Use UTC timezone to match kdump collection
CURRENT_TSTAMP=$(date -u +"%Y%m%d%H%M")
# By default, pstore is mounted in this location; if it isn't, we bail-out.
# Notice we currently only support the logs generated by the ramoops backend.
PSTORE_CNT=$(find /sys/fs/pstore/* 2>/dev/null | grep -c ramoops)
if [ "${PSTORE_CNT}" -ne 0 ]; then
PSTORE_FOLDER="${KDUMP_TMP_FOLDER}/pstore"
mkdir -p "${PSTORE_FOLDER}"
LOOP_CNT=0
while [ "${PSTORE_CNT}" -gt 0 ]; do
PSTORE_FILE="$(find /sys/fs/pstore/* | grep dmesg-ramoops | sort | head -n1)"
SAVED_FILE="${PSTORE_FOLDER}/dmesg-pstore.${CURRENT_TSTAMP}-${LOOP_CNT}"
if [ -e "${PSTORE_FILE}" ]; then
cat "${PSTORE_FILE}" > "${SAVED_FILE}"
sync "${SAVED_FILE}"
rm -f "${PSTORE_FILE}"
fi
PSTORE_CNT=$((PSTORE_CNT - 1))
LOOP_CNT=$((LOOP_CNT + 1))
done
LOGS_FOUND=${LOOP_CNT}
# Logs should live on <...>/.tmp folder, due to the zip compression.
mv "${PSTORE_FOLDER}"/* "${KDUMP_TMP_FOLDER}/" 2>/dev/null
rm -rf "${PSTORE_FOLDER}"
fi
# Now, we proceed the same way if there are kdump data.
KDUMP_CRASH_FOLDER="${MAIN_FOLDER}/crash"
KDUMP_CNT=$(find "${KDUMP_CRASH_FOLDER}"/* -type d 2>/dev/null | wc -l)
if [ "${KDUMP_CNT}" -ne 0 ]; then
KD_FOLDER="${KDUMP_TMP_FOLDER}/kdump"
mkdir -p "${KD_FOLDER}"
LOOP_CNT=0
while [ "${KDUMP_CNT}" -gt 0 ]; do
CRASH_CURRENT=$(find "${KDUMP_CRASH_FOLDER}"/* -type d 2>/dev/null | head -n1)
# When collecting the vmcore/dmesg during kdump, folder is
# saved with its name == the timestamp of the collection.
CRASH_TSTAMP=$(basename "${CRASH_CURRENT}")
if [ -s "${CRASH_CURRENT}/dmesg.txt" ]; then
SAVED_FILE="${KD_FOLDER}/dmesg-kdump.${CRASH_TSTAMP}"
mv "${CRASH_CURRENT}/dmesg.txt" "${SAVED_FILE}"
sync "${SAVED_FILE}"
fi
# We won't pack vmcores in the zip blob, but let's save
# it in case it was collected as well.
if [ -s "${CRASH_CURRENT}/vmcore.compressed" ]; then
SAVED_FILE="${KDUMP_CRASH_FOLDER}/vmcore.${CRASH_TSTAMP}"
mv "${CRASH_CURRENT}/vmcore.compressed" "${SAVED_FILE}"
sync "${SAVED_FILE}"
fi
rm -rf "${CRASH_CURRENT}"
KDUMP_CNT=$((KDUMP_CNT - 1))
LOOP_CNT=$((LOOP_CNT + 1))
done
LOGS_FOUND=$((LOGS_FOUND + LOOP_CNT))
# Logs should live on .tmp folder, due to the zip compression.
mv "${KD_FOLDER}"/* "${KDUMP_TMP_FOLDER}/" 2>/dev/null
rm -rf "${KD_FOLDER}"
fi
# If we have pstore and/or kdump logs, let's process them...
LOGS_FOLDER="${MAIN_FOLDER}/logs"
if [ ${LOGS_FOUND} -ne 0 ]; then
mkdir -p "${LOGS_FOLDER}"
# First we collect some more info, like DMI data, os-release, etc;
DMI_FNAME="${KDUMP_TMP_FOLDER}/dmidecode.${CURRENT_TSTAMP}"
dmidecode > "${DMI_FNAME}"
BUILD_FNAME="${KDUMP_TMP_FOLDER}/build.${CURRENT_TSTAMP}"
cp "/etc/os-release" "${BUILD_FNAME}"
VERSION_FNAME="${KDUMP_TMP_FOLDER}/version.${CURRENT_TSTAMP}"
uname -r > "${VERSION_FNAME}"
sync "${DMI_FNAME}" "${BUILD_FNAME}" "${VERSION_FNAME}"
# Create the dump compressed pack.
LOG_FNAME="kdump-${CURRENT_TSTAMP}.zip"
LOG_FNAME="${LOGS_FOLDER}/${LOG_FNAME}"
zip -9 -jq "${LOG_FNAME}" "${KDUMP_TMP_FOLDER}"/* 1>/dev/null
sync "${LOG_FNAME}" 2>/dev/null
if [ ! -s "${LOG_FNAME}" ]; then
logger "kdump: couldn't create the compressed log archive"
logger "kdump: check folder \"${KDUMP_TMP_FOLDER}\" for logs"
else
logger "kdump: logs saved in \"${LOGS_FOLDER}\""
fi
fi
rm -rf "${KDUMP_TMP_FOLDER}"