kdump-load.sh: Clean-up old/useless kdump initrd files
The kdump-steamos tooling creates an initrd file based in the running kernel version for kdump, during package installation (even if kdump is not the default crash collection mechanism). Such file lives in the /home partition. When SteamOS image is upgraded, with a new kernel, there is a mechanism to create a new initrd either manually or automatically, just before the kdump load; in the end, we may have lots of initrds (one per kernel version ever installed), but we don't have currently a way to clear that. Well, until now. We hereby introduce such a simple mechanism, to prevent waste of precious /home space with useless initrd files. It works by comparing installed kernels [0] with the kdump-initrd-* files in /home, and if we have some of these kdump initrds that have no match with any installed kernel, they are removed (and such operation is logged in the systemd journal). [0] Definition: installed kernel in our context is a kernel that has a modules folder in /lib/modules . Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
This commit is contained in:
@ -64,6 +64,27 @@ create_initrd() {
|
|||||||
export DRACUT_NO_XATTR=${DRACUT_XATTR}
|
export DRACUT_NO_XATTR=${DRACUT_XATTR}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This routine performs a clean-up by deleting the old/useless remaining
|
||||||
|
# kdump initrd files.
|
||||||
|
cleanup_unused_initrd() {
|
||||||
|
INSTALLED_KERNELS="${KDUMP_FOLDER}/.installed_kernels"
|
||||||
|
|
||||||
|
find /lib/modules/* -maxdepth 0 -type d -exec basename {} \;>"${INSTALLED_KERNELS}"
|
||||||
|
|
||||||
|
find "${KDUMP_FOLDER}"/* -name "kdump-initrd*" -type f -print0 | while IFS= read -r -d '' file
|
||||||
|
do
|
||||||
|
FNAME="$(basename "${file}" .img)"
|
||||||
|
KVER="${FNAME#kdump-initrd-}"
|
||||||
|
if ! grep -q "${KVER}" "${INSTALLED_KERNELS}" ; then
|
||||||
|
rm -f "${KDUMP_FOLDER}/${FNAME}.img"
|
||||||
|
logger "kdump-steamos: removed unused file \"${FNAME}.img\""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -f "${INSTALLED_KERNELS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if [ ! -s "/usr/share/kdump/kdump.conf" ]; then
|
if [ ! -s "/usr/share/kdump/kdump.conf" ]; then
|
||||||
logger "kdump-steamos: /usr/share/kdump/kdump.conf is missing, aborting."
|
logger "kdump-steamos: /usr/share/kdump/kdump.conf is missing, aborting."
|
||||||
exit 0
|
exit 0
|
||||||
@ -106,6 +127,7 @@ if [ "${USE_PSTORE_RAM}" -eq 1 ]; then
|
|||||||
if modprobe ramoops mem_address=0x"${MEM_START}" mem_size=${MEM_REQUIRED} record_size=${RECORD_SIZE}; then
|
if modprobe ramoops mem_address=0x"${MEM_START}" mem_size=${MEM_REQUIRED} record_size=${RECORD_SIZE}; then
|
||||||
# If Pstore is set, update grub.cfg to avoid reserving crashkernel memory.
|
# If Pstore is set, update grub.cfg to avoid reserving crashkernel memory.
|
||||||
logger "kdump-steamos: pstore-RAM was loaded successfully"
|
logger "kdump-steamos: pstore-RAM was loaded successfully"
|
||||||
|
cleanup_unused_initrd
|
||||||
grub_update pstore
|
grub_update pstore
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -118,6 +140,7 @@ if [ "${USE_PSTORE_RAM}" -eq 1 ]; then
|
|||||||
# no point in continuing since kdump cannot work.
|
# no point in continuing since kdump cannot work.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cleanup_unused_initrd
|
||||||
grub_update kdump
|
grub_update kdump
|
||||||
|
|
||||||
# Stolen from Debian kdump
|
# Stolen from Debian kdump
|
||||||
|
|||||||
Reference in New Issue
Block a user