Kdumpctl: provide cmds for exporting kdump
root@jkekc7-nfd01:/run/log/kdump# kdumpctl list
kcore-1
kcore-2
kcore-3
kdumpctl dump kcore-1 > /tmp/core.1
Google-Bug-Id: 307608081
Change-Id: I04384e8b31917f3030e9eb8efc749f5fd1ed4726
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
(cherry picked from commit e7d25bafc8d9a5c7745c4005053f959247e0873d)
diff --git a/recipes-google/kdump-core/files/kdumpctl b/recipes-google/kdump-core/files/kdumpctl
new file mode 100644
index 0000000..8cf400f
--- /dev/null
+++ b/recipes-google/kdump-core/files/kdumpctl
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+function usage(){
+ echo " kdumpctl list -- list existing kernel dump"
+ echo " kdumpctl dump <corefile> -- print specific kernel dump in raw"
+ exit 1
+}
+
+exec 2>/dev/null
+
+ram_dir='/run/log/kdump'
+emmc_dir='/mnt/luks-mmcblk0_fs/kdump'
+
+function list_core(){
+ ls -A1 $emmc_dir | grep 'kcore'
+ ls -A1 $ram_dir | grep 'kcore'
+}
+
+function dump_core(){
+ if [ -z "$1" ]; then
+ usage
+ fi
+
+ if ls $emmc_dir/$1 > /dev/null; then
+ cat $emmc_dir/$1
+ exit 0
+ fi
+
+ if ls $ram_dir/$1 > /dev/null; then
+ cat $ram_dir/$1
+ exit 0
+ fi
+
+ echo "core not found"
+ exit 1
+}
+
+if [ $1 == 'list' ]; then
+ list_core
+elif [ $1 == "dump" ]; then
+ dump_core $2
+else
+ usage
+fi
diff --git a/recipes-google/kdump-core/kdump-core.bb b/recipes-google/kdump-core/kdump-core.bb
index 78fd89a..97bfc5c 100644
--- a/recipes-google/kdump-core/kdump-core.bb
+++ b/recipes-google/kdump-core/kdump-core.bb
@@ -9,6 +9,7 @@
file://gbmc-kexec-prepare.service \
file://gbmc-kexec-prepare.sh \
file://gbmc-kexec-init.sh \
+ file://kdumpctl \
"
S = "${WORKDIR}"
@@ -35,4 +36,7 @@
install -d -m0755 ${D}${systemd_system_unitdir}/
install -m0644 gbmc-kexec-prepare.service ${D}${systemd_system_unitdir}/
+
+ install -d -m0755 ${D}${bindir}
+ install -m0755 ${WORKDIR}/kdumpctl ${D}${bindir}/
}