kdump.init 3.4 KB

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