summaryrefslogtreecommitdiffstats
path: root/import-layers/yocto-poky/meta/recipes-kernel/kexec/kexec-tools/kdump
blob: 2347205eda2271aa991ec569fc62395d0511f8d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#! /bin/sh
#
#  kdump
#
#  Description: The kdump script provides the support:
#		1. Load a kdump kernel image into memory;
#		2. Copy away vmcore when system panic.
#

#default
KEXEC=/usr/sbin/kexec
KEXEC_ARGS="-p"

MAKEDUMPFILE=/usr/bin/makedumpfile
MAKEDUMPFILE_ARGS="-E -d 1"

LOGGER="logger -p info -t kdump"

if [ -f /etc/sysconfig/kdump.conf ]; then
	. /etc/sysconfig/kdump.conf
else
	echo "no /etc/sysconfig/kdump.conf"
	exit 1;
fi

do_check()
{
	#check makedumpfile
	if [ ! -e ${MAKEDUMPFILE} -o ! -x ${MAKEDUMPFILE} ] ;then
		echo "No makedumpfile found."
		exit 0
	fi

	#check kexec
	if [ ! -e ${KEXEC} -o ! -x ${KEXEC} ] ;then
		echo "No kexec found."
		exit 0
	fi

	#check whether kdump kernel image exists on the system
	if [ -z "${KDUMP_KIMAGE}" -o ! -f "${KDUMP_KIMAGE}" ]; then
		echo "No kdump kernel image found."
		exit 0
	fi

	if [ "${KDUMP_CMDLINE}"x = "x" ] ; then
		echo "KDUMP_CMDLINE is not configured"
		exit 0
	fi
}

do_save_vmcore()
{
	if [ ${KDUMP_VMCORE_PATH}x = x ]; then
		KDUMP_VMCORE_PATH="/var/crash/`date +"%Y-%m-%d"`"
	fi

	mkdir -p ${KDUMP_VMCORE_PATH}
	echo "Saving a vmcore to ${KDUMP_VMCORE_PATH}."

	${MAKEDUMPFILE} ${MAKEDUMPFILE_ARGS} /proc/vmcore ${KDUMP_VMCORE_PATH}/vmcore-"`date +"%H:%M:%S"`"
#	cp --sparse=always /proc/vmcore ${KDUMP_VMCORE_PATH}/vmcore-"`date +"%H:%M:%S"`"
	rc=$?
	if [ ${rc} == 0 ]; then
		${LOGGER} "Saved a vmcore to ${KDUMP_VMCORE_PATH}."
	else
		${LOGGER} "Failed to save vmcore!"
	fi
	return ${rc}
}

do_start()
{
	#check file
	do_check

	#check whether the running kernel supports kdump.
	if [ ! -e /sys/kernel/kexec_crash_loaded ]; then
		echo "Kdump isn't supported on the running kernel!!!"
		${LOGGER} "Kdump isn't supported on the running kernel!!!"
		return 1
	fi

	#check whether kdump kernel image has been loaded
	rc=`cat /sys/kernel/kexec_crash_loaded`
	if [ ${rc} != 0 ]; then
		echo "Kdump is already running.";
		${LOGGER} "Kdump is already running."
		return 0
	fi

	#check the running kernel cmdline option,insure "crashkenrel=" always set.
	grep -q crashkernel= /proc/cmdline
	if [ $? != 0 ]; then
		echo "Kdump isn't supported on the running kernel,please check boot option!!!"
		${LOGGER} "Kdump isn't supported on the running kernel,please check boot option!!!"
		return 1
	fi

	#Load the kdump kernel image
	${KEXEC} ${KEXEC_ARGS} "${KDUMP_KIMAGE}" --append="${KDUMP_CMDLINE}"
	if [ $? != 0 ]; then
		echo "Failed to load kdump kernel!"
		${LOGGER} "Failed to load kdump kernel!"
		return 1
	fi

	echo "Kdump started up."
	${LOGGER} "Kdump started up."
}

do_stop()
{
	${KEXEC} -p -u 2>/dev/null
	if [ $? == 0 ]; then
		echo "Kdump has been stopped."
		${LOGGER} "Kdump has been stopped."
	else
		echo "Failed to stop kdump!"
		${LOGGER} "Failed to stop kdump!"
	fi
}

case "$1" in
  start)
	if [ -s /proc/vmcore ]; then
		do_save_vmcore
		reboot
	else
		do_start
	fi
	;;
 restart)
	do_stop
	do_start
	;;
  stop)
	do_stop
	;;
   *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?
OpenPOWER on IntegriCloud