When fadump mode is enabled, the default initrd is rebuilt with kdump
dracut module. As the default initrd is altered, the original default
initrd is backed up. But we are not restoring it when fadump mode is
disabled. This patch tries to restore the backed up default initrd on
disabling fadump mode.
Signed-off-by: Hari Bathini <hbathini(a)linux.vnet.ibm.com>
---
Changes from v2:
* Using `uname -r` for kernel version instead of $kdump-kver
for fadump.
* Detecting mode switch and rebuilding initrd
kdumpctl | 78 +++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 57 insertions(+), 21 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index d0bbb55..a7f968b 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -9,6 +9,8 @@ MKDUMPRD="/sbin/mkdumprd -f"
SAVE_PATH=/var/crash
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
DUMP_TARGET=""
+DEFAULT_INITRD=""
+DEFAULT_INITRD_BAK=""
TARGET_INITRD=""
FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled"
FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered"
@@ -154,9 +156,6 @@ rebuild_fadump_initrd()
{
local target_initrd_tmp
- # backup fadump initrd for reference before replacing it
- backup_initrd
-
# this file tells the initrd is fadump enabled
touch /tmp/fadump.initramfs
target_initrd_tmp="$TARGET_INITRD.tmp"
@@ -190,8 +189,17 @@ rebuild_kdump_initrd()
rebuild_initrd()
{
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then
+ # backup initrd for reference before replacing it
+ # with fadump aware initrd
+ backup_default_initrd
+
rebuild_fadump_initrd
else
+ # check if a backup of default initrd exists. If yes,
+ # it signifies a switch from fadump mode. So, restore
+ # the backed up default initrd.
+ restore_default_initrd
+
rebuild_kdump_initrd
fi
@@ -220,15 +228,25 @@ check_executable()
done
}
-backup_initrd()
+backup_default_initrd()
{
- local target_initrd_bak
+ if [ ! -e $DEFAULT_INITRD_BAK ]; then
+ echo "Backing up $DEFAULT_INITRD before rebuild."
+ cp $DEFAULT_INITRD $DEFAULT_INITRD_BAK
+ fi
+}
- # Check if backup initrd is already present.
- target_initrd_bak="$TARGET_INITRD.bak"
- if [ ! -e $target_initrd_bak ];then
- echo "Backing up $TARGET_INITRD"
- cp $TARGET_INITRD $target_initrd_bak
+restore_default_initrd()
+{
+ # If a backup initrd exists, we must be switching back from
+ # fadump to kdump. Restore the original default initrd.
+ if [ -f $DEFAULT_INITRD_BAK ];then
+ mv $DEFAULT_INITRD_BAK $DEFAULT_INITRD
+ if [[ $? -eq 0 ]]; then
+ echo -n "Restoring original initrd as fadump mode "
+ echo "is disabled."
+ sync
+ fi
fi
}
@@ -320,10 +338,12 @@ check_boot_dir()
fi
}
-setup_target_initrd()
+setup_initrd()
{
+ DEFAULT_INITRD="${KDUMP_BOOTDIR}/initramfs-`uname -r`.img"
+ DEFAULT_INITRD_BAK="${KDUMP_BOOTDIR}/.initramfs-`uname -r`.img.default"
if [ $DEFAULT_DUMP_MODE == "fadump" ]; then
- TARGET_INITRD="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}.img"
+ TARGET_INITRD="$DEFAULT_INITRD"
if [ ! -s "$TARGET_INITRD" ]; then
echo "Error: No initrd found to rebuild!"
return 1
@@ -504,7 +524,6 @@ check_rebuild()
local extra_modules
local _force_rebuild force_rebuild="0"
local ret system_modified="0"
- local initramfs_has_fadump
check_boot_dir
@@ -515,7 +534,7 @@ check_rebuild()
fi
kdump_kernel="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${kdump_kver}${KDUMP_IMG_EXT}"
- setup_target_initrd
+ setup_initrd
if [ $? -ne 0 ]; then
return 1
fi
@@ -547,15 +566,10 @@ check_rebuild()
system_modified="1"
fi
- #check if target initrd has fadump support
- if [ "$DEFAULT_DUMP_MODE" = "fadump" ] && [ -f
"$TARGET_INITRD" ]; then
- initramfs_has_fadump=`lsinitrd -m $TARGET_INITRD | grep ^kdumpbase$ | wc -l`
- fi
-
if [ $image_time -eq 0 ]; then
echo -n "No kdump initial ramdisk found."; echo
- elif [ $DEFAULT_DUMP_MODE == "fadump" ] && [
"$initramfs_has_fadump" -eq "0" ]; then
- echo "$TARGET_INITRD has no fadump support"
+ elif is_mode_switched; then
+ echo -n "Dump mode changed from last boot."; echo
elif [ "$force_rebuild" != "0" ]; then
echo -n "Force rebuild $TARGET_INITRD"; echo
elif [ "$system_modified" != "0" ]; then
@@ -714,6 +728,28 @@ propagate_ssh_key()
fi
}
+is_mode_switched()
+{
+ local _mod_included
+
+ # find if default initrd has kdumpbase module included.
+ _mod_included=`lsinitrd -m $DEFAULT_INITRD | grep ^kdumpbase$ | wc -l`
+
+ if [ "$DEFAULT_DUMP_MODE" != "fadump" ]; then
+ # If kdumpbase module is included in default initrd,
+ # we must have just switched from fadump mode.
+ if [ "$_mod_included" -eq "1" ]; then
+ return 0
+ fi
+ elif [ "$_mod_included" -eq "0" ]; then
+ # If kdumpbase module is missing in default initrd,
+ # we must have just switched from kdump mode.
+ return 0
+ fi
+
+ return 1
+}
+
is_fadump_capable()
{
# Check if firmware-assisted dump is enabled