Take a backup of original initrd when fadump is used first time or
when user has switched from kdump to fadump. This will allow us to
fall back to original initrd when kdump service fails to rebuild
the fadump ready default initrd. Also, if the user switches from
fadump to kdump, then the original initrd will be restored when
kdump script is run first time after the switch.
Signed-off-by: Mahesh Salgaonkar <mahesh(a)linux.vnet.ibm.com>
Signed-off-by: Hari Bathini <hbathini(a)linux.vnet.ibm.com>
---
kdumpctl | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 71 insertions(+), 9 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 41e4c69..f4760b5 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -15,6 +15,7 @@ FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered"
. /lib/kdump/kdump-lib.sh
standard_kexec_args="-p"
+declare -i image_time
if [ -f /etc/sysconfig/kdump ]; then
. /etc/sysconfig/kdump
@@ -70,6 +71,10 @@ function save_core()
function rebuild_initrd()
{
+ if is_fadump_capable; then
+ backup_default_initrd
+ fi
+
$MKDUMPRD $kdump_initrd $kdump_kver
if [ $? != 0 ]; then
echo "mkdumprd: failed to make kdump initrd" >&2
@@ -99,6 +104,65 @@ function check_executable()
done
}
+function backup_default_initrd()
+{
+ # Check if backup initrd is already present. If not, then
+ # this is the first time fadump is being used OR user
+ # has switched from kdump to fadump.
+ # Take a backup of the original default initrd before
+ # we rebuild default initrd for fadump support.
+ if [ ! -e $default_initrd_bak ];then
+ echo "Backing up default initrd"
+ cp $default_initrd $default_initrd_bak
+ sync
+ fi
+}
+
+function check_fadump()
+{
+ default_initrd_bak="$default_initrd.default.bak"
+ if is_fadump_capable; then
+ if [ -e $kdump_initrd ];then
+ # This means user has switched from kdump to fadump.
+ # Remove kdump initrd which is no longer needed
+ rm -f $kdump_initrd
+ fi
+ else
+ if [ -e $default_initrd_bak ];then
+ # !fadump and original initrd backup file exists.
+ # This means user has switched from fadump to kdump.
+ # Restore the original default initrd.
+ mv $default_initrd_bak $default_initrd
+ sync
+ fi
+ fi
+}
+
+function find_initrd_image_time()
+{
+ image_time=0
+
+ # Check to see if dependent files have been modified
+ # since last build of the image file
+ if [ -f $kdump_initrd ]; then
+ image_time=`stat -c "%Y" $kdump_initrd 2>/dev/null`
+ return
+ else
+ # if fadump is not used, image_time=0
+ if ! is_fadump_capable; then
+ return
+ fi
+ fi
+
+ # If this is the first time we are using fadump then let image_time
+ # be zero to force rebuild intital initrd. The non-existance of backup
+ # initrd means this is the first time fadump is being used. if exists
+ # then return the image time of default initrd.
+ if [ -e $default_initrd_bak ]; then
+ image_time=`stat -c "%Y" $default_initrd 2>/dev/null`
+ fi
+}
+
function check_config()
{
local nr
@@ -146,7 +210,9 @@ function check_rebuild()
fi
kdump_kernel="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${kdump_kver}${KDUMP_IMG_EXT}"
+ default_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}.img"
kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
+ check_fadump
_force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE 2>/dev/null`
if [ $? -eq 0 ]; then
@@ -157,17 +223,13 @@ function check_rebuild()
fi
fi
- #will rebuild every time if extra_modules are specified
+ # Will rebuild every time if extra_modules are specified
extra_modules=`grep ^extra_modules $KDUMP_CONFIG_FILE`
[ -n "$extra_modules" ] && force_rebuild="1"
- #check to see if dependent files has been modified
- #since last build of the image file
- if [ -f $kdump_initrd ]; then
- image_time=`stat -c "%Y" $kdump_initrd 2>/dev/null`
- else
- image_time=0
- fi
+ # Find initrd image time based on whether dependent files have been
+ # modified since last build of the image file
+ find_initrd_image_time
EXTRA_BINS=`grep ^kdump_post $KDUMP_CONFIG_FILE | cut -d\ -f2`
CHECK_FILES=`grep ^kdump_pre $KDUMP_CONFIG_FILE | cut -d\ -f2`
@@ -191,7 +253,7 @@ function check_rebuild()
elif [ "$force_rebuild" != "0" ]; then
echo -n "Force rebuild $kdump_initrd"; echo
elif [ -n "$modified_files" ]; then
- echo "Detected change(s) the following file(s):"
+ echo "Detected change(s) in the following file(s):"
echo -n " "; echo "$modified_files" | sed 's/\s/\n /g'
else
return 0