kdump.init 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/bin/sh /etc/rc.common
  2. START=41
  3. STOP=90
  4. BOOT_IMAGE=/boot/vmlinuz
  5. EXTRA_COMMANDS="status"
  6. EXTRA_HELP=" status Print crashkernel status"
  7. verify_kdump() {
  8. local cfg="$1"
  9. local enabled
  10. local path
  11. local save_vmcore
  12. local save_dmesg
  13. config_get_bool enabled "$cfg" enabled 1
  14. config_get_bool save_dmesg "$cfg" save_dmesg 1
  15. config_get_bool save_vmcore "$cfg" save_vmcore 0
  16. [ "$enabled" -gt 0 ] || return 2
  17. [ "$save_dmesg" -gt 0 ] || [ "$save_vmcore" -gt 0 ] || return 2
  18. config_get path "$cfg" path "/"
  19. [ -d "$path" ] || mkdir -p "$path" 2>/dev/null || return 1
  20. }
  21. run_kdump() {
  22. local cfg="$1"
  23. local enabled
  24. local path
  25. local save_vmcore
  26. local save_dmesg
  27. config_get_bool enabled "$cfg" enabled 1
  28. [ "$enabled" -gt 0 ] || return
  29. config_get_bool save_dmesg "$cfg" save_dmesg 1
  30. config_get_bool save_vmcore "$cfg" save_vmcore 0
  31. config_get path "$cfg" path "/"
  32. timestamp=$(date "+%Y%m%dT%H%M%S")
  33. if [ "$save_vmcore" -eq 1 ]; then
  34. echo -n "Saving vmcore (this may take a while)..."
  35. # would like 'sparse' but busybox doesn't support it
  36. dd if=/proc/vmcore of="$path/vmcore-$timestamp" conv=fsync bs=1M
  37. echo " done"
  38. fi
  39. if [ "$save_dmesg" -eq 1 ]; then
  40. vmcore-dmesg /proc/vmcore > "$path/dmesg-$timestamp"
  41. fi
  42. sync
  43. reboot -f
  44. }
  45. find_kernel() {
  46. . /lib/functions.sh
  47. local kernel
  48. kernel="$BOOT_IMAGE"
  49. if [ -r "$kernel" ]; then
  50. echo $kernel
  51. return 0
  52. fi
  53. kernel="$(find_mtd_part kernel)"
  54. if [ -r "$kernel" ]; then
  55. echo $kernel
  56. return 0
  57. fi
  58. for voldir in /sys/class/ubi/ubi*_*; do
  59. [ ! -e "$voldir" ] && continue
  60. if [ "$(cat "${voldir}/name")" = "kernel" ]; then
  61. kernel="/dev/$(basename "$voldir")"
  62. echo $kernel
  63. return 0
  64. fi
  65. done
  66. return 1
  67. }
  68. load_crashkernel() {
  69. local append_cmdline
  70. local kernel
  71. kernel="$(find_kernel)"
  72. [ $? -gt 0 ] && return 1
  73. case "$(uname -m)" in
  74. i?86|x86_64)
  75. grep -q "crashkernel=" /proc/cmdline || return 1
  76. append_cmdline="1 irqpoll reset_devices maxcpus=1"
  77. ;;
  78. arm*)
  79. append_cmdline="1 maxcpus=1 reset_devices"
  80. ;;
  81. esac
  82. kexec -p "$kernel" --reuse-cmdline --append="$append_cmdline"
  83. return $?
  84. }
  85. start() {
  86. local retval
  87. if [ ! -e /sys/kernel/kexec_crash_loaded ]; then
  88. return 1
  89. fi
  90. if [ -e /proc/vmcore ]; then
  91. config_load kdump
  92. config_foreach run_kdump kdump
  93. else
  94. config_load kdump
  95. config_foreach verify_kdump kdump
  96. retval=$?
  97. [ $retval = 1 ] && return 1
  98. [ $retval = 0 ] && load_crashkernel
  99. return $?
  100. fi
  101. }
  102. stop() {
  103. [ "$(cat /sys/kernel/kexec_crash_loaded)" = "1" ] || return
  104. if [ -e "$BOOT_IMAGE" ]; then
  105. kexec -p -u "$BOOT_IMAGE"
  106. fi
  107. }
  108. status() {
  109. local retval kernel
  110. if [ ! -e /sys/kernel/kexec_crash_loaded ]; then
  111. echo "crashdump not supported by kernel"
  112. return
  113. fi
  114. if [ $(cat /sys/kernel/kexec_crash_size) -eq 0 ]; then
  115. echo "memory for crashdump kernel not reserved!"
  116. echo "check crashkernel= kernel cmdline parameter"
  117. echo "(a reboot is required after installing kdump)"
  118. return
  119. fi
  120. kernel="$(find_kernel)"
  121. if [ $? -gt 0 ]; then
  122. echo "cannot find kernel image"
  123. return
  124. else
  125. echo "using kernel image $kernel"
  126. fi
  127. echo -n "kdump configuration is "
  128. config_load kdump
  129. retval=$?
  130. if [ $retval = 0 ]; then
  131. if [ "$(config_foreach echo kdump)" ]; then
  132. config_foreach verify_kdump kdump
  133. retval=$?
  134. else
  135. retval=1
  136. fi
  137. fi
  138. if [ $retval = 0 ]; then
  139. echo "valid"
  140. elif [ $retval = 2 ]; then
  141. echo "disabled"
  142. else
  143. echo "BROKEN"
  144. fi
  145. echo -n "kexec crash kernel "
  146. if [ "$(cat /sys/kernel/kexec_crash_loaded)" = "0" ]; then
  147. echo -n "not "
  148. fi
  149. echo "loaded"
  150. }