[RESEND PATCH v7 6/6] kdump: Add firmware-assisted dump howto document
by Hari Bathini
Resending this patch by updating 'fadump control flow' to reflect
the latest changes.
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(a)linux.vnet.ibm.com>
Signed-off-by: Hari Bathini <hbathini(a)linux.vnet.ibm.com>
---
fadump-howto.txt | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 251 insertions(+)
create mode 100644 fadump-howto.txt
diff --git a/fadump-howto.txt b/fadump-howto.txt
new file mode 100644
index 0000000..cfde878
--- /dev/null
+++ b/fadump-howto.txt
@@ -0,0 +1,251 @@
+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 for user's reference. The dracut package has been
+enhanced to rebuild the default initrd with vmcore capture steps. The initrd
+image is rebuilt as per the configuration in /etc/kdump.conf file.
+
+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/device-tree/rtas/ibm,kernel-dump' 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.
9 years, 9 months
[PATCH v3 0/5] Kdump error handling service
by WANG Chao
Hi, All
Now upon failure kdump script might not be called at all and it might
not be able to execute default action. It results in a hang.
Because we disable emergency shell and rely on kdump.sh being invoked
through dracut-pre-pivot hook. But it might happen that we never call
into dracut-pre-pivot hook because certain systemd targets could not
reach due to failure in their dependencies. In those cases error
handling code does not run and system hangs.
To solve this problem, we need to separate the error handling code from
dracut-pre-pivot hook, and every time when a failure shows up, the
separated code can be called by the emergency service.
By default systemd provides an emergency service which will drop us into
shell every time upon a critical failure. It's very convenient for us to
re-use the framework of systemd emergency, because we don't have to
touch the other parts of systemd. We can use our own script instead of
the default one.
This new scheme will overwrite emergency shell and replace with kdump
error handling code. And this code will do the error handling as needed.
Now, we will not rely on dracut-pre-pivot hook running always. Instead
whenever error happens and it is serious enough that emergency shell
needed to run, now kdump error handler will run.
This patchset introduce a new kdump emergency service. It will override the
existing emergency.service. When fatal error occurs, this emergency service
will be triggered and systemd will isolate to emergency path.
This kdump emergency service can will read kdump.conf and act according to the
configired "default action" (reboot/poweroff/halt/shell/dump_to_rootfs).
Along with this patchset, kdump-capture.service is introduced as a service unit
to run kdump.sh. When kdump-capture.service fails, systemd will isolate to
kdump emergency service. I copied all the dependencies from
dracut-pre-pivot.service to kdump-capture.service so that kdump.sh will be
called at the correct time window.
v2:
Address several comments from Vivek:
- split [patch 1] into 1/6 and 2/6
- remove several unnecessary lines in service unit.
- modify the description of kdump-capture.service
- introduce another kdump lib kdump-lib-2.sh used in 2nd kernel.
V3:
Address several comments from Vivek:
- update description of [PATCH 1/5] and [PATCH 5/5]
- separate the patch of cleanup to kdump-lib-initramfs.sh
WANG Chao (5):
Introduce kdump error handling service
Introduce kdump capture service
disable dracut-emergency.service the whole time
mkdumprd: mount dump target under /sysroot in 2nd kernel
mkdumprd: append "x-initrd.mount" to the mount options.
dracut-kdump-capture.service | 23 +++++++++++++++++++++++
dracut-kdump-emergency.service | 23 +++++++++++++++++++++++
dracut-kdump-error-handler.sh | 10 ++++++++++
dracut-kdump.sh | 9 ++-------
dracut-module-setup.sh | 7 ++++++-
kexec-tools.spec | 7 ++++++-
mkdumprd | 25 +++++++++++++------------
7 files changed, 83 insertions(+), 21 deletions(-)
create mode 100644 dracut-kdump-capture.service
create mode 100644 dracut-kdump-emergency.service
create mode 100755 dracut-kdump-error-handler.sh
--
1.9.3
9 years, 9 months
Re: kdump annaconda addon update
by Dave Young
Oops, cced wrong list, should be Fedora list instead.
----- Original Message -----
From: "Dave Young" <dyoung(a)redhat.com>
To: chaowang(a)redhat.com
Cc: kexec-kdump-list(a)redhat.com
Sent: Wednesday, July 23, 2014 3:23:51 PM
Subject: kdump annaconda addon update
Hi, Chao
I have merged patches for optionally enable kdump addon in Fedora
Also during my test there's a bug in previous release, some propeties does
not exist in gtk3, ananconda people helped fixed RHEL part but for Fedora
there's a seperate glade gui file which need update as well
I have fixed above issue.
BTW, I changed the version number to git tag name instead of date because
it's hard to match the date prefix with the commit point in git.
Please upload a new addon tarball and add a new release in F21 so that we
can test with the default F21 boot.iso
Thanks
Dave
9 years, 9 months
[PATCH v2 1/2] dracut-module-setup: avoid writing the vlan.conf twice
by WANG Chao
We handle different types of device for vlan. For each type, it should
write different options for vlan.conf in each control path.
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-module-setup.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index b58146c..5732e04 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -154,8 +154,6 @@ kdump_setup_vlan() {
local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")"
local _netmac="$(kdump_get_mac_addr $_phydev)"
- echo " vlan=$_netdev:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf
-
#Just support vlan over bond, it is not easy
#to support all other complex setup
if kdump_is_bridge "$_phydev"; then
@@ -166,6 +164,7 @@ kdump_setup_vlan() {
exit 1
elif kdump_is_bond "$_phydev"; then
kdump_setup_bond "$_phydev"
+ echo " vlan=$_netdev:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf
else
echo " vlan=$_netdev:$_phydev ifname=$_phydev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf
fi
--
1.9.3
9 years, 9 months
[PATCH v2 1/2] dracut-module-setup: avoid writing the vlan.conf twice
by WANG Chao
We handle different types of device for vlan. For each type, it should
write different options for vlan.conf in each control path.
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-module-setup.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 87ad072..d2d135b 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -154,8 +154,6 @@ kdump_setup_vlan() {
local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")"
local _netmac="$(kdump_get_mac_addr $_phydev)"
- echo " vlan=$_netdev:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf
-
#Just support vlan over bond, it is not easy
#to support all other complex setup
if kdump_is_bridge "$_phydev"; then
@@ -166,6 +164,7 @@ kdump_setup_vlan() {
exit 1
elif kdump_is_bond "$_phydev"; then
kdump_setup_bond "$_phydev"
+ echo " vlan=$_netdev:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf
else
echo " vlan=$_netdev:$_phydev ifname=$_phydev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf
fi
--
1.9.3
9 years, 9 months
[PATCH] dracut-module-setup: NIC renamed with prefix "kdump-" for native ethX
by WANG Chao
We met a problem that eth0 ends up being eth1 and eth1 being eth0
between 1st and 2nd kernel. Because we pass ifname=eth0:$mac to force
it's named eth0 and since "eth0"is already taken by the other NIC, udev
fails to bring up the NIC we want, thus kdump fails.
For ethX, we put a prefix "kdump-" before it, so in 2nd kernel, ethX
will name to "kdump-ethX". So that we can avoid the naming conflict.
We only need to change the ethernet card name, that means, for bridge,
vlan, bond, team devices' names , we never prefix them. Because these
names are assigned when they're created by userspace.
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-module-setup.sh | 50 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 15 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 87ad072..2fcfd21 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -97,9 +97,21 @@ kdump_get_perm_addr() {
fi
}
+kdump_setup_ifname() {
+ local _ifname
+
+ if [[ $1 =~ eth* ]]; then
+ _ifname="kdump-$1"
+ else
+ _ifname="$1"
+ fi
+
+ echo "$_ifname"
+}
+
kdump_setup_bridge() {
local _netdev=$1
- local _brif _dev
+ local _brif _dev _mac
for _dev in `ls /sys/class/net/$_netdev/brif/`; do
if kdump_is_bond "$_dev"; then
kdump_setup_bond "$_dev"
@@ -108,7 +120,9 @@ kdump_setup_bridge() {
elif kdump_is_vlan "$_dev"; then
kdump_setup_vlan "$_dev"
else
- echo -n " ifname=$_dev:$(kdump_get_mac_addr $_dev)" >> ${initdir}/etc/cmdline.d/41bridge.conf
+ _mac=$(kdump_get_mac_addr $_dev)
+ _dev=$(kdump_setup_ifname $_dev)
+ echo -n " ifname=$_dev:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf
fi
_brif+="$_dev,"
done
@@ -117,11 +131,14 @@ kdump_setup_bridge() {
kdump_setup_bond() {
local _netdev=$1
- local _dev
+ local _dev _mac _slaves
for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do
- echo -n " ifname=$_dev:$(kdump_get_perm_addr $_dev)" >> ${initdir}/etc/cmdline.d/42bond.conf
+ _mac=$(kdump_get_perm_addr $_dev)
+ _dev=$(kdump_setup_ifname $_dev)
+ echo -n " ifname=$_dev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf
+ _slaves+="$_dev,"
done
- echo -n " bond=$_netdev:$(sed -e 's/ /,/g' /sys/class/net/$_netdev/bonding/slaves)" >> ${initdir}/etc/cmdline.d/42bond.conf
+ echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf
# Get bond options specified in ifcfg
. /etc/sysconfig/network-scripts/ifcfg-$_netdev
bondoptions="$(echo :$BONDING_OPTS | sed 's/\s\+/,/')"
@@ -130,10 +147,12 @@ kdump_setup_bond() {
kdump_setup_team() {
local _netdev=$1
- local slaves _dev
+ local _dev _mac _slaves
for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do
- echo -n " ifname=$_dev:$(kdump_get_perm_addr $_dev)" >> ${initdir}/etc/cmdline.d/44team.conf
- slaves+="$_dev,"
+ _mac=$(kdump_get_perm_addr $_dev)
+ _dev=$(kdump_setup_ifname $_dev)
+ echo -n " ifname=$_dev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf
+ _slaves+="$_dev,"
done
echo " team=$_netdev:$(echo $slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf
#Buggy version teamdctl outputs to stderr!
@@ -153,8 +172,7 @@ kdump_setup_vlan() {
local _netdev=$1
local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")"
local _netmac="$(kdump_get_mac_addr $_phydev)"
-
- echo " vlan=$_netdev:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf
+ local _dev
#Just support vlan over bond, it is not easy
#to support all other complex setup
@@ -166,8 +184,10 @@ kdump_setup_vlan() {
exit 1
elif kdump_is_bond "$_phydev"; then
kdump_setup_bond "$_phydev"
+ echo " vlan=$_netdev:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf
else
- echo " vlan=$_netdev:$_phydev ifname=$_phydev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf
+ local _dev="$(kdump_setup_ifname $_phydev)"
+ echo " vlan=$_netdev:$_dev ifname=$_dev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf
fi
}
@@ -200,7 +220,7 @@ kdump_setup_netdev() {
fi
_ip_conf="${initdir}/etc/cmdline.d/40ip.conf"
- _ip_opts=" ip=${_static}$_netdev:${_proto}"
+ _ip_opts=" ip=${_static}$(kdump_setup_ifname $_netdev):${_proto}"
# dracut doesn't allow duplicated configuration for same NIC, even they're exactly the same.
# so we have to avoid adding duplicates
@@ -217,7 +237,7 @@ kdump_setup_netdev() {
elif kdump_is_vlan "$_netdev"; then
kdump_setup_vlan "$_netdev"
else
- _ifname_opts=" ifname=$_netdev:$(kdump_get_mac_addr $_netdev)"
+ _ifname_opts=" ifname=$(kdump_setup_ifname $_netdev):$(kdump_get_mac_addr $_netdev)"
echo "$_ifname_opts" >> $_ip_conf
fi
@@ -262,8 +282,8 @@ kdump_install_net() {
# gateway.
if [ ! -f ${initdir}${initdir}/etc/cmdline.d/60kdumpnic.conf ] &&
[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then
- echo "kdumpnic=${_netdev}" > ${initdir}/etc/cmdline.d/60kdumpnic.conf
- echo "bootdev=${_netdev}" > ${initdir}/etc/cmdline.d/70bootdev.conf
+ echo "kdumpnic=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/60kdumpnic.conf
+ echo "bootdev=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/70bootdev.conf
fi
}
--
1.9.3
9 years, 9 months
[PATCH v6 0/7] kdump: Modify kdump init script to support firmware-assisted dump
by Hari Bathini
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 from v5 to v6:
1. Using common global variable TARGET_INITRD for both kdump and
fadump modes
2. Reworked on determine_dump_mode routine
3. Using a temporary image for rebuilding
---
Hari Bathini (7):
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: Rebuild default initrd for firmware assisted dump
kdump: Check for /proc/vmcore existence before capturing the vmcore.
kdump: Add firmware-assisted dump howto document
cleanup: Remove "function" keyword from all functions and correct typos
dracut-kdump.sh | 3 +
fadump-howto.txt | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
kdumpctl | 242 ++++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 456 insertions(+), 39 deletions(-)
create mode 100644 fadump-howto.txt
--
- Hari
9 years, 9 months
[PATCH v2] cleanup: extract functions from kdump.sh to kdump-lib-initramfs.sh
by WANG Chao
Extract functions from kdump.sh, and construct kdump-lib-initramfs.sh as
kdump common functions/varaibles library.
kdump-lib-initramfs.sh will include kdump-lib.sh, because it will use
the functions from there. IOW, kdump-lib-initramfs.sh will be a superset
of kdump-lib.sh
So after this cleanup:
- scripts running in 1st kernel only have to include kdump-lib.sh
- scripts running in 2nd kernel only have to include kdump-lib-initramfs.sh
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-kdump.sh | 153 +---------------------------------------------
dracut-module-setup.sh | 1 +
kdump-lib-initramfs.sh | 162 +++++++++++++++++++++++++++++++++++++++++++++++++
kdump-lib.sh | 1 -
kexec-tools.spec | 2 +
5 files changed, 168 insertions(+), 151 deletions(-)
create mode 100755 kdump-lib-initramfs.sh
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index cb13d92..194c3c3 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
@@ -3,30 +3,13 @@
exec &> /dev/console
. /lib/dracut-lib.sh
. /lib/kdump-lib.sh
+. /lib/kdump-lib-initramfs.sh
if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then
rm -f -- $initdir/lib/dracut/no-emergency-shell
fi
set -o pipefail
-KDUMP_PATH="/var/crash"
-CORE_COLLECTOR=""
-DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
-DMESG_COLLECTOR="/sbin/vmcore-dmesg"
-DEFAULT_ACTION="reboot -f"
-DATEDIR=`date +%Y.%m.%d-%T`
-HOST_IP='127.0.0.1'
-DUMP_INSTRUCTION=""
-SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
-KDUMP_SCRIPT_DIR="/kdumpscripts"
-DD_BLKSIZE=512
-FINAL_ACTION="reboot -f"
-DUMP_RETVAL=0
-conf_file="/etc/kdump.conf"
-KDUMP_PRE=""
-KDUMP_POST=""
-MOUNTS=""
-
export PATH=$PATH:$KDUMP_SCRIPT_DIR
do_dump()
@@ -43,27 +26,6 @@ do_dump()
return $_ret
}
-do_umount()
-{
- if [ -n "$MOUNTS" ]; then
- for mount in $MOUNTS; do
- ismounted $mount && umount -R $mount
- done
- fi
-}
-
-do_final_action()
-{
- do_umount
- eval $FINAL_ACTION
-}
-
-do_default_action()
-{
- wait_for_loginit
- eval $DEFAULT_ACTION
-}
-
do_kdump_pre()
{
if [ -n "$KDUMP_PRE" ]; then
@@ -83,39 +45,6 @@ add_dump_code()
DUMP_INSTRUCTION=$1
}
-# dump_fs <mount point| device>
-dump_fs()
-{
- local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
- local _mp=$(findmnt -k -f -n -r -o TARGET $1)
-
- echo "kdump: dump target is $_dev"
-
- if [ -z "$_mp" ]; then
- echo "kdump: error: Dump target $_dev is not mounted."
- return 1
- fi
- MOUNTS="$MOUNTS $_mp"
-
- # Remove -F in makedumpfile case. We don't want a flat format dump here.
- [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
-
- echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- mount -o remount,rw $_mp || return 1
- mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
-
- save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- echo "kdump: saving vmcore"
- $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1
- mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
- sync
-
- echo "kdump: saving vmcore complete"
- return 0
-}
-
dump_raw()
{
local _raw=$1
@@ -165,21 +94,6 @@ dump_ssh()
return 0
}
-save_vmcore_dmesg_fs() {
- local _dmesg_collector=$1
- local _path=$2
-
- echo "kdump: saving vmcore-dmesg.txt"
- $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
- _exitcode=$?
- if [ $_exitcode -eq 0 ]; then
- mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
- echo "kdump: saving vmcore-dmesg.txt complete"
- else
- echo "kdump: saving vmcore-dmesg.txt failed"
- fi
-}
-
save_vmcore_dmesg_ssh() {
local _dmesg_collector=$1
local _path=$2
@@ -218,61 +132,7 @@ get_host_ip()
read_kdump_conf()
{
- if [ ! -f "$conf_file" ]; then
- echo "kdump: $conf_file not found"
- return
- fi
-
- # first get the necessary variables
- while read config_opt config_val;
- do
- # remove inline comments after the end of a directive.
- config_val=$(strip_comments $config_val)
- case "$config_opt" in
- path)
- KDUMP_PATH="$config_val"
- ;;
- core_collector)
- [ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
- ;;
- sshkey)
- if [ -f "$config_val" ]; then
- SSH_KEY_LOCATION=$config_val
- fi
- ;;
- kdump_pre)
- KDUMP_PRE="$config_val"
- ;;
- kdump_post)
- KDUMP_POST="$config_val"
- ;;
- fence_kdump_args)
- FENCE_KDUMP_ARGS="$config_val"
- ;;
- fence_kdump_nodes)
- FENCE_KDUMP_NODES="$config_val"
- ;;
- default)
- case $config_val in
- shell)
- DEFAULT_ACTION="_emergency_shell kdump"
- ;;
- reboot)
- DEFAULT_ACTION="do_umount; reboot -f"
- ;;
- halt)
- DEFAULT_ACTION="do_umount; halt -f"
- ;;
- poweroff)
- DEFAULT_ACTION="do_umount; poweroff -f"
- ;;
- dump_to_rootfs)
- DEFAULT_ACTION="dump_fs $NEWROOT"
- ;;
- esac
- ;;
- esac
- done < $conf_file
+ get_kdump_confs
# rescan for add code for dump target
while read config_opt config_val;
@@ -290,7 +150,7 @@ read_kdump_conf()
add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val"
;;
esac
- done < $conf_file
+ done < $KDUMP_CONF
}
fence_kdump_notify()
@@ -303,13 +163,6 @@ fence_kdump_notify()
read_kdump_conf
fence_kdump_notify
-if [ -z "$CORE_COLLECTOR" ];then
- CORE_COLLECTOR=$DEFAULT_CORE_COLLECTOR
- if is_ssh_dump_target || is_raw_dump_target; then
- CORE_COLLECTOR="$CORE_COLLECTOR -F"
- fi
-fi
-
get_host_ip
if [ $? -ne 0 ]; then
echo "kdump: get_host_ip exited with non-zero status!"
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 87ad072..84bf975 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -555,6 +555,7 @@ install() {
inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg"
inst_hook pre-pivot 9999 "$moddir/kdump.sh"
inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"
+ inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh"
# Check for all the devices and if any device is iscsi, bring up iscsi
# target. Ideally all this should be pushed into dracut iscsi module
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
new file mode 100755
index 0000000..a79fe59
--- /dev/null
+++ b/kdump-lib-initramfs.sh
@@ -0,0 +1,162 @@
+# These variables and functions are useful in 2nd kernel
+
+. /lib/kdump-lib.sh
+
+KDUMP_PATH="/var/crash"
+CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
+DMESG_COLLECTOR="/sbin/vmcore-dmesg"
+DEFAULT_ACTION="reboot -f"
+SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
+KDUMP_PRE=""
+KDUMP_POST=""
+DATEDIR=`date +%Y.%m.%d-%T`
+HOST_IP='127.0.0.1'
+DUMP_INSTRUCTION=""
+KDUMP_SCRIPT_DIR="/kdumpscripts"
+DD_BLKSIZE=512
+KDUMP_CONF="/etc/kdump.conf"
+NEWROOT="/sysroot"
+
+get_kdump_confs()
+{
+ local config_opt config_val
+ local user_specified_cc
+
+ while read config_opt config_val;
+ do
+ # remove inline comments after the end of a directive.
+ config_val=$(strip_comments $config_val)
+ case "$config_opt" in
+ path)
+ KDUMP_PATH="$config_val"
+ ;;
+ core_collector)
+ CORE_COLLECTOR="$config_val"
+ user_specified_cc=yes
+ ;;
+ sshkey)
+ SSH_KEY_LOCATION=$config_val
+ ;;
+ kdump_pre)
+ KDUMP_PRE="$config_val"
+ ;;
+ kdump_post)
+ KDUMP_POST="$config_val"
+ ;;
+ fence_kdump_args)
+ FENCE_KDUMP_ARGS="$config_val"
+ ;;
+ fence_kdump_nodes)
+ FENCE_KDUMP_NODES="$config_val"
+ ;;
+ default)
+ case $config_val in
+ shell)
+ DEFAULT_ACTION="kdump_emergency_shell"
+ ;;
+ reboot)
+ DEFAULT_ACTION="do_umount; reboot -f"
+ ;;
+ halt)
+ DEFAULT_ACTION="do_umount; halt -f"
+ ;;
+ poweroff)
+ DEFAULT_ACTION="do_umount; poweroff -f"
+ ;;
+ dump_to_rootfs)
+ DEFAULT_ACTION="dump_to_rootfs"
+ ;;
+ esac
+ ;;
+ esac
+ done < $KDUMP_CONF
+
+ if is_ssh_dump_target || is_raw_dump_target; then
+ if [ -z "$user_specified_cc" ]; then
+ CORE_COLLECTOR="$CORE_COLLECTOR -F"
+ fi
+ fi
+}
+
+# dump_fs <mount point| device>
+dump_fs()
+{
+
+ local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
+ local _mp=$(findmnt -k -f -n -r -o TARGET $1)
+
+ echo "kdump: dump target is $_dev"
+
+ if [ -z "$_mp" ]; then
+ echo "kdump: error: Dump target $_dev is not mounted."
+ return 1
+ fi
+
+ # Remove -F in makedumpfile case. We don't want a flat format dump here.
+ [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
+
+ echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ mount -o remount,rw $_mp || return 1
+ mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
+
+ save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ echo "kdump: saving vmcore"
+ $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1
+ mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
+ sync
+
+ echo "kdump: saving vmcore complete"
+}
+
+save_vmcore_dmesg_fs() {
+ local _dmesg_collector=$1
+ local _path=$2
+
+ echo "kdump: saving vmcore-dmesg.txt"
+ $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
+ _exitcode=$?
+ if [ $_exitcode -eq 0 ]; then
+ mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
+ echo "kdump: saving vmcore-dmesg.txt complete"
+ else
+ echo "kdump: saving vmcore-dmesg.txt failed"
+ fi
+}
+
+dump_to_rootfs()
+{
+
+ echo "Kdump: trying to bring up rootfs device"
+ systemctl start dracut-initqueue
+ echo "Kdump: waiting for rootfs mount, will timeout after 90 seconds"
+ systemctl start sysroot.mount
+
+ dump_fs $NEWROOT
+}
+
+kdump_emergency_shell()
+{
+ echo "PS1=\"kdump:\\\${PWD}# \"" >/etc/profile
+ /bin/dracut-emergency
+ rm -f /etc/profile
+}
+
+do_umount()
+{
+ umount -Rf /sysroot
+}
+
+do_default_action()
+{
+ echo "Kdump: Error Occured, doing default action"
+ eval $DEFAULT_ACTION
+}
+
+
+do_final_action()
+{
+ do_umount
+ reboot -f
+}
diff --git a/kdump-lib.sh b/kdump-lib.sh
index a20c6e8..07b9527 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -137,4 +137,3 @@ check_save_path_fs()
perror_exit "Dump path $_path does not exist."
fi
}
-
diff --git a/kexec-tools.spec b/kexec-tools.spec
index c4db536..5aa919c 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -27,6 +27,7 @@ Source20: kdump-lib.sh
Source21: kdump-in-cluster-environment.txt
Source22: kdump-dep-generator.sh
Source23: kdump-anaconda-addon-20140522.tar.gz
+Source24: kdump-lib-initramfs.sh
#######################################
# These are sources for mkdumpramfs
@@ -178,6 +179,7 @@ install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8
install -m 755 %{SOURCE11} $RPM_BUILD_ROOT%{_datadir}/kdump/firstboot_kdump.py
install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8
install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh
+install -m 755 %{SOURCE24} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh
%ifnarch s390x
# For s390x the ELF header is created in the kdump kernel and therefore kexec
# udev rules are not required
--
1.9.3
9 years, 9 months
[PATCH] cleanup: Remove "function" keyword from all functions and correct typos
by Hari Bathini
This cleanup patch removes unnecessary keyword "function" at all places in
kdumpctl script. Also, corrects couple of typos in the script.
Signed-off-by: Hari Bathini <hbathini(a)linux.vnet.ibm.com>
---
kdumpctl | 94 ++++++++++++++++++++++++++++++++------------------------------
1 file changed, 48 insertions(+), 46 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 9cae0c4..67f43c6 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -27,7 +27,7 @@ single_instance_lock()
# 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
@@ -45,7 +45,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"; } \
@@ -58,21 +58,21 @@ 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/""}
+ local cmdline=$1
+ local newstr=${cmdline/$2/""}
- # unchanged str implies argument wasn't there
- if [ "$cmdline" == "$newstr" ]; then
- cmdline="${cmdline} ${2}=${3}"
- fi
+ # unchanged str implies argument wasn't there
+ if [ "$cmdline" == "$newstr" ]; then
+ cmdline="${cmdline} ${2}=${3}"
+ fi
- echo $cmdline
+ echo $cmdline
}
# This function performs a series of edits on the command line
-function prepare_cmdline()
+prepare_cmdline()
{
local cmdline;
if [ -z "$KDUMP_COMMANDLINE" ]; then
@@ -94,7 +94,7 @@ function prepare_cmdline()
}
-function save_core()
+save_core()
{
coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
@@ -119,7 +119,7 @@ function save_core()
fi
}
-function rebuild_initrd()
+rebuild_initrd()
{
$MKDUMPRD $kdump_initrd $kdump_kver
if [ $? != 0 ]; then
@@ -129,7 +129,7 @@ function rebuild_initrd()
}
#$1: the files to be checked with IFS=' '
-function check_exist()
+check_exist()
{
for file in $1; do
if [ ! -f "$file" ]; then
@@ -140,7 +140,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
@@ -150,7 +150,7 @@ function check_executable()
done
}
-function check_config()
+check_config()
{
local nr
@@ -161,8 +161,8 @@ function check_config()
}
while read config_opt config_val; do
- # remove inline comments after the end of a directive.
- config_val=$(strip_comments $config_val)
+ # remove inline comments after the end of a directive.
+ config_val=$(strip_comments $config_val)
case "$config_opt" in
\#* | "")
;;
@@ -182,7 +182,7 @@ function check_config()
;;
esac
done < $KDUMP_CONFIG_FILE
-
+
check_fence_kdump_config || return 1
return 0
@@ -216,7 +216,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"
@@ -276,7 +276,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
@@ -289,16 +289,16 @@ 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")); }'`
+ return `tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); \
+ print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'`
}
# 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 ]
@@ -345,11 +345,11 @@ 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.
- config_val=$(strip_comments $config_val)
+ # remove inline comments after the end of a directive.
+ config_val=$(strip_comments $config_val)
case "$config_opt" in
sshkey)
if [ -f "$config_val" ]; then
@@ -378,7 +378,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
@@ -390,7 +390,7 @@ function check_ssh_target()
return 0
}
-function propagate_ssh_key()
+propagate_ssh_key()
{
check_ssh_config
if [ $? -ne 0 ]; then
@@ -413,7 +413,7 @@ function propagate_ssh_key()
#now find the target ssh user and server to contact.
SSH_USER=`echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1`
SSH_SERVER=`echo $DUMP_TARGET | sed -e's/\(.*(a)\)\(.*$\)/\2/'`
-
+
#now send the found key to the found server
ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER
RET=$?
@@ -424,10 +424,9 @@ function propagate_ssh_key()
echo $errmsg, $KEYFILE failed in transfer to $SSH_SERVER >&2
exit 1
fi
-
}
-function check_current_kdump_status()
+check_current_kdump_status()
{
rc=`cat /sys/kernel/kexec_crash_loaded`
if [ $rc == 1 ]; then
@@ -437,7 +436,7 @@ function check_current_kdump_status()
fi
}
-function save_raw()
+save_raw()
{
local kdump_dir
local raw_target
@@ -472,7 +471,8 @@ function save_raw()
return 0
}
-get_save_path() {
+get_save_path()
+{
local _save_path=$(grep "^path" /etc/kdump.conf|awk '{print $2}')
if [ -z "$_save_path" ]; then
_save_path="/var/crash"
@@ -481,12 +481,13 @@ get_save_path() {
echo $_save_path
}
-is_dump_target_configured() {
- local _target
+is_dump_target_configured()
+{
+ local _target
- _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw|^ssh|^nfs" /etc/kdump.conf)
+ _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw|^ssh|^nfs" /etc/kdump.conf)
- [ -n "$_target" ]
+ [ -n "$_target" ]
}
local_fs_dump_target()
@@ -499,7 +500,8 @@ local_fs_dump_target()
fi
}
-path_to_be_relabeled() {
+path_to_be_relabeled()
+{
local _path _target _mnt="/" _rmnt
if is_dump_target_configured; then
@@ -548,7 +550,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
@@ -568,7 +570,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"
@@ -581,7 +583,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")
@@ -596,7 +598,7 @@ function check_fence_kdump_config()
return 0
}
-function start()
+start()
{
check_config
if [ $? -ne 0 ]; then
@@ -646,7 +648,7 @@ function start()
echo "Starting kdump: [OK]"
}
-function stop()
+stop()
{
$KEXEC -p -u 2>/dev/null
if [ $? == 0 ]; then
@@ -654,7 +656,7 @@ function stop()
echo "Stopping kdump: [OK]"
return 0
else
- echo "kexec: failed to unloaded kdump kernel"
+ echo "kexec: failed to unload kdump kernel"
echo "Stopping kdump: [FAILED]"
return 1
fi
9 years, 9 months
[PATCH] cleanup: extract functions from kdump.sh to kdump-lib-initramfs.sh
by WANG Chao
Extract functions from kdump.sh, and construct kdump-lib-initramfs.sh as
kdump common functions/varaibles library.
kdump-lib-initramfs.sh will include kdump-lib.sh, because it will use
the functions from there. IOW, kdump-lib-initramfs.sh will be a superset
of kdump-lib.sh
So after this cleanup:
- scripts running in 1st kernel only have to include kdump-lib.sh
- scripts running in 2nd kernel only have to include kdump-lib-initramfs.sh
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-kdump.sh | 153 +---------------------------------------------
dracut-module-setup.sh | 1 +
kdump-lib-initramfs.sh | 162 +++++++++++++++++++++++++++++++++++++++++++++++++
kdump-lib.sh | 1 -
kexec-tools.spec | 2 +
5 files changed, 168 insertions(+), 151 deletions(-)
create mode 100755 kdump-lib-initramfs.sh
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index cb13d92..194c3c3 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
@@ -3,30 +3,13 @@
exec &> /dev/console
. /lib/dracut-lib.sh
. /lib/kdump-lib.sh
+. /lib/kdump-lib-initramfs.sh
if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then
rm -f -- $initdir/lib/dracut/no-emergency-shell
fi
set -o pipefail
-KDUMP_PATH="/var/crash"
-CORE_COLLECTOR=""
-DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
-DMESG_COLLECTOR="/sbin/vmcore-dmesg"
-DEFAULT_ACTION="reboot -f"
-DATEDIR=`date +%Y.%m.%d-%T`
-HOST_IP='127.0.0.1'
-DUMP_INSTRUCTION=""
-SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
-KDUMP_SCRIPT_DIR="/kdumpscripts"
-DD_BLKSIZE=512
-FINAL_ACTION="reboot -f"
-DUMP_RETVAL=0
-conf_file="/etc/kdump.conf"
-KDUMP_PRE=""
-KDUMP_POST=""
-MOUNTS=""
-
export PATH=$PATH:$KDUMP_SCRIPT_DIR
do_dump()
@@ -43,27 +26,6 @@ do_dump()
return $_ret
}
-do_umount()
-{
- if [ -n "$MOUNTS" ]; then
- for mount in $MOUNTS; do
- ismounted $mount && umount -R $mount
- done
- fi
-}
-
-do_final_action()
-{
- do_umount
- eval $FINAL_ACTION
-}
-
-do_default_action()
-{
- wait_for_loginit
- eval $DEFAULT_ACTION
-}
-
do_kdump_pre()
{
if [ -n "$KDUMP_PRE" ]; then
@@ -83,39 +45,6 @@ add_dump_code()
DUMP_INSTRUCTION=$1
}
-# dump_fs <mount point| device>
-dump_fs()
-{
- local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
- local _mp=$(findmnt -k -f -n -r -o TARGET $1)
-
- echo "kdump: dump target is $_dev"
-
- if [ -z "$_mp" ]; then
- echo "kdump: error: Dump target $_dev is not mounted."
- return 1
- fi
- MOUNTS="$MOUNTS $_mp"
-
- # Remove -F in makedumpfile case. We don't want a flat format dump here.
- [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
-
- echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- mount -o remount,rw $_mp || return 1
- mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
-
- save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- echo "kdump: saving vmcore"
- $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1
- mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
- sync
-
- echo "kdump: saving vmcore complete"
- return 0
-}
-
dump_raw()
{
local _raw=$1
@@ -165,21 +94,6 @@ dump_ssh()
return 0
}
-save_vmcore_dmesg_fs() {
- local _dmesg_collector=$1
- local _path=$2
-
- echo "kdump: saving vmcore-dmesg.txt"
- $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
- _exitcode=$?
- if [ $_exitcode -eq 0 ]; then
- mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
- echo "kdump: saving vmcore-dmesg.txt complete"
- else
- echo "kdump: saving vmcore-dmesg.txt failed"
- fi
-}
-
save_vmcore_dmesg_ssh() {
local _dmesg_collector=$1
local _path=$2
@@ -218,61 +132,7 @@ get_host_ip()
read_kdump_conf()
{
- if [ ! -f "$conf_file" ]; then
- echo "kdump: $conf_file not found"
- return
- fi
-
- # first get the necessary variables
- while read config_opt config_val;
- do
- # remove inline comments after the end of a directive.
- config_val=$(strip_comments $config_val)
- case "$config_opt" in
- path)
- KDUMP_PATH="$config_val"
- ;;
- core_collector)
- [ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
- ;;
- sshkey)
- if [ -f "$config_val" ]; then
- SSH_KEY_LOCATION=$config_val
- fi
- ;;
- kdump_pre)
- KDUMP_PRE="$config_val"
- ;;
- kdump_post)
- KDUMP_POST="$config_val"
- ;;
- fence_kdump_args)
- FENCE_KDUMP_ARGS="$config_val"
- ;;
- fence_kdump_nodes)
- FENCE_KDUMP_NODES="$config_val"
- ;;
- default)
- case $config_val in
- shell)
- DEFAULT_ACTION="_emergency_shell kdump"
- ;;
- reboot)
- DEFAULT_ACTION="do_umount; reboot -f"
- ;;
- halt)
- DEFAULT_ACTION="do_umount; halt -f"
- ;;
- poweroff)
- DEFAULT_ACTION="do_umount; poweroff -f"
- ;;
- dump_to_rootfs)
- DEFAULT_ACTION="dump_fs $NEWROOT"
- ;;
- esac
- ;;
- esac
- done < $conf_file
+ get_kdump_confs
# rescan for add code for dump target
while read config_opt config_val;
@@ -290,7 +150,7 @@ read_kdump_conf()
add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val"
;;
esac
- done < $conf_file
+ done < $KDUMP_CONF
}
fence_kdump_notify()
@@ -303,13 +163,6 @@ fence_kdump_notify()
read_kdump_conf
fence_kdump_notify
-if [ -z "$CORE_COLLECTOR" ];then
- CORE_COLLECTOR=$DEFAULT_CORE_COLLECTOR
- if is_ssh_dump_target || is_raw_dump_target; then
- CORE_COLLECTOR="$CORE_COLLECTOR -F"
- fi
-fi
-
get_host_ip
if [ $? -ne 0 ]; then
echo "kdump: get_host_ip exited with non-zero status!"
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 87ad072..84bf975 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -555,6 +555,7 @@ install() {
inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg"
inst_hook pre-pivot 9999 "$moddir/kdump.sh"
inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh"
+ inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh"
# Check for all the devices and if any device is iscsi, bring up iscsi
# target. Ideally all this should be pushed into dracut iscsi module
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
new file mode 100755
index 0000000..a79fe59
--- /dev/null
+++ b/kdump-lib-initramfs.sh
@@ -0,0 +1,162 @@
+# These variables and functions are useful in 2nd kernel
+
+. /lib/kdump-lib.sh
+
+KDUMP_PATH="/var/crash"
+CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
+DMESG_COLLECTOR="/sbin/vmcore-dmesg"
+DEFAULT_ACTION="reboot -f"
+SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
+KDUMP_PRE=""
+KDUMP_POST=""
+DATEDIR=`date +%Y.%m.%d-%T`
+HOST_IP='127.0.0.1'
+DUMP_INSTRUCTION=""
+KDUMP_SCRIPT_DIR="/kdumpscripts"
+DD_BLKSIZE=512
+KDUMP_CONF="/etc/kdump.conf"
+NEWROOT="/sysroot"
+
+get_kdump_confs()
+{
+ local config_opt config_val
+ local user_specified_cc
+
+ while read config_opt config_val;
+ do
+ # remove inline comments after the end of a directive.
+ config_val=$(strip_comments $config_val)
+ case "$config_opt" in
+ path)
+ KDUMP_PATH="$config_val"
+ ;;
+ core_collector)
+ CORE_COLLECTOR="$config_val"
+ user_specified_cc=yes
+ ;;
+ sshkey)
+ SSH_KEY_LOCATION=$config_val
+ ;;
+ kdump_pre)
+ KDUMP_PRE="$config_val"
+ ;;
+ kdump_post)
+ KDUMP_POST="$config_val"
+ ;;
+ fence_kdump_args)
+ FENCE_KDUMP_ARGS="$config_val"
+ ;;
+ fence_kdump_nodes)
+ FENCE_KDUMP_NODES="$config_val"
+ ;;
+ default)
+ case $config_val in
+ shell)
+ DEFAULT_ACTION="kdump_emergency_shell"
+ ;;
+ reboot)
+ DEFAULT_ACTION="do_umount; reboot -f"
+ ;;
+ halt)
+ DEFAULT_ACTION="do_umount; halt -f"
+ ;;
+ poweroff)
+ DEFAULT_ACTION="do_umount; poweroff -f"
+ ;;
+ dump_to_rootfs)
+ DEFAULT_ACTION="dump_to_rootfs"
+ ;;
+ esac
+ ;;
+ esac
+ done < $KDUMP_CONF
+
+ if is_ssh_dump_target || is_raw_dump_target; then
+ if [ -z "$user_specified_cc" ]; then
+ CORE_COLLECTOR="$CORE_COLLECTOR -F"
+ fi
+ fi
+}
+
+# dump_fs <mount point| device>
+dump_fs()
+{
+
+ local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
+ local _mp=$(findmnt -k -f -n -r -o TARGET $1)
+
+ echo "kdump: dump target is $_dev"
+
+ if [ -z "$_mp" ]; then
+ echo "kdump: error: Dump target $_dev is not mounted."
+ return 1
+ fi
+
+ # Remove -F in makedumpfile case. We don't want a flat format dump here.
+ [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
+
+ echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ mount -o remount,rw $_mp || return 1
+ mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
+
+ save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ echo "kdump: saving vmcore"
+ $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1
+ mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
+ sync
+
+ echo "kdump: saving vmcore complete"
+}
+
+save_vmcore_dmesg_fs() {
+ local _dmesg_collector=$1
+ local _path=$2
+
+ echo "kdump: saving vmcore-dmesg.txt"
+ $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
+ _exitcode=$?
+ if [ $_exitcode -eq 0 ]; then
+ mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
+ echo "kdump: saving vmcore-dmesg.txt complete"
+ else
+ echo "kdump: saving vmcore-dmesg.txt failed"
+ fi
+}
+
+dump_to_rootfs()
+{
+
+ echo "Kdump: trying to bring up rootfs device"
+ systemctl start dracut-initqueue
+ echo "Kdump: waiting for rootfs mount, will timeout after 90 seconds"
+ systemctl start sysroot.mount
+
+ dump_fs $NEWROOT
+}
+
+kdump_emergency_shell()
+{
+ echo "PS1=\"kdump:\\\${PWD}# \"" >/etc/profile
+ /bin/dracut-emergency
+ rm -f /etc/profile
+}
+
+do_umount()
+{
+ umount -Rf /sysroot
+}
+
+do_default_action()
+{
+ echo "Kdump: Error Occured, doing default action"
+ eval $DEFAULT_ACTION
+}
+
+
+do_final_action()
+{
+ do_umount
+ reboot -f
+}
diff --git a/kdump-lib.sh b/kdump-lib.sh
index a20c6e8..07b9527 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -137,4 +137,3 @@ check_save_path_fs()
perror_exit "Dump path $_path does not exist."
fi
}
-
diff --git a/kexec-tools.spec b/kexec-tools.spec
index c4db536..5aa919c 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -27,6 +27,7 @@ Source20: kdump-lib.sh
Source21: kdump-in-cluster-environment.txt
Source22: kdump-dep-generator.sh
Source23: kdump-anaconda-addon-20140522.tar.gz
+Source24: kdump-lib-initramfs.sh
#######################################
# These are sources for mkdumpramfs
@@ -178,6 +179,7 @@ install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8
install -m 755 %{SOURCE11} $RPM_BUILD_ROOT%{_datadir}/kdump/firstboot_kdump.py
install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8
install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh
+install -m 755 %{SOURCE24} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh
%ifnarch s390x
# For s390x the ELF header is created in the kdump kernel and therefore kexec
# udev rules are not required
--
1.9.3
9 years, 9 months