kdump.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. ================================================================
  2. Documentation for Kdump - The kexec-based Crash Dumping Solution
  3. ================================================================
  4. This document includes overview, setup, installation, and analysis
  5. information.
  6. Overview
  7. ========
  8. Kdump uses kexec to quickly boot to a dump-capture kernel whenever a
  9. dump of the system kernel's memory needs to be taken (for example, when
  10. the system panics). The system kernel's memory image is preserved across
  11. the reboot and is accessible to the dump-capture kernel.
  12. You can use common commands, such as cp, scp or makedumpfile to copy
  13. the memory image to a dump file on the local disk, or across the network
  14. to a remote system.
  15. Kdump and kexec are currently supported on the x86, x86_64, ppc64,
  16. s390x, arm and arm64 architectures.
  17. When the system kernel boots, it reserves a small section of memory for
  18. the dump-capture kernel. This ensures that ongoing Direct Memory Access
  19. (DMA) from the system kernel does not corrupt the dump-capture kernel.
  20. The kexec -p command loads the dump-capture kernel into this reserved
  21. memory.
  22. On x86 machines, the first 640 KB of physical memory is needed for boot,
  23. regardless of where the kernel loads. For simpler handling, the whole
  24. low 1M is reserved to avoid any later kernel or device driver writing
  25. data into this area. Like this, the low 1M can be reused as system RAM
  26. by kdump kernel without extra handling.
  27. On PPC64 machines first 32KB of physical memory is needed for booting
  28. regardless of where the kernel is loaded and to support 64K page size
  29. kexec backs up the first 64KB memory.
  30. For s390x, when kdump is triggered, the crashkernel region is exchanged
  31. with the region [0, crashkernel region size] and then the kdump kernel
  32. runs in [0, crashkernel region size]. Therefore no relocatable kernel is
  33. needed for s390x.
  34. All of the necessary information about the system kernel's core image is
  35. encoded in the ELF format, and stored in a reserved area of memory
  36. before a crash. The physical address of the start of the ELF header is
  37. passed to the dump-capture kernel through the elfcorehdr= boot
  38. parameter. Optionally the size of the ELF header can also be passed
  39. when using the elfcorehdr=[size[KMG]@]offset[KMG] syntax.
  40. With the dump-capture kernel, you can access the memory image through
  41. /proc/vmcore. This exports the dump as an ELF-format file that you can
  42. write out using file copy commands such as cp or scp. You can also use
  43. makedumpfile utility to analyze and write out filtered contents with
  44. options, e.g with '-d 31' it will only write out kernel data. Further,
  45. you can use analysis tools such as the GNU Debugger (GDB) and the Crash
  46. tool to debug the dump file. This method ensures that the dump pages are
  47. correctly ordered.
  48. Setup and Installation
  49. ======================
  50. Install kexec-tools
  51. -------------------
  52. 1) Login as the root user.
  53. 2) Download the kexec-tools user-space package from the following URL:
  54. http://kernel.org/pub/linux/utils/kernel/kexec/kexec-tools.tar.gz
  55. This is a symlink to the latest version.
  56. The latest kexec-tools git tree is available at:
  57. - git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
  58. - http://www.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
  59. There is also a gitweb interface available at
  60. http://www.kernel.org/git/?p=utils/kernel/kexec/kexec-tools.git
  61. More information about kexec-tools can be found at
  62. http://horms.net/projects/kexec/
  63. 3) Unpack the tarball with the tar command, as follows::
  64. tar xvpzf kexec-tools.tar.gz
  65. 4) Change to the kexec-tools directory, as follows::
  66. cd kexec-tools-VERSION
  67. 5) Configure the package, as follows::
  68. ./configure
  69. 6) Compile the package, as follows::
  70. make
  71. 7) Install the package, as follows::
  72. make install
  73. Build the system and dump-capture kernels
  74. -----------------------------------------
  75. There are two possible methods of using Kdump.
  76. 1) Build a separate custom dump-capture kernel for capturing the
  77. kernel core dump.
  78. 2) Or use the system kernel binary itself as dump-capture kernel and there is
  79. no need to build a separate dump-capture kernel. This is possible
  80. only with the architectures which support a relocatable kernel. As
  81. of today, i386, x86_64, ppc64, arm and arm64 architectures support
  82. relocatable kernel.
  83. Building a relocatable kernel is advantageous from the point of view that
  84. one does not have to build a second kernel for capturing the dump. But
  85. at the same time one might want to build a custom dump capture kernel
  86. suitable to his needs.
  87. Following are the configuration setting required for system and
  88. dump-capture kernels for enabling kdump support.
  89. System kernel config options
  90. ----------------------------
  91. 1) Enable "kexec system call" or "kexec file based system call" in
  92. "Processor type and features."::
  93. CONFIG_KEXEC=y or CONFIG_KEXEC_FILE=y
  94. And both of them will select KEXEC_CORE::
  95. CONFIG_KEXEC_CORE=y
  96. 2) Enable "sysfs file system support" in "Filesystem" -> "Pseudo
  97. filesystems." This is usually enabled by default::
  98. CONFIG_SYSFS=y
  99. Note that "sysfs file system support" might not appear in the "Pseudo
  100. filesystems" menu if "Configure standard kernel features (expert users)"
  101. is not enabled in "General Setup." In this case, check the .config file
  102. itself to ensure that sysfs is turned on, as follows::
  103. grep 'CONFIG_SYSFS' .config
  104. 3) Enable "Compile the kernel with debug info" in "Kernel hacking."::
  105. CONFIG_DEBUG_INFO=Y
  106. This causes the kernel to be built with debug symbols. The dump
  107. analysis tools require a vmlinux with debug symbols in order to read
  108. and analyze a dump file.
  109. Dump-capture kernel config options (Arch Independent)
  110. -----------------------------------------------------
  111. 1) Enable "kernel crash dumps" support under "Processor type and
  112. features"::
  113. CONFIG_CRASH_DUMP=y
  114. And this will select VMCORE_INFO and CRASH_RESERVE::
  115. CONFIG_VMCORE_INFO=y
  116. CONFIG_CRASH_RESERVE=y
  117. 2) Enable "/proc/vmcore support" under "Filesystems" -> "Pseudo filesystems"::
  118. CONFIG_PROC_VMCORE=y
  119. (CONFIG_PROC_VMCORE is set by default when CONFIG_CRASH_DUMP is selected.)
  120. Dump-capture kernel config options (Arch Dependent, i386 and x86_64)
  121. --------------------------------------------------------------------
  122. 1) On i386, enable high memory support under "Processor type and
  123. features"::
  124. CONFIG_HIGHMEM64G=y
  125. or::
  126. CONFIG_HIGHMEM4G
  127. 2) With CONFIG_SMP=y, usually nr_cpus=1 need specified on the kernel
  128. command line when loading the dump-capture kernel because one
  129. CPU is enough for kdump kernel to dump vmcore on most of systems.
  130. However, you can also specify nr_cpus=X to enable multiple processors
  131. in kdump kernel.
  132. With CONFIG_SMP=n, the above things are not related.
  133. 3) A relocatable kernel is suggested to be built by default. If not yet,
  134. enable "Build a relocatable kernel" support under "Processor type and
  135. features"::
  136. CONFIG_RELOCATABLE=y
  137. 4) Use a suitable value for "Physical address where the kernel is
  138. loaded" (under "Processor type and features"). This only appears when
  139. "kernel crash dumps" is enabled. A suitable value depends upon
  140. whether kernel is relocatable or not.
  141. If you are using a relocatable kernel use CONFIG_PHYSICAL_START=0x100000
  142. This will compile the kernel for physical address 1MB, but given the fact
  143. kernel is relocatable, it can be run from any physical address hence
  144. kexec boot loader will load it in memory region reserved for dump-capture
  145. kernel.
  146. Otherwise it should be the start of memory region reserved for
  147. second kernel using boot parameter "crashkernel=Y@X". Here X is
  148. start of memory region reserved for dump-capture kernel.
  149. Generally X is 16MB (0x1000000). So you can set
  150. CONFIG_PHYSICAL_START=0x1000000
  151. 5) Make and install the kernel and its modules. DO NOT add this kernel
  152. to the boot loader configuration files.
  153. Dump-capture kernel config options (Arch Dependent, ppc64)
  154. ----------------------------------------------------------
  155. 1) Enable "Build a kdump crash kernel" support under "Kernel" options::
  156. CONFIG_CRASH_DUMP=y
  157. 2) Enable "Build a relocatable kernel" support::
  158. CONFIG_RELOCATABLE=y
  159. Make and install the kernel and its modules.
  160. Dump-capture kernel config options (Arch Dependent, arm)
  161. ----------------------------------------------------------
  162. - To use a relocatable kernel,
  163. Enable "AUTO_ZRELADDR" support under "Boot" options::
  164. AUTO_ZRELADDR=y
  165. Dump-capture kernel config options (Arch Dependent, arm64)
  166. ----------------------------------------------------------
  167. - Please note that kvm of the dump-capture kernel will not be enabled
  168. on non-VHE systems even if it is configured. This is because the CPU
  169. will not be reset to EL2 on panic.
  170. crashkernel syntax
  171. ===========================
  172. 1) crashkernel=size@offset
  173. Here 'size' specifies how much memory to reserve for the dump-capture kernel
  174. and 'offset' specifies the beginning of this reserved memory. For example,
  175. "crashkernel=64M@16M" tells the system kernel to reserve 64 MB of memory
  176. starting at physical address 0x01000000 (16MB) for the dump-capture kernel.
  177. The crashkernel region can be automatically placed by the system
  178. kernel at run time. This is done by specifying the base address as 0,
  179. or omitting it all together::
  180. crashkernel=256M@0
  181. or::
  182. crashkernel=256M
  183. If the start address is specified, note that the start address of the
  184. kernel will be aligned to a value (which is Arch dependent), so if the
  185. start address is not then any space below the alignment point will be
  186. wasted.
  187. 2) range1:size1[,range2:size2,...][@offset]
  188. While the "crashkernel=size[@offset]" syntax is sufficient for most
  189. configurations, sometimes it's handy to have the reserved memory dependent
  190. on the value of System RAM -- that's mostly for distributors that pre-setup
  191. the kernel command line to avoid a unbootable system after some memory has
  192. been removed from the machine.
  193. The syntax is::
  194. crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]
  195. range=start-[end]
  196. For example::
  197. crashkernel=512M-2G:64M,2G-:128M
  198. This would mean:
  199. 1) if the RAM is smaller than 512M, then don't reserve anything
  200. (this is the "rescue" case)
  201. 2) if the RAM size is between 512M and 2G (exclusive), then reserve 64M
  202. 3) if the RAM size is larger than 2G, then reserve 128M
  203. 3) crashkernel=size,high and crashkernel=size,low
  204. If memory above 4G is preferred, crashkernel=size,high can be used to
  205. fulfill that. With it, physical memory is allowed to be allocated from top,
  206. so could be above 4G if system has more than 4G RAM installed. Otherwise,
  207. memory region will be allocated below 4G if available.
  208. When crashkernel=X,high is passed, kernel could allocate physical memory
  209. region above 4G, low memory under 4G is needed in this case. There are
  210. three ways to get low memory:
  211. 1) Kernel will allocate at least 256M memory below 4G automatically
  212. if crashkernel=Y,low is not specified.
  213. 2) Let user specify low memory size instead.
  214. 3) Specified value 0 will disable low memory allocation::
  215. crashkernel=0,low
  216. Boot into System Kernel
  217. -----------------------
  218. 1) Update the boot loader (such as grub, yaboot, or lilo) configuration
  219. files as necessary.
  220. 2) Boot the system kernel with the boot parameter "crashkernel=Y@X".
  221. On x86 and x86_64, use "crashkernel=Y[@X]". Most of the time, the
  222. start address 'X' is not necessary, kernel will search a suitable
  223. area. Unless an explicit start address is expected.
  224. On ppc64, use "crashkernel=128M@32M".
  225. On s390x, typically use "crashkernel=xxM". The value of xx is dependent
  226. on the memory consumption of the kdump system. In general this is not
  227. dependent on the memory size of the production system.
  228. On arm, the use of "crashkernel=Y@X" is no longer necessary; the
  229. kernel will automatically locate the crash kernel image within the
  230. first 512MB of RAM if X is not given.
  231. On arm64, use "crashkernel=Y[@X]". Note that the start address of
  232. the kernel, X if explicitly specified, must be aligned to 2MiB (0x200000).
  233. Load the Dump-capture Kernel
  234. ============================
  235. After booting to the system kernel, dump-capture kernel needs to be
  236. loaded.
  237. Based on the architecture and type of image (relocatable or not), one
  238. can choose to load the uncompressed vmlinux or compressed bzImage/vmlinuz
  239. of dump-capture kernel. Following is the summary.
  240. For i386 and x86_64:
  241. - Use bzImage/vmlinuz if kernel is relocatable.
  242. - Use vmlinux if kernel is not relocatable.
  243. For ppc64:
  244. - Use vmlinux
  245. For s390x:
  246. - Use image or bzImage
  247. For arm:
  248. - Use zImage
  249. For arm64:
  250. - Use vmlinux or Image
  251. If you are using an uncompressed vmlinux image then use following command
  252. to load dump-capture kernel::
  253. kexec -p <dump-capture-kernel-vmlinux-image> \
  254. --initrd=<initrd-for-dump-capture-kernel> --args-linux \
  255. --append="root=<root-dev> <arch-specific-options>"
  256. If you are using a compressed bzImage/vmlinuz, then use following command
  257. to load dump-capture kernel::
  258. kexec -p <dump-capture-kernel-bzImage> \
  259. --initrd=<initrd-for-dump-capture-kernel> \
  260. --append="root=<root-dev> <arch-specific-options>"
  261. If you are using a compressed zImage, then use following command
  262. to load dump-capture kernel::
  263. kexec --type zImage -p <dump-capture-kernel-bzImage> \
  264. --initrd=<initrd-for-dump-capture-kernel> \
  265. --dtb=<dtb-for-dump-capture-kernel> \
  266. --append="root=<root-dev> <arch-specific-options>"
  267. If you are using an uncompressed Image, then use following command
  268. to load dump-capture kernel::
  269. kexec -p <dump-capture-kernel-Image> \
  270. --initrd=<initrd-for-dump-capture-kernel> \
  271. --append="root=<root-dev> <arch-specific-options>"
  272. Following are the arch specific command line options to be used while
  273. loading dump-capture kernel.
  274. For i386 and x86_64:
  275. "1 irqpoll nr_cpus=1 reset_devices"
  276. For ppc64:
  277. "1 maxcpus=1 noirqdistrib reset_devices"
  278. For s390x:
  279. "1 nr_cpus=1 cgroup_disable=memory"
  280. For arm:
  281. "1 maxcpus=1 reset_devices"
  282. For arm64:
  283. "1 nr_cpus=1 reset_devices"
  284. Notes on loading the dump-capture kernel:
  285. * By default, the ELF headers are stored in ELF64 format to support
  286. systems with more than 4GB memory. On i386, kexec automatically checks if
  287. the physical RAM size exceeds the 4 GB limit and if not, uses ELF32.
  288. So, on non-PAE systems, ELF32 is always used.
  289. The --elf32-core-headers option can be used to force the generation of ELF32
  290. headers. This is necessary because GDB currently cannot open vmcore files
  291. with ELF64 headers on 32-bit systems.
  292. * The "irqpoll" boot parameter reduces driver initialization failures
  293. due to shared interrupts in the dump-capture kernel.
  294. * You must specify <root-dev> in the format corresponding to the root
  295. device name in the output of mount command.
  296. * Boot parameter "1" boots the dump-capture kernel into single-user
  297. mode without networking. If you want networking, use "3".
  298. * We generally don't have to bring up a SMP kernel just to capture the
  299. dump. Hence generally it is useful either to build a UP dump-capture
  300. kernel or specify maxcpus=1 option while loading dump-capture kernel.
  301. Note, though maxcpus always works, you had better replace it with
  302. nr_cpus to save memory if supported by the current ARCH, such as x86.
  303. * You should enable multi-cpu support in dump-capture kernel if you intend
  304. to use multi-thread programs with it, such as parallel dump feature of
  305. makedumpfile. Otherwise, the multi-thread program may have a great
  306. performance degradation. To enable multi-cpu support, you should bring up an
  307. SMP dump-capture kernel and specify maxcpus/nr_cpus options while loading it.
  308. * For s390x there are two kdump modes: If a ELF header is specified with
  309. the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
  310. is done on all other architectures. If no elfcorehdr= kernel parameter is
  311. specified, the s390x kdump kernel dynamically creates the header. The
  312. second mode has the advantage that for CPU and memory hotplug, kdump has
  313. not to be reloaded with kexec_load().
  314. * For s390x systems with many attached devices the "cio_ignore" kernel
  315. parameter should be used for the kdump kernel in order to prevent allocation
  316. of kernel memory for devices that are not relevant for kdump. The same
  317. applies to systems that use SCSI/FCP devices. In that case the
  318. "allow_lun_scan" zfcp module parameter should be set to zero before
  319. setting FCP devices online.
  320. Kernel Panic
  321. ============
  322. After successfully loading the dump-capture kernel as previously
  323. described, the system will reboot into the dump-capture kernel if a
  324. system crash is triggered. Trigger points are located in panic(),
  325. die(), die_nmi() and in the sysrq handler (ALT-SysRq-c).
  326. The following conditions will execute a crash trigger point:
  327. If a hard lockup is detected and "NMI watchdog" is configured, the system
  328. will boot into the dump-capture kernel ( die_nmi() ).
  329. If die() is called, and it happens to be a thread with pid 0 or 1, or die()
  330. is called inside interrupt context or die() is called and panic_on_oops is set,
  331. the system will boot into the dump-capture kernel.
  332. On powerpc systems when a soft-reset is generated, die() is called by all cpus
  333. and the system will boot into the dump-capture kernel.
  334. For testing purposes, you can trigger a crash by using "ALT-SysRq-c",
  335. "echo c > /proc/sysrq-trigger" or write a module to force the panic.
  336. Write Out the Dump File
  337. =======================
  338. After the dump-capture kernel is booted, write out the dump file with
  339. the following command::
  340. cp /proc/vmcore <dump-file>
  341. or use scp to write out the dump file between hosts on a network, e.g::
  342. scp /proc/vmcore remote_username@remote_ip:<dump-file>
  343. You can also use makedumpfile utility to write out the dump file
  344. with specified options to filter out unwanted contents, e.g::
  345. makedumpfile -l --message-level 1 -d 31 /proc/vmcore <dump-file>
  346. Analysis
  347. ========
  348. Before analyzing the dump image, you should reboot into a stable kernel.
  349. You can do limited analysis using GDB on the dump file copied out of
  350. /proc/vmcore. Use the debug vmlinux built with -g and run the following
  351. command::
  352. gdb vmlinux <dump-file>
  353. Stack trace for the task on processor 0, register display, and memory
  354. display work fine.
  355. Note: GDB cannot analyze core files generated in ELF64 format for x86.
  356. On systems with a maximum of 4GB of memory, you can generate
  357. ELF32-format headers using the --elf32-core-headers kernel option on the
  358. dump kernel.
  359. You can also use the Crash utility to analyze dump files in Kdump
  360. format. Crash is available at the following URL:
  361. https://github.com/crash-utility/crash
  362. Crash document can be found at:
  363. https://crash-utility.github.io/
  364. Trigger Kdump on WARN()
  365. =======================
  366. The kernel parameter, panic_on_warn, calls panic() in all WARN() paths. This
  367. will cause a kdump to occur at the panic() call. In cases where a user wants
  368. to specify this during runtime, /proc/sys/kernel/panic_on_warn can be set to 1
  369. to achieve the same behaviour.
  370. Trigger Kdump on add_taint()
  371. ============================
  372. The kernel parameter panic_on_taint facilitates a conditional call to panic()
  373. from within add_taint() whenever the value set in this bitmask matches with the
  374. bit flag being set by add_taint().
  375. This will cause a kdump to occur at the add_taint()->panic() call.
  376. Contact
  377. =======
  378. - kexec@lists.infradead.org
  379. GDB macros
  380. ==========
  381. .. include:: gdbmacros.txt
  382. :literal: