This patch set implements firmware-assisted dump support for kdump service. Firmware-assisted dump support depends on existing kdump infrastructure (kdump scripts) present in userland to save dump to the disk. Though existing kdump script will work seemlessly, it still needs to modified to make it aware of presense of firmware- assisted dump feature during service start and stop. These changes are tested successfully on a power box with fedora19.
Changes in v4: 1. Using a global variable DUMP_MODE to store current dump mode. 2. Updated the fadump-howto.txt doc based on review comments.
---
Hari Bathini (8): kdump: Modify status routine to check for firmware-assisted dump kdump: Modify kdump script to start the firmware assisted dump. kdump: Modify kdump script to stop firmware assisted dump kdump: Take a backup of original default initrd before rebuilding. kdump: Rebuild default initrd for firmware assisted dump kdump: Get rid of "function" keyword from all functions kdump: Check for /proc/vmcore existence before capturing the vmcore. kdump: Add firmware-assisted dump howto document
dracut-kdump.sh | 3 + fadump-howto.txt | 250 +++++++++++++++++++++++++++++++++++++++++++ kdumpctl | 312 ++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 516 insertions(+), 49 deletions(-) create mode 100644 fadump-howto.txt
This patch enables kdump script to check if firmware-assisted dump is enabled or not by reading value from '/sys/kernel/fadump_enabled'. The determine_dump_mode() routine sets dump_mode to 'fadump', if fadump is enabled. By default, dump_mode is set to 'kdump' mode.
Modify status routine to check if firmware assisted dump is registered or not by reading value from '/sys/kernel/fadump_registered' file. If it is set to '1' then return status=0 else return status=1.
0 <= Firmware assisted is enabled and running 1 <= Firmware assisted is enabled but not running
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com --- kdumpctl | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/kdumpctl b/kdumpctl index 9cae0c4..fc93ede 100755 --- a/kdumpctl +++ b/kdumpctl @@ -9,6 +9,9 @@ MKDUMPRD="/sbin/mkdumprd -f" SAVE_PATH=/var/crash SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" DUMP_TARGET="" +FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" +FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" +DUMP_MODE="kdump" # kdump shall be the default dump mode
. /lib/kdump/kdump-lib.sh
@@ -24,6 +27,16 @@ single_instance_lock() flock 9 }
+determine_dump_mode() +{ + # Check if firmware-assisted dump is enabled + # if yes, set the dump mode as fadump + if is_fadump_capable; then + echo "Using dump mode fadump" + DUMP_MODE="fadump" + fi +} + # remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>] # Remove a list of kernel parameters from a given kernel cmdline and print the result. # For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists. @@ -427,6 +440,25 @@ function propagate_ssh_key() }
+is_fadump_capable() +{ + # Check if firmware-assisted dump is enabled + # if no, fallback to kdump check + if [ -f $FADUMP_ENABLED_SYS_NODE ]; then + rc=`cat $FADUMP_ENABLED_SYS_NODE` + [ $rc -eq 1 ] && return 0 + fi + return 1 +} + +check_current_fadump_status() +{ + # Check if firmware-assisted dump has been registered. + rc=`cat $FADUMP_REGISTER_SYS_NODE` + [ $rc -eq 1 ] && return 0 + return 1 +} + function check_current_kdump_status() { rc=`cat /sys/kernel/kexec_crash_loaded` @@ -437,6 +469,17 @@ function check_current_kdump_status() fi }
+check_current_status() +{ + if [ $DUMP_MODE == "fadump" ]; then + check_current_fadump_status + else + check_current_kdump_status + fi + + return $? +} + function save_raw() { local kdump_dir @@ -596,6 +639,16 @@ function check_fence_kdump_config() return 0 }
+check_dump_feasibility() +{ + if [ $DUMP_MODE != "kdump" ]; then + return 0 + fi + + check_kdump_feasibility + return $? +} + function start() { check_config @@ -613,13 +666,13 @@ function start() return 1 fi
- check_kdump_feasibility + check_dump_feasibility if [ $? -ne 0 ]; then echo "Starting kdump: [FAILED]" return 1 fi
- check_current_kdump_status + check_current_status if [ $? == 0 ]; then echo "Kdump already running: [WARNING]" return 0 @@ -667,6 +720,9 @@ fi
main () { + # Determine if the dump mode is kdump or fadump + determine_dump_mode + case "$1" in start) if [ -s /proc/vmcore ]; then @@ -681,7 +737,7 @@ main () ;; status) EXIT_CODE=0 - check_current_kdump_status + check_current_status case "$?" in 0) echo "Kdump is operational"
During service kdump start, if firmware assisted dump is not enabled then fallback to starting of existing kexec based kdump. If firmware assisted is enabled but not running, then start firmware assisted dump by echo'ing 1 to '/sys/kernel/fadump_registered' file.
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com --- kdumpctl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/kdumpctl b/kdumpctl index fc93ede..ae17c3b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -649,6 +649,29 @@ check_dump_feasibility() return $? }
+start_fadump() +{ + echo 1 > $FADUMP_REGISTER_SYS_NODE + if ! check_current_fadump_status; then + echo "fadump: failed to register" + return 1 + fi + + echo "fadump: registered successfully" + return 0 +} + +start_dump() +{ + if [ $DUMP_MODE == "fadump" ]; then + start_fadump + else + load_kdump + fi + + return $? +} + function start() { check_config @@ -690,7 +713,8 @@ function start() echo "Starting kdump: [FAILED]" return 1 fi - load_kdump + + start_dump if [ $? != 0 ]; then echo "Starting kdump: [FAILED]" return 1
During service kdump stop, if firmware assisted dump is enabled and running, then stop firmware assisted dump by echo'ing 0 to '/sys/kernel/fadump_registered' file.
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com --- kdumpctl | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-)
diff --git a/kdumpctl b/kdumpctl index ae17c3b..efd77ce 100755 --- a/kdumpctl +++ b/kdumpctl @@ -723,18 +723,45 @@ function start() echo "Starting kdump: [OK]" }
-function stop() +stop_fadump() +{ + check_current_fadump_status && echo 0 > $FADUMP_REGISTER_SYS_NODE + if check_current_fadump_status; then + echo "fadump: failed to un-register" + return 1 + fi + + echo "fadump: un-registered successfully" + return 0 +} + +stop_kdump() { $KEXEC -p -u 2>/dev/null - if [ $? == 0 ]; then - echo "kexec: unloaded kdump kernel" - echo "Stopping kdump: [OK]" - return 0 - else + if [ $? != 0 ]; then echo "kexec: failed to unloaded kdump kernel" + return 1 + fi + + echo "kexec: unloaded kdump kernel" + return 0 +} + +function stop() +{ + if [ $DUMP_MODE == "fadump" ]; then + stop_fadump + else + stop_kdump + fi + + if [ $? != 0 ]; then echo "Stopping kdump: [FAILED]" return 1 fi + + echo "Stopping kdump: [OK]" + return 0 }
if [ ! -f "$KDUMP_CONFIG_FILE" ]; then
On Tue, Apr 29, 2014 at 07:27:49PM +0530, Hari Bathini wrote:
During service kdump stop, if firmware assisted dump is enabled and running, then stop firmware assisted dump by echo'ing 0 to '/sys/kernel/fadump_registered' file.
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com
kdumpctl | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-)
diff --git a/kdumpctl b/kdumpctl index ae17c3b..efd77ce 100755 --- a/kdumpctl +++ b/kdumpctl @@ -723,18 +723,45 @@ function start() echo "Starting kdump: [OK]" }
-function stop() +stop_fadump() +{
- check_current_fadump_status && echo 0 > $FADUMP_REGISTER_SYS_NODE
Do we have to check current status of fadump. Can't we unditionally write 0 to $FADUMP_REGISTER_SYS_NODE?
- if check_current_fadump_status; then
echo "fadump: failed to un-register"
return 1
- fi
- echo "fadump: un-registered successfully"
- return 0
+}
+stop_kdump() { $KEXEC -p -u 2>/dev/null
- if [ $? == 0 ]; then
echo "kexec: unloaded kdump kernel"
echo "Stopping kdump: [OK]"
return 0
- else
- if [ $? != 0 ]; then echo "kexec: failed to unloaded kdump kernel"
^^^^^ Typo in original code. Should be "unload" instead of "unloaded". Would you mind sending a one line fix for this separately.
Thanks Vivek
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@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com --- kdumpctl | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 17 deletions(-)
diff --git a/kdumpctl b/kdumpctl index efd77ce..5170487 100755 --- a/kdumpctl +++ b/kdumpctl @@ -16,6 +16,7 @@ DUMP_MODE="kdump" # kdump shall be the default dump mode . /lib/kdump/kdump-lib.sh
standard_kexec_args="-p" +declare -i image_time
if [ -f /etc/sysconfig/kdump ]; then . /etc/sysconfig/kdump @@ -29,12 +30,25 @@ single_instance_lock()
determine_dump_mode() { + if [ -z "$KDUMP_KERNELVER" ]; then + kdump_kver=`uname -r` + else + kdump_kver=$KDUMP_KERNELVER + fi + + default_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}.img" + kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img" + default_initrd_bak="$default_initrd.default.bak" + # Check if firmware-assisted dump is enabled # if yes, set the dump mode as fadump if is_fadump_capable; then echo "Using dump mode fadump" DUMP_MODE="fadump" fi + + # Handle dump mode switch from kdump to fadump OR fadump to kdump + handle_dump_mode_switch }
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>] @@ -134,6 +148,10 @@ function save_core()
function rebuild_initrd() { + if [ $DUMP_MODE == "fadump" ]; then + backup_default_initrd + fi + $MKDUMPRD $kdump_initrd $kdump_kver if [ $? != 0 ]; then echo "mkdumprd: failed to make kdump initrd" >&2 @@ -163,6 +181,61 @@ function check_executable() done }
+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 +} + +handle_dump_mode_switch() +{ + if [ $DUMP_MODE == "fadump" ]; 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 +} + +find_initrd_image_time() +{ + image_time=0 + + # Check to see if dependent files have been modified + # since last build of the image file + if [ $DUMP_MODE == "fadump" ]; then + # If this is the 1st time we are using fadump then let image_time be + # zero to force rebuild initrd. The non-existance of backup initrd + # means this is the 1st time fadump is being used. If it 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 + else + if [ -f $kdump_initrd ]; then + image_time=`stat -c "%Y" $kdump_initrd 2>/dev/null` + return + fi + fi +} + function check_config() { local nr @@ -234,14 +307,7 @@ function check_rebuild() local extra_modules modified_files="" local _force_rebuild force_rebuild="0"
- if [ -z "$KDUMP_KERNELVER" ]; then - kdump_kver=`uname -r` - else - kdump_kver=$KDUMP_KERNELVER - fi - kdump_kernel="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${kdump_kver}${KDUMP_IMG_EXT}" - kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
_force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE 2>/dev/null` if [ $? -eq 0 ]; then @@ -256,13 +322,9 @@ function check_rebuild() 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
#also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. modified_files=$(get_pcs_cluster_modified_files $image_time) @@ -285,11 +347,17 @@ function check_rebuild() done
if [ $image_time -eq 0 ]; then - echo -n "No kdump initial ramdisk found."; echo + if [ $DUMP_MODE == "kdump" ]; then + echo -n "No kdump initial ramdisk found."; echo + fi elif [ "$force_rebuild" != "0" ]; then - echo -n "Force rebuild $kdump_initrd"; echo + if [ $DUMP_MODE == "kdump" ]; then + echo -n "Force rebuild $kdump_initrd"; echo + else + echo -n "Force rebuild $default_initrd with fadump support"; echo + fi 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
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
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.
Thinking more about it. Why should kdump worry about keeping an initrd backup and restoring that later.
I feel this should be left to user if he needs to do so.
Kdump should just build initrd separately and upon successful build replace the original with this one.
I think it is similar to admin invoking "dracut" to rebuild initrd. dracut does not create a backup of original initrd.
I don't think kdump should be tasked with keeping a backup of original initrd and restore it. That does not sound right to me. That's not kdump's job.
Thanks Vivek
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com
kdumpctl | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 17 deletions(-)
diff --git a/kdumpctl b/kdumpctl index efd77ce..5170487 100755 --- a/kdumpctl +++ b/kdumpctl @@ -16,6 +16,7 @@ DUMP_MODE="kdump" # kdump shall be the default dump mode . /lib/kdump/kdump-lib.sh
standard_kexec_args="-p" +declare -i image_time
if [ -f /etc/sysconfig/kdump ]; then . /etc/sysconfig/kdump @@ -29,12 +30,25 @@ single_instance_lock()
determine_dump_mode() {
- if [ -z "$KDUMP_KERNELVER" ]; then
kdump_kver=`uname -r`
- else
kdump_kver=$KDUMP_KERNELVER
- fi
- default_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}.img"
- kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
- default_initrd_bak="$default_initrd.default.bak"
- # Check if firmware-assisted dump is enabled # if yes, set the dump mode as fadump if is_fadump_capable; then echo "Using dump mode fadump" DUMP_MODE="fadump" fi
- # Handle dump mode switch from kdump to fadump OR fadump to kdump
- handle_dump_mode_switch
}
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>] @@ -134,6 +148,10 @@ function save_core()
function rebuild_initrd() {
- if [ $DUMP_MODE == "fadump" ]; then
backup_default_initrd
- fi
- $MKDUMPRD $kdump_initrd $kdump_kver if [ $? != 0 ]; then echo "mkdumprd: failed to make kdump initrd" >&2
@@ -163,6 +181,61 @@ function check_executable() done }
+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
+}
+handle_dump_mode_switch() +{
- if [ $DUMP_MODE == "fadump" ]; 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
+}
+find_initrd_image_time() +{
- image_time=0
- # Check to see if dependent files have been modified
- # since last build of the image file
- if [ $DUMP_MODE == "fadump" ]; then
# If this is the 1st time we are using fadump then let image_time be
# zero to force rebuild initrd. The non-existance of backup initrd
# means this is the 1st time fadump is being used. If it 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
- else
if [ -f $kdump_initrd ]; then
image_time=`stat -c "%Y" $kdump_initrd 2>/dev/null`
return
fi
- fi
+}
function check_config() { local nr @@ -234,14 +307,7 @@ function check_rebuild() local extra_modules modified_files="" local _force_rebuild force_rebuild="0"
if [ -z "$KDUMP_KERNELVER" ]; then
kdump_kver=`uname -r`
else
kdump_kver=$KDUMP_KERNELVER
fi
kdump_kernel="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${kdump_kver}${KDUMP_IMG_EXT}"
kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
_force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE 2>/dev/null` if [ $? -eq 0 ]; then
@@ -256,13 +322,9 @@ function check_rebuild() 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
#also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. modified_files=$(get_pcs_cluster_modified_files $image_time)
@@ -285,11 +347,17 @@ function check_rebuild() done
if [ $image_time -eq 0 ]; then
echo -n "No kdump initial ramdisk found."; echo
if [ $DUMP_MODE == "kdump" ]; then
echo -n "No kdump initial ramdisk found."; echo
elif [ "$force_rebuild" != "0" ]; thenfi
echo -n "Force rebuild $kdump_initrd"; echo
if [ $DUMP_MODE == "kdump" ]; then
echo -n "Force rebuild $kdump_initrd"; echo
else
echo -n "Force rebuild $default_initrd with fadump support"; echo
elif [ -n "$modified_files" ]; thenfi
echo "Detected change(s) the following file(s):"
echo -n " "; echo "$modified_files" | sed 's/\s/\n /g' else return 0echo "Detected change(s) in the following file(s):"
kexec mailing list kexec@lists.fedoraproject.org https://lists.fedoraproject.org/mailman/listinfo/kexec
On 05/06/2014 02:53 AM, Vivek Goyal wrote:
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
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.
Thinking more about it. Why should kdump worry about keeping an initrd backup and restoring that later.
I feel this should be left to user if he needs to do so.
Kdump should just build initrd separately and upon successful build replace the original with this one.
I think it is similar to admin invoking "dracut" to rebuild initrd. dracut does not create a backup of original initrd.
I don't think kdump should be tasked with keeping a backup of original initrd and restore it. That does not sound right to me. That's not kdump's job.
Thanks Vivek
Vivek, in fadump case, as default initrd is the initrd image for fadump as well, it becomes a bit tricky on when to rebuild the initrd image with fadump support as the default initrd image could already be built with fadump support in most cases. Having a backup image solves this problem. Also, it helps in cases where default initrd is manually created by user for specific needs as while switching back from fadump to kdump, creating a new default initrd image instead of restoring the original initrd image may be undesirable. Please share your opinion on this.
Thanks Hari
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com
kdumpctl | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 17 deletions(-)
diff --git a/kdumpctl b/kdumpctl index efd77ce..5170487 100755 --- a/kdumpctl +++ b/kdumpctl @@ -16,6 +16,7 @@ DUMP_MODE="kdump" # kdump shall be the default dump mode . /lib/kdump/kdump-lib.sh
standard_kexec_args="-p" +declare -i image_time
if [ -f /etc/sysconfig/kdump ]; then . /etc/sysconfig/kdump @@ -29,12 +30,25 @@ single_instance_lock()
determine_dump_mode() {
if [ -z "$KDUMP_KERNELVER" ]; then
kdump_kver=`uname -r`
else
kdump_kver=$KDUMP_KERNELVER
fi
default_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}.img"
kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
default_initrd_bak="$default_initrd.default.bak"
# Check if firmware-assisted dump is enabled # if yes, set the dump mode as fadump if is_fadump_capable; then echo "Using dump mode fadump" DUMP_MODE="fadump" fi
# Handle dump mode switch from kdump to fadump OR fadump to kdump
handle_dump_mode_switch }
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>]
@@ -134,6 +148,10 @@ function save_core()
function rebuild_initrd() {
- if [ $DUMP_MODE == "fadump" ]; then
backup_default_initrd
- fi
- $MKDUMPRD $kdump_initrd $kdump_kver if [ $? != 0 ]; then echo "mkdumprd: failed to make kdump initrd" >&2
@@ -163,6 +181,61 @@ function check_executable() done }
+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
+}
+handle_dump_mode_switch() +{
- if [ $DUMP_MODE == "fadump" ]; 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
+}
+find_initrd_image_time() +{
- image_time=0
- # Check to see if dependent files have been modified
- # since last build of the image file
- if [ $DUMP_MODE == "fadump" ]; then
# If this is the 1st time we are using fadump then let image_time be
# zero to force rebuild initrd. The non-existance of backup initrd
# means this is the 1st time fadump is being used. If it 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
- else
if [ -f $kdump_initrd ]; then
image_time=`stat -c "%Y" $kdump_initrd 2>/dev/null`
return
fi
- fi
+}
- function check_config() { local nr
@@ -234,14 +307,7 @@ function check_rebuild() local extra_modules modified_files="" local _force_rebuild force_rebuild="0"
if [ -z "$KDUMP_KERNELVER" ]; then
kdump_kver=`uname -r`
else
kdump_kver=$KDUMP_KERNELVER
fi
kdump_kernel="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${kdump_kver}${KDUMP_IMG_EXT}"
kdump_initrd="${KDUMP_BOOTDIR}/initramfs-${kdump_kver}kdump.img"
_force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE 2>/dev/null` if [ $? -eq 0 ]; then
@@ -256,13 +322,9 @@ function check_rebuild() 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
#also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. modified_files=$(get_pcs_cluster_modified_files $image_time)
@@ -285,11 +347,17 @@ function check_rebuild() done
if [ $image_time -eq 0 ]; then
echo -n "No kdump initial ramdisk found."; echo
if [ $DUMP_MODE == "kdump" ]; then
echo -n "No kdump initial ramdisk found."; echo
elif [ "$force_rebuild" != "0" ]; thenfi
echo -n "Force rebuild $kdump_initrd"; echo
if [ $DUMP_MODE == "kdump" ]; then
echo -n "Force rebuild $kdump_initrd"; echo
else
echo -n "Force rebuild $default_initrd with fadump support"; echo
elif [ -n "$modified_files" ]; thenfi
echo "Detected change(s) the following file(s):"
echo -n " "; echo "$modified_files" | sed 's/\s/\n /g' else return 0echo "Detected change(s) in the following file(s):"
kexec mailing list kexec@lists.fedoraproject.org https://lists.fedoraproject.org/mailman/listinfo/kexec
On Thu, May 08, 2014 at 02:45:18PM +0530, Hari Bathini wrote:
On 05/06/2014 02:53 AM, Vivek Goyal wrote:
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
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.
Thinking more about it. Why should kdump worry about keeping an initrd backup and restoring that later.
I feel this should be left to user if he needs to do so.
Kdump should just build initrd separately and upon successful build replace the original with this one.
I think it is similar to admin invoking "dracut" to rebuild initrd. dracut does not create a backup of original initrd.
I don't think kdump should be tasked with keeping a backup of original initrd and restore it. That does not sound right to me. That's not kdump's job.
Thanks Vivek
Vivek, in fadump case, as default initrd is the initrd image for fadump as well, it becomes a bit tricky on when to rebuild the initrd image with fadump support as the default initrd image could already be built with fadump support in most cases.
That's the issue with fadump from day 1. I am not very comfortable with the idea of regneration of *boot* initrd. Given the fact that you are trying to take a backup and restore it, you are not comfortable either and hence trying to create some sort of fall back mechanism.
Anyway, in this specific case I did not understand two things.
- What's wrong with regeneration of initrd even if fadump is already built in. We do this all the time with kdump initrd?
- And if you have been successful in generating initrd once with fadump module and it works, there is no reason that rebuilding it that way will not work.
So I am not sure what's the concern here.
Having a backup image solves this problem.
Also, it helps in cases where default initrd is manually created by user for specific needs as while switching back from fadump to kdump,
If user has created an initrd manually, the need to create a backup of it.
You know what, we probably can do something like "make install". It seems to save old kernel and initrd with suffix .old. I think that kind of functionality still might be somewhat resonable. As one can argue that it is not obvious that kdump service will overwrite intrd.
But I am not conviced about restoring initrd part. That needs to be done manually if need be by user. Anyway, restoring initrd should not be required if kdump service stops. There will not be any /proc/vmcore even if kernel crashes and fadump module will not do anything.
creating a new default initrd image instead of restoring the original initrd image may be undesirable.
You indeed are creating a new default initramfs. That can always make your current system unbootable. If you think that this is undesirable then we should not be doing fadump feature this way. I had warned about this long back.
It was you who had confidence that you can reliably rebuild initrd. And if that's the case, why are you trying to introduce a backup and restore mechanism?
Also what if user builds a custom initrd and that's overwritten by kdump when service stops (as it restored the original initrd).
Please share your opinion on this.
I think we can just save the old initrd with some suffix. But I really don't like the idea of restoring from backup when kdump service stops.
Thanks Vivek
On 05/13/2014 02:09 AM, Vivek Goyal wrote:
On Thu, May 08, 2014 at 02:45:18PM +0530, Hari Bathini wrote:
On 05/06/2014 02:53 AM, Vivek Goyal wrote:
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
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.
Thinking more about it. Why should kdump worry about keeping an initrd backup and restoring that later.
I feel this should be left to user if he needs to do so.
Kdump should just build initrd separately and upon successful build replace the original with this one.
I think it is similar to admin invoking "dracut" to rebuild initrd. dracut does not create a backup of original initrd.
I don't think kdump should be tasked with keeping a backup of original initrd and restore it. That does not sound right to me. That's not kdump's job.
Thanks Vivek
Vivek, in fadump case, as default initrd is the initrd image for fadump as well, it becomes a bit tricky on when to rebuild the initrd image with fadump support as the default initrd image could already be built with fadump support in most cases.
That's the issue with fadump from day 1. I am not very comfortable with the idea of regneration of *boot* initrd. Given the fact that you are trying to take a backup and restore it, you are not comfortable either and hence trying to create some sort of fall back mechanism.
Anyway, in this specific case I did not understand two things.
- What's wrong with regeneration of initrd even if fadump is already built in. We do this all the time with kdump initrd?
In kdump case, when kdump initrd is missing, we create it. But in case of fadump, default initrd is always there. So we should either rebuild initrd with fadump support all the time or have a check mechanism to minimize the number of times we rebuild. I prefer the latter for the frequency of rebuilds without a check mechanism will be much higher although rebuilding multiple times doesn't have much of a functional impact. A simple check mechanism could be to have a "/boot/.fadump" file; if the file is present, we don't bother rebuilding, else we rebuild initrd with fadump support.
- And if you have been successful in generating initrd once with fadump module and it works, there is no reason that rebuilding it that way will not work.
So I am not sure what's the concern here.
Having a backup image solves this problem. Also, it helps in cases where default initrd is manually created by user for specific needs as while switching back from fadump to kdump,
If user has created an initrd manually, the need to create a backup of it.
You know what, we probably can do something like "make install". It seems to save old kernel and initrd with suffix .old. I think that kind of functionality still might be somewhat resonable. As one can argue that it is not obvious that kdump service will overwrite intrd.
But I am not conviced about restoring initrd part. That needs to be done manually if need be by user. Anyway, restoring initrd should not be required if kdump service stops. There will not be any /proc/vmcore even if kernel crashes and fadump module will not do anything.
True. There is no need in restoring initrd when kdump service stops.
creating a new default initrd image instead of restoring the original initrd image may be undesirable.
You indeed are creating a new default initramfs. That can always make your current system unbootable. If you think that this is undesirable then we should not be doing fadump feature this way. I had warned about this long back.
It was you who had confidence that you can reliably rebuild initrd. And if that's the case, why are you trying to introduce a backup and restore mechanism?
We are indeed confident about rebuilding initrd with fadump support. Intention in restoring was only to remove fadump support from initrd when it is unnecessary. Since that doesn't sound like kexec-tools job, will drop the idea of restoring when service stops. Will have the backup though, for user's reference. Please share your views. I will work on these changes and post the revised patches soon.
Thanks Hari
Also what if user builds a custom initrd and that's overwritten by kdump when service stops (as it restored the original initrd).
Please share your opinion on this.
I think we can just save the old initrd with some suffix. But I really don't like the idea of restoring from backup when kdump service stops. Thanks Vivek
PS: Sorry about the delayed response. I was on vacation all these days.
On Fri, May 30, 2014 at 11:40:02PM +0530, Hari Bathini wrote:
[..]
- What's wrong with regeneration of initrd even if fadump is already built in. We do this all the time with kdump initrd?
In kdump case, when kdump initrd is missing, we create it. But in case of fadump, default initrd is always there. So we should either rebuild initrd with fadump support all the time or have a check mechanism to minimize the number of times we rebuild. I prefer the latter for the frequency of rebuilds without a check mechanism will be much higher although rebuilding multiple times doesn't have much of a functional impact. A simple check mechanism could be to have a "/boot/.fadump" file; if the file is present, we don't bother rebuilding, else we rebuild initrd with fadump support.
How about using "lsinitrd" and check whether relevant files are present or not. We could check for module "kdumpbase" is present or not? We could also create a new option to lsinitrd so that it lists only modules and nothing else.
- And if you have been successful in generating initrd once with fadump module and it works, there is no reason that rebuilding it that way will not work.
So I am not sure what's the concern here.
Having a backup image solves this problem. Also, it helps in cases where default initrd is manually created by user for specific needs as while switching back from fadump to kdump,
If user has created an initrd manually, the need to create a backup of it.
You know what, we probably can do something like "make install". It seems to save old kernel and initrd with suffix .old. I think that kind of functionality still might be somewhat resonable. As one can argue that it is not obvious that kdump service will overwrite intrd.
But I am not conviced about restoring initrd part. That needs to be done manually if need be by user. Anyway, restoring initrd should not be required if kdump service stops. There will not be any /proc/vmcore even if kernel crashes and fadump module will not do anything.
True. There is no need in restoring initrd when kdump service stops.
creating a new default initrd image instead of restoring the original initrd image may be undesirable.
You indeed are creating a new default initramfs. That can always make your current system unbootable. If you think that this is undesirable then we should not be doing fadump feature this way. I had warned about this long back.
It was you who had confidence that you can reliably rebuild initrd. And if that's the case, why are you trying to introduce a backup and restore mechanism?
We are indeed confident about rebuilding initrd with fadump support. Intention in restoring was only to remove fadump support from initrd when it is unnecessary. Since that doesn't sound like kexec-tools job, will drop the idea of restoring when service stops. Will have the backup though, for user's reference. Please share your views. I will work on these changes and post the revised patches soon.
I think I am fine with saving backup of existing initramfs. I have the main problem with restoration part. You never know who has mucked with stored backup in the mean time.
Thanks Vivek
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
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.
You should build an initrd into a separate temporary file and then replace the original initrd to take care of this issue.
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.
If user switches modes, that should trigger generataion of fresh initrd instead of trying to restore from some backup.
Thanks Vivek
On 05/06/2014 02:55 AM, Vivek Goyal wrote:
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
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.
You should build an initrd into a separate temporary file and then replace the original initrd to take care of this issue.
Identifying that fadump is being used for the first time maybe a challenge. This makes it tricky on when to rebuild default initrd image with fadump support. Any suggestions on this would be of great help.
Thanks Hari
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.
If user switches modes, that should trigger generataion of fresh initrd instead of trying to restore from some backup.
Thanks Vivek
On Thu, May 08, 2014 at 02:54:03PM +0530, Hari Bathini wrote:
On 05/06/2014 02:55 AM, Vivek Goyal wrote:
On Tue, Apr 29, 2014 at 07:27:55PM +0530, Hari Bathini wrote:
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.
You should build an initrd into a separate temporary file and then replace the original initrd to take care of this issue.
Identifying that fadump is being used for the first time maybe a challenge. This makes it tricky on when to rebuild default initrd image with fadump support. Any suggestions on this would be of great help.
Why do we need to identify that fadump is being enabled first time. If you can rebuild initrd right first time, then you can rebuild it right second time too.
Thanks Vivek
The current kdump infrastructure builds a separate initrd which then gets loaded into memory by kexec-tools for use by kdump kernel. But firmware assisted dump (FADUMP) does not use kexec-based approach. After crash, firmware reboots the partition and loads grub loader like the normal booting process does. Hence in the FADUMP approach, the second kernel (after crash) will always use the default initrd (OS built). So, to support FADUMP, change is required, as in to add dump capturing steps, in default initrd.
The current kdumpctl script implementation already has the code to build initrd using mkdumprd. This patch uses the new '--rebuild' option introduced, in dracut, to incrementally build the initramfs image. A backup of default initrd image is taken before rebuilding default initrd image with fadump support. If this operation fails, default initrd image is restored.
Kexec-tools package in rhel7 is now enhanced to insert a out-of-tree kdump module for dracut, which is responsible for adding vmcore capture steps into initrd, if dracut is invoked with "IN_KDUMP" environment variable set to 1. mkdumprd script exports "IN_KDUMP=1" environment variable before invoking dracut to build kdump initrd. This patch relies on this current mechanism of kdump init script.
Dracut patch that introduces '--rebuild' option is accepted upstream (commit id: 659dc319d950999f8d191a81fdc4d3114e9213de).
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com --- kdumpctl | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-)
diff --git a/kdumpctl b/kdumpctl index 5170487..02b32bc 100755 --- a/kdumpctl +++ b/kdumpctl @@ -146,17 +146,46 @@ function save_core() fi }
-function rebuild_initrd() +rebuild_fadump_initrd() { - if [ $DUMP_MODE == "fadump" ]; then - backup_default_initrd + if [ ! -s "$default_initrd" ]; then + echo "No default initrd found to rebuild for fadump support!" + return 1 fi + backup_default_initrd + + echo "Rebuilding $default_initrd with fadump support" + $MKDUMPRD --rebuild $default_initrd --kver $kdump_kver + if [ $? != 0 ]; then + echo "mkdumprd: failed to make initrd with fadump support" >&2 + restore_default_initrd + return 1 + fi + + return 0 +}
+rebuild_kdump_initrd() +{ + echo "Rebuilding $kdump_initrd" $MKDUMPRD $kdump_initrd $kdump_kver if [ $? != 0 ]; then echo "mkdumprd: failed to make kdump initrd" >&2 return 1 fi + + return 0 +} + +rebuild_initrd() +{ + if [ $DUMP_MODE == "fadump" ]; then + rebuild_fadump_initrd + else + rebuild_kdump_initrd + fi + + return $? }
#$1: the files to be checked with IFS=' ' @@ -214,6 +243,17 @@ handle_dump_mode_switch() fi }
+restore_default_initrd() +{ + # We have failed to rebuild initrd for fadump support. + # Restore the original default initrd. + if [ -f $default_initrd_bak ];then + echo "Restored default initrd" + mv $default_initrd_bak $default_initrd + sync + fi +} + find_initrd_image_time() { image_time=0 @@ -363,7 +403,6 @@ function check_rebuild() return 0 fi
- echo "Rebuilding $kdump_initrd" rebuild_initrd return $? }
This cleanup patch removes unnecessary keyword "function" at all places in kdumpctl script.
Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com --- kdumpctl | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/kdumpctl b/kdumpctl index 02b32bc..79a11c5 100755 --- a/kdumpctl +++ b/kdumpctl @@ -54,7 +54,7 @@ determine_dump_mode() # remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>] # Remove a list of kernel parameters from a given kernel cmdline and print the result. # For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists. -function remove_cmdline_param() +remove_cmdline_param() { local cmdline=$1 shift @@ -72,7 +72,7 @@ function remove_cmdline_param() # This function returns the "initial apicid" of the # boot cpu (cpu 0) if present. # -function get_bootcpu_initial_apicid() +get_bootcpu_initial_apicid() { awk ' \ BEGIN { CPU = "-1"; } \ @@ -85,7 +85,7 @@ function get_bootcpu_initial_apicid() # # This function appends argument "$2=$3" to string ($1) if not already present. # -function append_cmdline() +append_cmdline() { local cmdline=$1 local newstr=${cmdline/$2/""} @@ -99,7 +99,7 @@ function append_cmdline() }
# This function performs a series of edits on the command line -function prepare_cmdline() +prepare_cmdline() { local cmdline; if [ -z "$KDUMP_COMMANDLINE" ]; then @@ -121,7 +121,7 @@ function prepare_cmdline() }
-function save_core() +save_core() { coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
@@ -189,7 +189,7 @@ rebuild_initrd() }
#$1: the files to be checked with IFS=' ' -function check_exist() +check_exist() { for file in $1; do if [ ! -f "$file" ]; then @@ -200,7 +200,7 @@ function check_exist() }
#$1: the files to be checked with IFS=' ' -function check_executable() +check_executable() { for file in $1; do if [ ! -x "$file" ]; then @@ -276,7 +276,7 @@ find_initrd_image_time() fi }
-function check_config() +check_config() { local nr
@@ -342,7 +342,7 @@ get_pcs_cluster_modified_files() echo $modified_files }
-function check_rebuild() +check_rebuild() { local extra_modules modified_files="" local _force_rebuild force_rebuild="0" @@ -409,7 +409,7 @@ function check_rebuild()
# This function check iomem and determines if we have more than # 4GB of ram available. Returns 1 if we do, 0 if we dont -function need_64bit_headers() +need_64bit_headers() { return `tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); \ print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'` @@ -418,7 +418,7 @@ function need_64bit_headers() # Load the kdump kerel specified in /etc/sysconfig/kdump # If none is specified, try to load a kdump kernel with the same version # as the currently running kernel. -function load_kdump() +load_kdump() { MEM_RESERVED=$(cat /sys/kernel/kexec_crash_size) if [ $MEM_RESERVED -eq 0 ] @@ -465,7 +465,7 @@ function load_kdump() fi }
-function check_ssh_config() +check_ssh_config() { while read config_opt config_val; do # remove inline comments after the end of a directive. @@ -498,7 +498,7 @@ function check_ssh_config() return 0 }
-function check_ssh_target() +check_ssh_target() { local _ret ssh -q -i $SSH_KEY_LOCATION -o BatchMode=yes $DUMP_TARGET mkdir -p $SAVE_PATH @@ -510,7 +510,7 @@ function check_ssh_target() return 0 }
-function propagate_ssh_key() +propagate_ssh_key() { check_ssh_config if [ $? -ne 0 ]; then @@ -566,7 +566,7 @@ check_current_fadump_status() return 1 }
-function check_current_kdump_status() +check_current_kdump_status() { rc=`cat /sys/kernel/kexec_crash_loaded` if [ $rc == 1 ]; then @@ -587,7 +587,7 @@ check_current_status() return $? }
-function save_raw() +save_raw() { local kdump_dir local raw_target @@ -698,7 +698,7 @@ selinux_relabel() # is 1 and SetupMode is 0, then secure boot is being enforced. # # Assume efivars is mounted at /sys/firmware/efi/efivars. -function is_secure_boot_enforced() +is_secure_boot_enforced() { local secure_boot_file setup_mode_file local secure_boot_byte setup_mode_byte @@ -718,7 +718,7 @@ function is_secure_boot_enforced() return 1 }
-function check_kdump_feasibility() +check_kdump_feasibility() { if is_secure_boot_enforced; then echo "Secure Boot is Enabled. Kdump service can't be started. Disable Secure Boot and retry" @@ -731,7 +731,7 @@ function check_kdump_feasibility() fi }
-function check_fence_kdump_config() +check_fence_kdump_config() { local hostname=`hostname` local nodes=$(get_option_value "fence_kdump_nodes") @@ -779,7 +779,7 @@ start_dump() return $? }
-function start() +start() { check_config if [ $? -ne 0 ]; then @@ -854,7 +854,7 @@ stop_kdump() return 0 }
-function stop() +stop() { if [ $DUMP_MODE == "fadump" ]; then stop_fadump
The script dracut-kdump.sh is responsible for capturing vmcore during second kernel boot. Currently this script gets installed into kdump initrd as part of kdumpbase dracut module. Since it's always installed into kdump initrd, this script assumes that '/proc/vmcore' will always be present when it is invoked.
With fadump support, 'dracut-kdump.sh' script also gets installed into default initrd to capture vmcore generated by firmware assisted dump. Thus in fadump case, the same initrd is going to be used for normal boot as well as boot after system crash. Hence a check is required to see if '/proc/vmcore' file exists before executing steps to capture vmcore. This check will help to bypass the vmcore capture steps during normal boot process.
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com --- dracut-kdump.sh | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/dracut-kdump.sh b/dracut-kdump.sh index cb13d92..55ac8bc 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -1,5 +1,8 @@ #!/bin/sh
+# continue only if /proc/vmcore is present. +[ ! -f /proc/vmcore ] && return + exec &> /dev/console . /lib/dracut-lib.sh . /lib/kdump-lib.sh
This patch adds fadump howto document to kexec-tools. The document is prepared in reference to kexec-kdump-howto.txt document.
Signed-off-by: Mahesh Salgaonkar mahesh@linux.vnet.ibm.com Signed-off-by: Hari Bathini hbathini@linux.vnet.ibm.com --- fadump-howto.txt | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 fadump-howto.txt
diff --git a/fadump-howto.txt b/fadump-howto.txt new file mode 100644 index 0000000..16f8549 --- /dev/null +++ b/fadump-howto.txt @@ -0,0 +1,250 @@ +Firmware assisted dump (fadump) HOWTO + +Introduction + +Firmware assisted dump is a new feature in the 3.4 mainline kernel supported +only on powerpc architecture. The goal of firmware-assisted dump is to enable +the dump of a crashed system, and to do so from a fully-reset system, and to +minimize the total elapsed time until the system is back in production use. A +complete documentation on implementation can be found at +Documentation/powerpc/firmware-assisted-dump.txt in upstream linux kernel tree +from 3.4 version and above. + +Please note that the firmware-assisted dump feature is only available on Power6 +and above systems with recent firmware versions. + +Overview + +Fadump + +Fadump is a robust kernel crash dumping mechanism to get reliable kernel crash +dump with assistance from firmware. This approach does not use kexec, instead +firmware assists in booting the kdump kernel while preserving memory contents. +Unlike kdump, the system is fully reset, and loaded with a fresh copy of the +kernel. In particular, PCI and I/O devices are reinitialized and are in a +clean, consistent state. This second kernel, often called a capture kernel, +boots with very little memory and captures the dump image. + +The first kernel registers the sections of memory with the Power firmware for +dump preservation during OS initialization. These registered sections of memory +are reserved by the first kernel during early boot. When a system crashes, the +Power firmware fully resets the system, preserves all the system memory +contents, save the low memory (boot memory of size larger of 5% of system +RAM or 256MB) of RAM to the previous registered region. It will also save +system registers, and hardware PTE's. + +Fadump is supported only on ppc64 platform. The standard kernel and capture +kernel are one and the same on ppc64. + +If you're reading this document, you should already have kexec-tools +installed. If not, you install it via the following command: + + # yum install kexec-tools + +Fadump Operational Flow: + +Like kdump, fadump also exports the ELF formatted kernel crash dump through +/proc/vmcore. Hence existing kdump infrastructure can be used to capture fadump +vmcore. The idea is to keep the functionality transparent to end user. From +user perspective there is no change in the way kdump init script works. + +However, unlike kdump, fadump does not pre-load kdump kernel and initrd into +reserved memory, instead it always uses default OS initrd during second boot +after crash. Hence, for fadump, we rebuild the new kdump initrd and replace it +with default initrd. Before replacing existing default initrd we take a backup +of original default initrd which is restored back when user decides to switch +to kdump. The dracut package has been enhanced to rebuild the default initrd +with vmcore capture steps as per /etc/kdump.conf + +The control flow of fadump works as follows: +01. System panics. +02. At the crash, kernel informs power firmware that kernel has crashed. +03. Firmware takes the control and reboots the entire system preserving + only the memory (resets all other devices). +04. The reboot follows the normal booting process (non-kexec). +05. The boot loader loads the default kernel and initrd from /boot +06. The default initrd loads and runs /init +07. dracut-kdump.sh script present in fadump aware default initrd checks if + '/proc/vmcore' file exists before executing steps to capture vmcore. + (This check will help to bypass the vmcore capture steps during normal boot + process.) +09. Captures dump according to /etc/kdump.conf +10. Is dump capture successful (yes goto 12, no goto 11) +11. Perfom the default action specified in /etc/kdump.conf (Default action + is reboot, if unspecified) +12. Reboot + + +How to configure fadump: + +Again, we assume if you're reading this document, you should already have +kexec-tools installed. If not, you install it via the following command: + + # yum install kexec-tools + +To be able to do much of anything interesting in the way of debug analysis, +you'll also need to install the kernel-debuginfo package, of the same arch +as your running kernel, and the crash utility: + + # yum --enablerepo=*debuginfo install kernel-debuginfo.$(uname -m) crash + +Next up, we need to modify some boot parameters to enable firmware assisted +dump. With the help of grubby, it's very easy to append "fadump=on" to the end +of your kernel boot parameters. Optionally, user can also append +'fadump_reserve_mem=X' kernel cmdline to specify size of the memory to reserve +for boot memory dump preservation. + + # grubby --args="fadump=on" --update-kernel=/boot/vmlinuz-`uname -r` + +The term 'boot memory' means size of the low memory chunk that is required for +a kernel to boot successfully when booted with restricted memory. By default, +the boot memory size will be the larger of 5% of system RAM or 256MB. +Alternatively, user can also specify boot memory size through boot parameter +'fadump_reserve_mem=' which will override the default calculated size. Use this +option if default boot memory size is not sufficient for second kernel to boot +successfully. + +After making said changes, reboot your system, so that the specified memory is +reserved and left untouched by the normal system. Take note that the output of +'free -m' will show X MB less memory than without this parameter, which is +expected. If you see OOM (Out Of Memory) error messages while loading capture +kernel, then you should bump up the memory reservation size. + +Now that you've got that reserved memory region set up, you want to turn on +the kdump init script: + + # systemctl enable kdump.service + +Then, start up kdump as well: + + # systemctl start kdump.service + +This should turn on the firmware assisted functionality in kernel by +echo'ing 1 to /sys/kernel/fadump_registered, leaving the system ready +to capture a vmcore upon crashing. To test this out, you can force-crash +your system by echo'ing a c into /proc/sysrq-trigger: + + # echo c > /proc/sysrq-trigger + +You should see some panic output, followed by the system reset and booting into +fresh copy of kernel. When default initrd loads and runs /init, vmcore should +be copied out to disk (by default, in /var/crash/YYYY.MM.DD-HH:MM:SS/vmcore), +then the system rebooted back into your normal kernel. + +Once back to your normal kernel, you can use the previously installed crash +kernel in conjunction with the previously installed kernel-debuginfo to +perform postmortem analysis: + + # crash /usr/lib/debug/lib/modules/2.6.17-1.2621.el5/vmlinux + /var/crash/2006-08-23-15:34/vmcore + + crash> bt + +and so on... + +Saving vmcore-dmesg.txt +---------------------- +Kernel log bufferes are one of the most important information available +in vmcore. Now before saving vmcore, kernel log bufferes are extracted +from /proc/vmcore and saved into a file vmcore-dmesg.txt. After +vmcore-dmesg.txt, vmcore is saved. Destination disk and directory for +vmcore-dmesg.txt is same as vmcore. Note that kernel log buffers will +not be available if dump target is raw device. + +Dump Triggering methods: + +This section talks about the various ways, other than a Kernel Panic, in which +fadump can be triggered. The following methods assume that fadump is configured +on your system, with the scripts enabled as described in the section above. + +1) AltSysRq C + +FAdump can be triggered with the combination of the 'Alt','SysRq' and 'C' +keyboard keys. Please refer to the following link for more details: + +http://kbase.redhat.com/faq/FAQ_43_5559.shtm + +In addition, on PowerPC boxes, fadump can also be triggered via Hardware +Management Console(HMC) using 'Ctrl', 'O' and 'C' keyboard keys. + +2) Kernel OOPs + +If we want to generate a dump everytime the Kernel OOPses, we can achieve this +by setting the 'Panic On OOPs' option as follows: + + # echo 1 > /proc/sys/kernel/panic_on_oops + +3) PowerPC specific methods: + +On IBM PowerPC machines, issuing a soft reset invokes the XMON debugger(if +XMON is configured). To configure XMON one needs to compile the kernel with +the CONFIG_XMON and CONFIG_XMON_DEFAULT options, or by compiling with +CONFIG_XMON and booting the kernel with xmon=on option. + +Following are the ways to remotely issue a soft reset on PowerPC boxes, which +would drop you to XMON. Pressing a 'X' (capital alphabet X) followed by an +'Enter' here will trigger the dump. + +3.1) HMC + +Hardware Management Console(HMC) available on Power4 and Power5 machines allow +partitions to be reset remotely. This is specially useful in hang situations +where the system is not accepting any keyboard inputs. + +Once you have HMC configured, the following steps will enable you to trigger +fadump via a soft reset: + +On Power4 + Using GUI + + * In the right pane, right click on the partition you wish to dump. + * Select "Operating System->Reset". + * Select "Soft Reset". + * Select "Yes". + + Using HMC Commandline + + # reset_partition -m <machine> -p <partition> -t soft + +On Power5 + Using GUI + + * In the right pane, right click on the partition you wish to dump. + * Select "Restart Partition". + * Select "Dump". + * Select "OK". + + Using HMC Commandline + + # chsysstate -m <managed system name> -n <lpar name> -o dumprestart -r lpar + +3.2) Blade Management Console for Blade Center + +To initiate a dump operation, go to Power/Restart option under "Blade Tasks" in +the Blade Management Console. Select the corresponding blade for which you want +to initate the dump and then click "Restart blade with NMI". This issues a +system reset and invokes xmon debugger. + + +Advanced Setups & Default action: + +Kdump and fadump exhibit similar behavior in terms of setup & default action. +For fadump advanced setup related information see section "Advanced Setups" in +"kexec-kdump-howto.txt" document. Refer to "Default action" section in "kexec- +kdump-howto.txt" document for fadump default action related information. + +Compression and filtering + +Refer "Compression and filtering" section in "kexec-kdump-howto.txt" document. +Compression and filtering are same for kdump & fadump. + + +Notes on rootfs mount: +Dracut is designed to mount rootfs by default. If rootfs mounting fails it +will refuse to go on. So fadump leaves rootfs mounting to dracut currently. +We make the assumtion that proper root= cmdline is being passed to dracut +initramfs for the time being. If you need modify "KDUMP_COMMANDLINE=" in +/etc/sysconfig/kdump, you will need to make sure that appropriate root= +options are copied from /proc/cmdline. In general it is best to append +command line options using "KDUMP_COMMANDLINE_APPEND=" instead of replacing +the original command line completely.