요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
설치와 커널 구성
kdump.rst:60-247kexec-tools 설치와 시스템·덤프 캡처 커널의 공통 및 아키텍처별 설정을 정리합니다.
메모리 예약
kdump.rst:248-358crashkernel의 고정·범위·high/low·CMA 문법과 부트 로더 설정을 설명합니다.
커널 적재
kdump.rst:359-487아키텍처별 이미지, kexec 명령줄과 ELF·CPU·장치 관련 주의 사항을 안내합니다.
수집과 분석
kdump.rst:488-570크래시 유발 조건, vmcore 저장, GDB·Crash 분석과 WARN·taint 트리거를 설명합니다.
암호화 볼륨
kdump.rst:571-612암호화 디스크의 키 보존·복원 절차와 연락처, GDB 매크로 포함 관계를 정리합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
================================================================
Documentation for Kdump - The kexec-based Crash Dumping Solution
================================================================
This document includes overview, setup, installation, and analysis
information.
Overview
========
Kdump uses kexec to quickly boot to a dump-capture kernel whenever a
dump of the system kernel's memory needs to be taken (for example, when
the system panics). The system kernel's memory image is preserved across
the reboot and is accessible to the dump-capture kernel.
You can use common commands, such as cp, scp or makedumpfile to copy
the memory image to a dump file on the local disk, or across the network
to a remote system.
Kdump and kexec are currently supported on the x86, x86_64, ppc64,
s390x, arm and arm64 architectures.
When the system kernel boots, it reserves a small section of memory for
the dump-capture kernel. This ensures that ongoing Direct Memory Access
(DMA) from the system kernel does not corrupt the dump-capture kernel.
The kexec -p command loads the dump-capture kernel into this reserved
memory.
On x86 machines, the first 640 KB of physical memory is needed for boot,
regardless of where the kernel loads. For simpler handling, the whole
low 1M is reserved to avoid any later kernel or device driver writing
data into this area. Like this, the low 1M can be reused as system RAM
by kdump kernel without extra handling.
On PPC64 machines first 32KB of physical memory is needed for booting
regardless of where the kernel is loaded and to support 64K page size
kexec backs up the first 64KB memory.
For s390x, when kdump is triggered, the crashkernel region is exchanged
with the region [0, crashkernel region size] and then the kdump kernel
runs in [0, crashkernel region size]. Therefore no relocatable kernel is
needed for s390x.
All of the necessary information about the system kernel's core image is
encoded in the ELF format, and stored in a reserved area of memory
before a crash. The physical address of the start of the ELF header is
passed to the dump-capture kernel through the elfcorehdr= boot
parameter. Optionally the size of the ELF header can also be passed
when using the elfcorehdr=[size[KMG]@]offset[KMG] syntax.
With the dump-capture kernel, you can access the memory image through
/proc/vmcore. This exports the dump as an ELF-format file that you can
write out using file copy commands such as cp or scp. You can also use
makedumpfile utility to analyze and write out filtered contents with
options, e.g with '-d 31' it will only write out kernel data. Further,
you can use analysis tools such as the GNU Debugger (GDB) and the Crash
tool to debug the dump file. This method ensures that the dump pages are
correctly ordered.
Setup and Installation
======================
Install kexec-tools
-------------------
1) Login as the root user.
2) Download the kexec-tools user-space package from the following URL:
http://kernel.org/pub/linux/utils/kernel/kexec/kexec-tools.tar.gz
This is a symlink to the latest version.
The latest kexec-tools git tree is available at:
- git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
- http://www.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
There is also a gitweb interface available at
http://www.kernel.org/git/?p=utils/kernel/kexec/kexec-tools.git
More information about kexec-tools can be found at
http://horms.net/projects/kexec/
3) Unpack the tarball with the tar command, as follows::
tar xvpzf kexec-tools.tar.gz
4) Change to the kexec-tools directory, as follows::
cd kexec-tools-VERSION
5) Configure the package, as follows::
./configure
6) Compile the package, as follows::
make
7) Install the package, as follows::
make install
Build the system and dump-capture kernels
-----------------------------------------
There are two possible methods of using Kdump.
1) Build a separate custom dump-capture kernel for capturing the
kernel core dump.
2) Or use the system kernel binary itself as dump-capture kernel and there is
no need to build a separate dump-capture kernel. This is possible
only with the architectures which support a relocatable kernel. As
of today, i386, x86_64, ppc64, arm and arm64 architectures support
relocatable kernel.
Building a relocatable kernel is advantageous from the point of view that
one does not have to build a second kernel for capturing the dump. But
at the same time one might want to build a custom dump capture kernel
suitable to his needs.
Following are the configuration setting required for system and
dump-capture kernels for enabling kdump support.
System kernel config options
----------------------------
1) Enable "kexec system call" or "kexec file based system call" in
"Processor type and features."::
CONFIG_KEXEC=y or CONFIG_KEXEC_FILE=y
And both of them will select KEXEC_CORE::
CONFIG_KEXEC_CORE=y
2) Enable "sysfs file system support" in "Filesystem" -> "Pseudo
filesystems." This is usually enabled by default::
CONFIG_SYSFS=y
Note that "sysfs file system support" might not appear in the "Pseudo
filesystems" menu if "Configure standard kernel features (expert users)"
is not enabled in "General Setup." In this case, check the .config file
itself to ensure that sysfs is turned on, as follows::
grep 'CONFIG_SYSFS' .config
3) Enable "Compile the kernel with debug info" in "Kernel hacking."::
CONFIG_DEBUG_INFO=Y
This causes the kernel to be built with debug symbols. The dump
analysis tools require a vmlinux with debug symbols in order to read
and analyze a dump file.
Dump-capture kernel config options (Arch Independent)
-----------------------------------------------------
1) Enable "kernel crash dumps" support under "Processor type and
features"::
CONFIG_CRASH_DUMP=y
And this will select VMCORE_INFO and CRASH_RESERVE::
CONFIG_VMCORE_INFO=y
CONFIG_CRASH_RESERVE=y
2) Enable "/proc/vmcore support" under "Filesystems" -> "Pseudo filesystems"::
CONFIG_PROC_VMCORE=y
(CONFIG_PROC_VMCORE is set by default when CONFIG_CRASH_DUMP is selected.)
Dump-capture kernel config options (Arch Dependent, i386 and x86_64)
--------------------------------------------------------------------
1) On i386, enable high memory support under "Processor type and
features"::
CONFIG_HIGHMEM4G
2) With CONFIG_SMP=y, usually nr_cpus=1 need specified on the kernel
command line when loading the dump-capture kernel because one
CPU is enough for kdump kernel to dump vmcore on most of systems.
However, you can also specify nr_cpus=X to enable multiple processors
in kdump kernel.
With CONFIG_SMP=n, the above things are not related.
3) A relocatable kernel is suggested to be built by default. If not yet,
enable "Build a relocatable kernel" support under "Processor type and
features"::
CONFIG_RELOCATABLE=y
4) Use a suitable value for "Physical address where the kernel is
loaded" (under "Processor type and features"). This only appears when
"kernel crash dumps" is enabled. A suitable value depends upon
whether kernel is relocatable or not.
If you are using a relocatable kernel use CONFIG_PHYSICAL_START=0x100000
This will compile the kernel for physical address 1MB, but given the fact
kernel is relocatable, it can be run from any physical address hence
kexec boot loader will load it in memory region reserved for dump-capture
kernel.
Otherwise it should be the start of memory region reserved for
second kernel using boot parameter "crashkernel=Y@X". Here X is
start of memory region reserved for dump-capture kernel.
Generally X is 16MB (0x1000000). So you can set
CONFIG_PHYSICAL_START=0x1000000
5) Make and install the kernel and its modules. DO NOT add this kernel
to the boot loader configuration files.
Dump-capture kernel config options (Arch Dependent, ppc64)
----------------------------------------------------------
1) Enable "Build a kdump crash kernel" support under "Kernel" options::
CONFIG_CRASH_DUMP=y
2) Enable "Build a relocatable kernel" support::
CONFIG_RELOCATABLE=y
Make and install the kernel and its modules.
Dump-capture kernel config options (Arch Dependent, arm)
----------------------------------------------------------
- To use a relocatable kernel,
Enable "AUTO_ZRELADDR" support under "Boot" options::
AUTO_ZRELADDR=y
Dump-capture kernel config options (Arch Dependent, arm64)
----------------------------------------------------------
- Please note that kvm of the dump-capture kernel will not be enabled
on non-VHE systems even if it is configured. This is because the CPU
will not be reset to EL2 on panic.
crashkernel syntax
===========================
1) crashkernel=size@offset
Here 'size' specifies how much memory to reserve for the dump-capture kernel
and 'offset' specifies the beginning of this reserved memory. For example,
"crashkernel=64M@16M" tells the system kernel to reserve 64 MB of memory
starting at physical address 0x01000000 (16MB) for the dump-capture kernel.
The crashkernel region can be automatically placed by the system
kernel at run time. This is done by specifying the base address as 0,
or omitting it all together::
crashkernel=256M@0
or::
crashkernel=256M
If the start address is specified, note that the start address of the
kernel will be aligned to a value (which is Arch dependent), so if the
start address is not then any space below the alignment point will be
wasted.
2) range1:size1[,range2:size2,...][@offset]
While the "crashkernel=size[@offset]" syntax is sufficient for most
configurations, sometimes it's handy to have the reserved memory dependent
on the value of System RAM -- that's mostly for distributors that pre-setup
the kernel command line to avoid a unbootable system after some memory has
been removed from the machine.
The syntax is::
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]
range=start-[end]
For example::
crashkernel=512M-2G:64M,2G-:128M
This would mean:
1) if the RAM is smaller than 512M, then don't reserve anything
(this is the "rescue" case)
2) if the RAM size is between 512M and 2G (exclusive), then reserve 64M
3) if the RAM size is larger than 2G, then reserve 128M
3) crashkernel=size,high and crashkernel=size,low
If memory above 4G is preferred, crashkernel=size,high can be used to
fulfill that. With it, physical memory is allowed to be allocated from top,
so could be above 4G if system has more than 4G RAM installed. Otherwise,
memory region will be allocated below 4G if available.
When crashkernel=X,high is passed, kernel could allocate physical memory
region above 4G, low memory under 4G is needed in this case. There are
three ways to get low memory:
1) Kernel will allocate at least 256M memory below 4G automatically
if crashkernel=Y,low is not specified.
2) Let user specify low memory size instead.
3) Specified value 0 will disable low memory allocation::
crashkernel=0,low
4) crashkernel=size,cma
Reserve additional crash kernel memory from CMA. This reservation is
usable by the first system's userspace memory and kernel movable
allocations (memory balloon, zswap). Pages allocated from this memory
range will not be included in the vmcore so this should not be used if
dumping of userspace memory is intended and it has to be expected that
some movable kernel pages may be missing from the dump.
A standard crashkernel reservation, as described above, is still needed
to hold the crash kernel and initrd.
This option increases the risk of a kdump failure: DMA transfers
configured by the first kernel may end up corrupting the second
kernel's memory.
This reservation method is intended for systems that can't afford to
sacrifice enough memory for standard crashkernel reservation and where
less reliable and possibly incomplete kdump is preferable to no kdump at
all.
Boot into System Kernel
-----------------------
1) Update the boot loader (such as grub, yaboot, or lilo) configuration
files as necessary.
2) Boot the system kernel with the boot parameter "crashkernel=Y@X".
On x86 and x86_64, use "crashkernel=Y[@X]". Most of the time, the
start address 'X' is not necessary, kernel will search a suitable
area. Unless an explicit start address is expected.
On ppc64, use "crashkernel=128M@32M".
On s390x, typically use "crashkernel=xxM". The value of xx is dependent
on the memory consumption of the kdump system. In general this is not
dependent on the memory size of the production system.
On arm, the use of "crashkernel=Y@X" is no longer necessary; the
kernel will automatically locate the crash kernel image within the
first 512MB of RAM if X is not given.
On arm64, use "crashkernel=Y[@X]". Note that the start address of
the kernel, X if explicitly specified, must be aligned to 2MiB (0x200000).
Load the Dump-capture Kernel
============================
After booting to the system kernel, dump-capture kernel needs to be
loaded.
Based on the architecture and type of image (relocatable or not), one
can choose to load the uncompressed vmlinux or compressed bzImage/vmlinuz
of dump-capture kernel. Following is the summary.
For i386 and x86_64:
- Use bzImage/vmlinuz if kernel is relocatable.
- Use vmlinux if kernel is not relocatable.
For ppc64:
- Use vmlinux
For s390x:
- Use image or bzImage
For arm:
- Use zImage
For arm64:
- Use vmlinux or Image
If you are using an uncompressed vmlinux image then use following command
to load dump-capture kernel::
kexec -p <dump-capture-kernel-vmlinux-image> \
--initrd=<initrd-for-dump-capture-kernel> --args-linux \
--append="root=<root-dev> <arch-specific-options>"
If you are using a compressed bzImage/vmlinuz, then use following command
to load dump-capture kernel::
kexec -p <dump-capture-kernel-bzImage> \
--initrd=<initrd-for-dump-capture-kernel> \
--append="root=<root-dev> <arch-specific-options>"
If you are using a compressed zImage, then use following command
to load dump-capture kernel::
kexec --type zImage -p <dump-capture-kernel-bzImage> \
--initrd=<initrd-for-dump-capture-kernel> \
--dtb=<dtb-for-dump-capture-kernel> \
--append="root=<root-dev> <arch-specific-options>"
If you are using an uncompressed Image, then use following command
to load dump-capture kernel::
kexec -p <dump-capture-kernel-Image> \
--initrd=<initrd-for-dump-capture-kernel> \
--append="root=<root-dev> <arch-specific-options>"
Following are the arch specific command line options to be used while
loading dump-capture kernel.
For i386 and x86_64:
"1 irqpoll nr_cpus=1 reset_devices"
For ppc64:
"1 maxcpus=1 noirqdistrib reset_devices"
For s390x:
"1 nr_cpus=1 cgroup_disable=memory"
For arm:
"1 maxcpus=1 reset_devices"
For arm64:
"1 nr_cpus=1 reset_devices"
Notes on loading the dump-capture kernel:
* By default, the ELF headers are stored in ELF64 format to support
systems with more than 4GB memory. On i386, kexec automatically checks if
the physical RAM size exceeds the 4 GB limit and if not, uses ELF32.
So, on non-PAE systems, ELF32 is always used.
The --elf32-core-headers option can be used to force the generation of ELF32
headers. This is necessary because GDB currently cannot open vmcore files
with ELF64 headers on 32-bit systems.
* The "irqpoll" boot parameter reduces driver initialization failures
due to shared interrupts in the dump-capture kernel.
* You must specify <root-dev> in the format corresponding to the root
device name in the output of mount command.
* Boot parameter "1" boots the dump-capture kernel into single-user
mode without networking. If you want networking, use "3".
* We generally don't have to bring up a SMP kernel just to capture the
dump. Hence generally it is useful either to build a UP dump-capture
kernel or specify maxcpus=1 option while loading dump-capture kernel.
Note, though maxcpus always works, you had better replace it with
nr_cpus to save memory if supported by the current ARCH, such as x86.
* You should enable multi-cpu support in dump-capture kernel if you intend
to use multi-thread programs with it, such as parallel dump feature of
makedumpfile. Otherwise, the multi-thread program may have a great
performance degradation. To enable multi-cpu support, you should bring up an
SMP dump-capture kernel and specify maxcpus/nr_cpus options while loading it.
* For s390x there are two kdump modes: If an ELF header is specified with
the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
is done on all other architectures. If no elfcorehdr= kernel parameter is
specified, the s390x kdump kernel dynamically creates the header. The
second mode has the advantage that for CPU and memory hotplug, kdump has
not to be reloaded with kexec_load().
* For s390x systems with many attached devices the "cio_ignore" kernel
parameter should be used for the kdump kernel in order to prevent allocation
of kernel memory for devices that are not relevant for kdump. The same
applies to systems that use SCSI/FCP devices. In that case the
"allow_lun_scan" zfcp module parameter should be set to zero before
setting FCP devices online.
Kernel Panic
============
After successfully loading the dump-capture kernel as previously
described, the system will reboot into the dump-capture kernel if a
system crash is triggered. Trigger points are located in panic(),
die(), die_nmi() and in the sysrq handler (ALT-SysRq-c).
The following conditions will execute a crash trigger point:
If a hard lockup is detected and "NMI watchdog" is configured, the system
will boot into the dump-capture kernel ( die_nmi() ).
If die() is called, and it happens to be a thread with pid 0 or 1, or die()
is called inside interrupt context or die() is called and panic_on_oops is set,
the system will boot into the dump-capture kernel.
On powerpc systems when a soft-reset is generated, die() is called by all cpus
and the system will boot into the dump-capture kernel.
For testing purposes, you can trigger a crash by using "ALT-SysRq-c",
"echo c > /proc/sysrq-trigger" or write a module to force the panic.
Write Out the Dump File
=======================
After the dump-capture kernel is booted, write out the dump file with
the following command::
cp /proc/vmcore <dump-file>
or use scp to write out the dump file between hosts on a network, e.g::
scp /proc/vmcore remote_username@remote_ip:<dump-file>
You can also use makedumpfile utility to write out the dump file
with specified options to filter out unwanted contents, e.g::
makedumpfile -l --message-level 1 -d 31 /proc/vmcore <dump-file>
Analysis
========
Before analyzing the dump image, you should reboot into a stable kernel.
You can do limited analysis using GDB on the dump file copied out of
/proc/vmcore. Use the debug vmlinux built with -g and run the following
command::
gdb vmlinux <dump-file>
Stack trace for the task on processor 0, register display, and memory
display work fine.
Note: GDB cannot analyze core files generated in ELF64 format for x86.
On systems with a maximum of 4GB of memory, you can generate
ELF32-format headers using the --elf32-core-headers kernel option on the
dump kernel.
You can also use the Crash utility to analyze dump files in Kdump
format. Crash is available at the following URL:
https://github.com/crash-utility/crash
Crash document can be found at:
https://crash-utility.github.io/
Trigger Kdump on WARN()
=======================
The kernel parameter, panic_on_warn, calls panic() in all WARN() paths. This
will cause a kdump to occur at the panic() call. In cases where a user wants
to specify this during runtime, /proc/sys/kernel/panic_on_warn can be set to 1
to achieve the same behaviour.
Trigger Kdump on add_taint()
============================
The kernel parameter panic_on_taint facilitates a conditional call to panic()
from within add_taint() whenever the value set in this bitmask matches with the
bit flag being set by add_taint().
This will cause a kdump to occur at the add_taint()->panic() call.
Write the dump file to encrypted disk volume
============================================
CONFIG_CRASH_DM_CRYPT can be enabled to support saving the dump file to an
encrypted disk volume (only x86_64 supported for now). User space can interact
with /sys/kernel/config/crash_dm_crypt_keys for setup,
1. Tell the first kernel what logon keys are needed to unlock the disk volumes,
# Add key #1
mkdir /sys/kernel/config/crash_dm_crypt_keys/7d26b7b4-e342-4d2d-b660-7426b0996720
# Add key #1's description
echo cryptsetup:7d26b7b4-e342-4d2d-b660-7426b0996720 > /sys/kernel/config/crash_dm_crypt_keys/description
# how many keys do we have now?
cat /sys/kernel/config/crash_dm_crypt_keys/count
1
# Add key #2 in the same way
# how many keys do we have now?
cat /sys/kernel/config/crash_dm_crypt_keys/count
2
# To support CPU/memory hot-plugging, re-use keys already saved to reserved
# memory
echo true > /sys/kernel/config/crash_dm_crypt_key/reuse
2. Load the dump-capture kernel
3. After the dump-capture kerne get booted, restore the keys to user keyring
echo yes > /sys/kernel/crash_dm_crypt_keys/restore
Contact
=======
- kexec@lists.infradead.org
GDB macros
==========
.. include:: gdbmacros.txt
:literal:
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Kdump 개요와 메모리 보존 방식
1-59Kdump: kexec 기반 크래시 덤프 솔루션
이 문서는 Kdump의 개요, 설정, 설치와 분석 정보를 제공합니다. Kdump는 시스템 커널의 메모리를 덤프해야 할 때, 예를 들어 시스템이 panic했을 때 `kexec`를 사용해 덤프 캡처 커널로 빠르게 부팅합니다. 재부팅하는 동안 시스템 커널의 메모리 이미지가 보존되며 덤프 캡처 커널에서 접근할 수 있습니다.
`cp`, `scp`, `makedumpfile` 같은 일반 명령으로 메모리 이미지를 로컬 디스크의 덤프 파일에 복사하거나 네트워크를 통해 원격 시스템으로 전송할 수 있습니다. Kdump와 kexec는 현재 x86, x86_64, ppc64, s390x, arm, arm64 아키텍처를 지원합니다.
시스템 커널은 부팅할 때 덤프 캡처 커널을 위한 작은 메모리 구간을 예약합니다. 이렇게 하면 시스템 커널에서 계속되는 DMA(Direct Memory Access)가 덤프 캡처 커널을 손상시키지 않습니다. `kexec -p` 명령은 이 예약 메모리에 덤프 캡처 커널을 적재합니다.
x86에서는 커널의 적재 위치와 관계없이 부팅에 물리 메모리의 첫 640 KB가 필요합니다. 처리를 단순하게 하고 이후 커널이나 장치 드라이버가 이 영역에 쓰는 일을 막기 위해 하위 1M 전체를 예약합니다. 그러면 Kdump 커널은 별도 처리 없이 하위 1M을 시스템 RAM으로 다시 사용할 수 있습니다.
PPC64에서는 커널 적재 위치와 관계없이 첫 32KB가 부팅에 필요하며, 64K 페이지 크기를 지원하기 위해 kexec가 첫 64KB 메모리를 백업합니다. s390x에서는 Kdump가 발동하면 crashkernel 영역을 `[0, crashkernel region size]` 구간과 교환하고 Kdump 커널이 그 구간에서 실행되므로 재배치 가능 커널이 필요하지 않습니다.
시스템 커널의 코어 이미지에 필요한 모든 정보는 ELF 형식으로 인코딩되어 크래시 전에 예약 메모리에 저장됩니다. ELF 헤더의 시작 물리 주소는 `elfcorehdr=` 부팅 매개변수로 덤프 캡처 커널에 전달합니다. `elfcorehdr=[size[KMG]@]offset[KMG]` 문법을 사용하면 ELF 헤더 크기도 선택적으로 전달할 수 있습니다.
덤프 캡처 커널에서는 `/proc/vmcore`를 통해 메모리 이미지에 접근합니다. 이 인터페이스는 덤프를 ELF 파일로 내보내므로 `cp`나 `scp`로 저장할 수 있습니다. `makedumpfile`은 내용을 분석하고 필터링해 저장할 수 있으며, 예를 들어 `-d 31`은 커널 데이터만 기록합니다. GNU Debugger(GDB)와 Crash 도구로 덤프 파일을 디버깅할 수도 있습니다. 이 방식은 덤프 페이지의 올바른 순서를 보장합니다.
kexec-tools 설치
60-105다음 순서로 `kexec-tools` 사용자 공간 패키지를 설치합니다.
1. `root` 사용자로 로그인합니다.
2. 아래 URL에서 패키지를 내려받습니다. tarball URL은 최신 버전을 가리키는 심볼릭 링크입니다. 최신 Git 트리, gitweb 인터페이스와 프로젝트 정보도 아래 링크에서 확인할 수 있습니다.
- 최신 kexec-tools tarball
http://kernel.org/pub/linux/utils/kernel/kexec/kexec-tools.tar.gz - kexec-tools Git(git 프로토콜)
git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git - kexec-tools Git(HTTP)
http://www.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git - kexec-tools gitweb
http://www.kernel.org/git/?p=utils/kernel/kexec/kexec-tools.git - kexec-tools 프로젝트 정보
http://horms.net/projects/kexec/
3. tarball의 압축을 풉니다.
tar xvpzf kexec-tools.tar.gz
4. `kexec-tools` 디렉터리로 이동합니다.
cd kexec-tools-VERSION
5. 패키지를 구성합니다.
./configure
6. 패키지를 컴파일합니다.
make
7. 패키지를 설치합니다.
make install
시스템 커널 빌드와 공통 설정
106-158Kdump를 사용하는 방법은 두 가지입니다. 코어 덤프 수집 전용 커널을 별도로 빌드하거나, 시스템 커널 바이너리 자체를 덤프 캡처 커널로 사용합니다. 후자는 재배치 가능 커널을 지원하는 아키텍처에서만 가능하며 i386, x86_64, ppc64, arm, arm64가 이에 해당합니다.
재배치 가능 커널은 두 번째 커널을 따로 빌드하지 않아도 된다는 장점이 있습니다. 반면 필요한 기능만 넣은 맞춤형 덤프 캡처 커널을 원하는 경우에는 별도 빌드가 적합합니다.
1. `Processor type and features`에서 `kexec system call` 또는 `kexec file based system call`을 활성화합니다.
CONFIG_KEXEC=y or CONFIG_KEXEC_FILE=y
두 옵션 모두 `KEXEC_CORE`를 선택합니다.
CONFIG_KEXEC_CORE=y
2. `Filesystem` → `Pseudo filesystems`에서 보통 기본 활성화되는 `sysfs file system support`를 켭니다.
CONFIG_SYSFS=y
`General Setup`의 `Configure standard kernel features (expert users)`가 꺼져 있으면 이 항목이 메뉴에 나타나지 않을 수 있습니다. 이 경우 `.config`를 직접 확인합니다.
grep 'CONFIG_SYSFS' .config
3. `Kernel hacking`에서 `Compile the kernel with debug info`를 활성화합니다. 디버그 심벌을 포함한 `vmlinux`는 덤프 분석 도구가 덤프 파일을 읽고 분석하는 데 필요합니다.
CONFIG_DEBUG_INFO=Y
덤프 캡처 커널 설정
159-219아키텍처 공통 설정으로 `Processor type and features`의 `kernel crash dumps`를 활성화합니다.
CONFIG_CRASH_DUMP=y
이 옵션은 `VMCORE_INFO`와 `CRASH_RESERVE`를 선택합니다.
CONFIG_VMCORE_INFO=y
CONFIG_CRASH_RESERVE=y
`Filesystems` → `Pseudo filesystems`에서 `/proc/vmcore support`를 활성화합니다. `CONFIG_CRASH_DUMP`를 선택하면 기본으로 설정됩니다.
CONFIG_PROC_VMCORE=y
i386에서는 `Processor type and features`의 high memory 지원을 활성화합니다.
CONFIG_HIGHMEM4G
`CONFIG_SMP=y`이면 대부분의 시스템에서 vmcore 덤프에 CPU 하나로 충분하므로 덤프 캡처 커널 명령줄에 보통 `nr_cpus=1`을 지정합니다. 여러 프로세서를 사용하려면 `nr_cpus=X`를 지정할 수 있습니다. `CONFIG_SMP=n`에는 해당하지 않습니다.
재배치 가능 커널을 기본으로 권장합니다. 아직 활성화하지 않았다면 `Processor type and features`에서 `Build a relocatable kernel`을 켭니다.
CONFIG_RELOCATABLE=y
`Physical address where the kernel is loaded` 값은 커널의 재배치 가능 여부에 맞춰 정합니다. 재배치 가능 커널은 물리 주소 1MB용으로 컴파일해도 kexec가 덤프 캡처 예약 영역 어디든 적재할 수 있습니다.
If you are using a relocatable kernel use CONFIG_PHYSICAL_START=0x100000
재배치할 수 없는 커널은 `crashkernel=Y@X`로 예약한 두 번째 커널 메모리의 시작 주소 X를 사용해야 합니다. X는 일반적으로 16MB(`0x1000000`)입니다.
CONFIG_PHYSICAL_START=0x1000000
마지막으로 커널과 모듈을 빌드해 설치합니다. 이 커널은 부트 로더 구성 파일에 추가하지 마십시오.
PPC64, arm과 arm64 설정
220-247PPC64에서는 `Kernel` 옵션의 `Build a kdump crash kernel`을 활성화합니다.
CONFIG_CRASH_DUMP=y
이어서 `Build a relocatable kernel`을 활성화하고 커널과 모듈을 빌드해 설치합니다.
CONFIG_RELOCATABLE=y
arm에서 재배치 가능 커널을 사용하려면 `Boot` 옵션의 `AUTO_ZRELADDR`을 활성화합니다.
AUTO_ZRELADDR=y
arm64의 non-VHE 시스템에서는 덤프 캡처 커널에 KVM을 구성했더라도 활성화되지 않습니다. panic 시 CPU가 EL2로 재설정되지 않기 때문입니다.
crashkernel=size@offset 문법
248-271`crashkernel=size@offset`에서 `size`는 덤프 캡처 커널을 위해 예약할 메모리 크기이고 `offset`은 예약 메모리의 시작입니다. 예를 들어 `crashkernel=64M@16M`은 물리 주소 `0x01000000`(16MB)부터 64 MB를 예약합니다.
기본 주소를 0으로 지정하거나 생략하면 시스템 커널이 런타임에 crashkernel 영역을 자동 배치합니다.
crashkernel=256M@0
crashkernel=256M
시작 주소를 명시하면 커널 시작 주소는 아키텍처별 정렬값에 맞춰집니다. 주소가 정렬되어 있지 않으면 다음 정렬 지점 아래의 공간은 낭비됩니다.
RAM 범위와 high/low 예약
272-313`crashkernel=size[@offset]`은 대부분의 구성에 충분하지만, 배포판처럼 시스템 RAM 크기에 따라 예약량을 정해야 할 때는 범위 문법을 사용합니다. 메모리 제거 뒤 부팅 불능 상태를 피하도록 미리 커널 명령줄을 구성할 때 특히 유용합니다.
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]
range=start-[end]
예시는 다음과 같습니다.
crashkernel=512M-2G:64M,2G-:128M
| 시스템 RAM | 예약량 |
|---|---|
| 512M 미만 | 아무것도 예약하지 않습니다. 복구(rescue) 경우입니다. |
| 512M 이상 2G 미만 | 64M을 예약합니다. |
| 2G 이상 | 128M을 예약합니다. |
4G 위 메모리를 우선 사용하려면 `crashkernel=size,high`를 지정합니다. 물리 메모리를 위쪽부터 할당할 수 있어 RAM이 4G보다 많으면 4G 위에 놓일 수 있습니다. 이 옵션이 없으면 가능한 경우 4G 아래에 할당합니다.
`crashkernel=X,high`로 4G 위에 영역을 배치하면 4G 아래의 저메모리도 필요합니다. `crashkernel=Y,low`를 생략하면 커널이 4G 아래에 최소 256M을 자동 할당하며, 사용자가 크기를 지정할 수도 있습니다. 0을 지정하면 저메모리 할당을 끕니다.
crashkernel=0,low
CMA 기반 추가 예약
314-334`crashkernel=size,cma`는 CMA에서 추가 crash kernel 메모리를 예약합니다. 첫 번째 시스템의 사용자 공간과 커널의 이동 가능한 할당(memory balloon, zswap)이 이 영역을 사용할 수 있습니다.
이 메모리 범위에서 할당된 페이지는 vmcore에 포함되지 않습니다. 사용자 공간 메모리를 덤프해야 할 때는 사용하지 않아야 하며, 이동 가능한 일부 커널 페이지가 덤프에서 빠질 수 있음을 예상해야 합니다. crash kernel과 initrd를 담기 위한 표준 crashkernel 예약도 별도로 필요합니다.
첫 번째 커널이 설정한 DMA 전송이 두 번째 커널의 메모리를 손상시킬 수 있으므로 Kdump 실패 위험도 커집니다. 충분한 표준 예약 메모리를 희생할 수 없고, 신뢰성이 낮거나 불완전하더라도 덤프가 전혀 없는 것보다는 나은 시스템을 위한 방식입니다.
시스템 커널로 부팅
335-3581. 필요에 따라 grub, yaboot, lilo 같은 부트 로더 구성 파일을 갱신합니다.
2. 시스템 커널을 `crashkernel=Y@X` 부팅 매개변수와 함께 시작합니다. x86과 x86_64에서는 `crashkernel=Y[@X]`를 사용하며, 명시적인 시작 주소가 꼭 필요한 경우가 아니면 커널이 적절한 영역을 찾으므로 X를 보통 생략합니다.
| 아키텍처 | 권장 형식과 제약 |
|---|---|
| ppc64 | `crashkernel=128M@32M` |
| s390x | 일반적으로 `crashkernel=xxM`을 사용합니다. xx는 운영 시스템 RAM 크기보다 Kdump 시스템의 메모리 소비량에 따라 정합니다. |
| arm | X를 생략하면 커널이 RAM의 첫 512MB 안에서 crash kernel 이미지를 자동 배치하므로 `crashkernel=Y@X`가 더는 필수가 아닙니다. |
| arm64 | `crashkernel=Y[@X]`를 사용합니다. X를 명시할 경우 2MiB(`0x200000`)에 맞춰 정렬해야 합니다. |
덤프 캡처 커널 적재
359-440시스템 커널로 부팅한 뒤 덤프 캡처 커널을 적재합니다. 아키텍처와 이미지의 재배치 가능 여부에 따라 압축하지 않은 `vmlinux` 또는 압축한 `bzImage`·`vmlinuz`를 선택합니다.
| 아키텍처 | 이미지 |
|---|---|
| i386, x86_64 | 재배치 가능 커널은 `bzImage`/`vmlinuz`, 그렇지 않으면 `vmlinux` |
| ppc64 | `vmlinux` |
| s390x | `image` 또는 `bzImage` |
| arm | `zImage` |
| arm64 | `vmlinux` 또는 `Image` |
압축하지 않은 `vmlinux` 이미지는 다음과 같이 적재합니다.
kexec -p <dump-capture-kernel-vmlinux-image> \
--initrd=<initrd-for-dump-capture-kernel> --args-linux \
--append="root=<root-dev> <arch-specific-options>"
압축한 `bzImage` 또는 `vmlinuz`는 다음과 같이 적재합니다.
kexec -p <dump-capture-kernel-bzImage> \
--initrd=<initrd-for-dump-capture-kernel> \
--append="root=<root-dev> <arch-specific-options>"
압축한 `zImage`는 다음과 같이 적재합니다.
kexec --type zImage -p <dump-capture-kernel-bzImage> \
--initrd=<initrd-for-dump-capture-kernel> \
--dtb=<dtb-for-dump-capture-kernel> \
--append="root=<root-dev> <arch-specific-options>"
압축하지 않은 `Image`는 다음과 같이 적재합니다.
kexec -p <dump-capture-kernel-Image> \
--initrd=<initrd-for-dump-capture-kernel> \
--append="root=<root-dev> <arch-specific-options>"
덤프 캡처 커널을 적재할 때 사용할 아키텍처별 명령줄 옵션은 다음과 같습니다.
| 아키텍처 | 명령줄 옵션 |
|---|---|
| i386, x86_64 | `1 irqpoll nr_cpus=1 reset_devices` |
| ppc64 | `1 maxcpus=1 noirqdistrib reset_devices` |
| s390x | `1 nr_cpus=1 cgroup_disable=memory` |
| arm | `1 maxcpus=1 reset_devices` |
| arm64 | `1 nr_cpus=1 reset_devices` |
"1 irqpoll nr_cpus=1 reset_devices"
"1 maxcpus=1 noirqdistrib reset_devices"
"1 nr_cpus=1 cgroup_disable=memory"
"1 maxcpus=1 reset_devices"
"1 nr_cpus=1 reset_devices"
적재 시 주의 사항
441-487기본적으로 4GB보다 큰 시스템을 지원하기 위해 ELF 헤더는 ELF64로 저장됩니다. i386의 kexec는 물리 RAM이 4GB를 넘는지 자동 확인하고, 넘지 않으면 ELF32를 사용합니다. 따라서 non-PAE 시스템은 항상 ELF32를 사용합니다.
`--elf32-core-headers`로 ELF32 헤더 생성을 강제할 수 있습니다. 현재 GDB가 32비트 시스템에서 ELF64 헤더의 vmcore를 열 수 없으므로 필요합니다.
`irqpoll` 부팅 매개변수는 덤프 캡처 커널의 공유 인터럽트 때문에 생기는 드라이버 초기화 실패를 줄입니다. `<root-dev>`는 `mount` 명령 출력의 루트 장치 이름과 같은 형식으로 지정해야 합니다.
부팅 매개변수 `1`은 네트워크 없이 단일 사용자 모드로 덤프 캡처 커널을 시작합니다. 네트워크가 필요하면 `3`을 사용합니다.
덤프 수집만을 위해 SMP 커널을 시작할 필요는 대개 없습니다. UP 덤프 캡처 커널을 빌드하거나 적재 시 `maxcpus=1`을 지정하는 것이 보통 유용합니다. `maxcpus`는 항상 동작하지만 x86처럼 현재 아키텍처가 지원한다면 메모리를 절약하도록 `nr_cpus`로 바꾸는 편이 낫습니다.
`makedumpfile`의 병렬 덤프처럼 다중 스레드 프로그램을 사용할 계획이라면 덤프 캡처 커널에서 다중 CPU 지원을 활성화해야 합니다. 그렇지 않으면 성능이 크게 저하될 수 있습니다. SMP 덤프 캡처 커널을 시작하고 적재할 때 `maxcpus`/`nr_cpus` 옵션을 지정합니다.
s390x에는 두 가지 Kdump 모드가 있습니다. `elfcorehdr=`를 지정하면 다른 아키텍처처럼 제공된 ELF 헤더를 사용합니다. 지정하지 않으면 s390x Kdump 커널이 헤더를 동적으로 만듭니다. 후자는 CPU나 메모리를 hotplug할 때 `kexec_load()`로 Kdump를 다시 적재하지 않아도 되는 장점이 있습니다.
장치가 많이 연결된 s390x에서는 Kdump와 무관한 장치에 커널 메모리를 할당하지 않도록 Kdump 커널에 `cio_ignore` 매개변수를 사용해야 합니다. SCSI/FCP 장치를 쓰는 시스템도 마찬가지이며, 이 경우 FCP 장치를 온라인으로 전환하기 전에 zfcp 모듈의 `allow_lun_scan`을 0으로 설정해야 합니다.
크래시 유발과 덤프 커널 재부팅
488-510덤프 캡처 커널을 성공적으로 적재한 뒤 시스템 크래시가 발생하면 시스템이 그 커널로 재부팅됩니다. 트리거 지점은 `panic()`, `die()`, `die_nmi()`와 sysrq 처리기(`ALT-SysRq-c`)에 있습니다.
NMI watchdog이 구성된 상태에서 hard lockup을 탐지하면 `die_nmi()`를 통해 덤프 캡처 커널로 부팅합니다. `die()`가 PID 0 또는 1인 스레드에서 호출되거나 인터럽트 문맥에서 호출되거나 `panic_on_oops`가 설정된 상태에서 호출되어도 같은 동작을 합니다.
powerpc에서 soft-reset을 생성하면 모든 CPU가 `die()`를 호출하고 덤프 캡처 커널로 부팅합니다. 테스트할 때는 `ALT-SysRq-c`, `echo c > /proc/sysrq-trigger` 또는 panic을 강제하는 모듈로 크래시를 유발할 수 있습니다.
덤프 파일 저장
511-527덤프 캡처 커널이 부팅된 뒤 다음 명령으로 덤프 파일을 저장합니다.
cp /proc/vmcore <dump-file>
네트워크의 다른 호스트로 저장하려면 `scp`를 사용할 수 있습니다.
scp /proc/vmcore remote_username@remote_ip:<dump-file>
`makedumpfile` 옵션으로 원하지 않는 내용을 필터링하면서 저장할 수도 있습니다.
makedumpfile -l --message-level 1 -d 31 /proc/vmcore <dump-file>
덤프 분석
528-554덤프 이미지를 분석하기 전에 안정적인 커널로 재부팅해야 합니다. `-g`로 빌드한 디버그용 `vmlinux`와 `/proc/vmcore`에서 복사한 덤프 파일을 사용하면 GDB로 제한적인 분석을 할 수 있습니다.
gdb vmlinux <dump-file>
프로세서 0에서 실행되던 태스크의 스택 추적, 레지스터와 메모리 표시는 정상 동작합니다.
GDB는 x86에서 ELF64 형식으로 생성된 코어 파일을 분석할 수 없습니다. 메모리가 최대 4GB인 시스템은 덤프 커널의 `--elf32-core-headers` 옵션으로 ELF32 헤더를 만들 수 있습니다.
Crash 유틸리티도 Kdump 형식의 덤프 파일을 분석할 수 있습니다.
WARN과 taint에서 Kdump 유발
555-570`panic_on_warn` 커널 매개변수는 모든 `WARN()` 경로에서 `panic()`을 호출하므로 그 지점에서 Kdump가 실행됩니다. 런타임에는 `/proc/sys/kernel/panic_on_warn`을 1로 설정해 같은 동작을 얻을 수 있습니다.
`panic_on_taint` 커널 매개변수는 설정한 비트마스크가 `add_taint()`가 설정하려는 비트 플래그와 일치할 때 `add_taint()` 내부에서 조건부로 `panic()`을 호출합니다. 따라서 `add_taint()->panic()` 지점에서 Kdump가 실행됩니다.
암호화 디스크 볼륨에 덤프 저장
571-602`CONFIG_CRASH_DM_CRYPT`를 활성화하면 암호화 디스크 볼륨에 덤프 파일을 저장할 수 있습니다. 현재는 x86_64만 지원합니다. 사용자 공간은 `/sys/kernel/config/crash_dm_crypt_keys`를 통해 설정합니다.
1. 첫 번째 커널에 디스크 볼륨 잠금을 해제하는 데 필요한 logon key를 알립니다. 아래 예시는 두 키를 추가하고 현재 키 수를 확인한 뒤, CPU·메모리 hotplug를 지원하도록 예약 메모리에 이미 저장된 키를 재사용하게 합니다.
# Add key #1
mkdir /sys/kernel/config/crash_dm_crypt_keys/7d26b7b4-e342-4d2d-b660-7426b0996720
# Add key #1's description
echo cryptsetup:7d26b7b4-e342-4d2d-b660-7426b0996720 > /sys/kernel/config/crash_dm_crypt_keys/description
# how many keys do we have now?
cat /sys/kernel/config/crash_dm_crypt_keys/count
1
# Add key #2 in the same way
# how many keys do we have now?
cat /sys/kernel/config/crash_dm_crypt_keys/count
2
# To support CPU/memory hot-plugging, re-use keys already saved to reserved
# memory
echo true > /sys/kernel/config/crash_dm_crypt_key/reuse
2. 덤프 캡처 커널을 적재합니다.
3. 덤프 캡처 커널이 부팅되면 다음 명령으로 키를 사용자 keyring에 복원합니다.
echo yes > /sys/kernel/crash_dm_crypt_keys/restore
연락처와 GDB 매크로
603-612Kdump 관련 연락처는 `kexec@lists.infradead.org`입니다.
문서 끝에는 `gdbmacros.txt`를 literal 형식으로 포함합니다. 해당 파일은 별도 페이지에서 원문 전체와 한국어 해설을 제공합니다.
.. include:: gdbmacros.txt
:literal:
동작 원리
kdump.rst:1-59kexec로 덤프 커널을 시작하고 예약 메모리와 ELF vmcore를 보존하는 흐름을 설명합니다.