fedoraでkdumpを使おうと思ったら設定に無駄に時間を喰ってしまったのでめも。どこにハマったかというとfedora 20のカーネルだったら問題なくダンプが取れたけど自前でビルドしたカーネルだと上手くいかなかったんですね。途中で止まるとかダンプが取れてないとかで。
設定としては以下の感じで実施
kexec-toolsパッケージをインストールしてkdumpを起動時に実行されるようにする(chkconfig kdump on)。
$ sudo systemctl enable kdump.service
そして/etc/defaults/grubを開いてカーネルのコマンドラインにcrashkernel=128Mを追加。
GRUB_CMDLINE_LINUX="vconsole.font=latarcyrheb-sun16 $([ -x /usr/sbin/rhcrashkernel-param ] && /usr/sbin/rhcrashkernel-param || :) vconsole.keymap=us rhgb quiet crashkernel=128M"
grub.confを書き換える。
$ sudo grub2-mkconfig -o /boot/grub2/grub.conf
書き換えたらリブートしてkdumpが有効になっているか確認
masami@linux-next:~$ cat /sys/kernel/kexec_crash_loaded 1 masami@linux-next:~$ systemctl status kdump.service kdump.service - Crash recovery kernel arming Loaded: loaded (/usr/lib/systemd/system/kdump.service; enabled) Active: active (exited) since Wed 2013-10-16 22:59:52 JST; 14min ago Process: 313 ExecStart=/usr/bin/kdumpctl start (code=exited, status=0/SUCCESS) Main PID: 313 (code=exited, status=0/SUCCESS) CGroup: /system.slice/kdump.service Oct 16 22:59:51 linux-next systemd[1]: Starting Crash recovery kernel arming... Oct 16 22:59:52 linux-next kdumpctl[313]: kexec: loaded kdump kernel Oct 16 22:59:52 linux-next kdumpctl[313]: Starting kdump: [OK] Oct 16 22:59:52 linux-next systemd[1]: Started Crash recovery kernel arming.
fedoraのカーネルだったら以下のようにsysrqの機能でクラッシュさせてダンプが取れます。
# echo c > /proc/sysrq-trigger
それで、自前ビルドの場合に何が問題だったかというとcrashカーネル用に確保するメモリの容量でした。。。128MiBだと足りてなかった模様。
挙動としてリブートするけどダンプが上手く取れていない、途中で止まるという感じで状況が一定していなかった上にkvmの画面が↓のスクリーンショットの用にダンプ取得用のカーネルが起動するまで画面表示が崩れてメッセージが読み辛いという状況で・・・
それでもなんとかメッセージが読めたときがあってメモリ不足でOOMキラーが動いているのが確認できた訳です。OOMキラーってことはメモリの量を128MBより増やせばいけるんじゃね?ということで256MBにしたら上手くいきました。これまでの苦労は何だったんだか(´・ω・`)
まあ、configの内容はほぼfedoraの設定と同じなのになぜ128MBで動かなかったのかは分かりませんが・・・
まあ、この過程で色々調べてたらFedora Core9のリリースノートに以下のような記述を見つけたのが良かったところですね。
x86 Kernel Includes Kdump Both the x86_64 and the i686 kernels are now relocatable, so they no longer require a separate kernel for kdump capability. PPC64 still requires a separate kdump kernel.
x86、x86_64のカーネルは再配置可能(CONFIG_RELOCATABLE=yですね)になっていればダンプ取得用のカーネルは作らなくてもOKということらしいです。
なので自分も作ってません。というか設定を弄ったのはカーネルのコマンドオプション位ですね。
ここからはさらにめも。
kdumpのsystemdの設定ファイル(/lib/systemd/system/kdump.service)は/usr/bin/kdumpctlで実際の処理を行っている。
Description=Crash recovery kernel arming After=network.target network-online.target remote-fs.target [Service] Type=oneshot ExecStart=/usr/bin/kdumpctl start ExecStop=/usr/bin/kdumpctl stop RemainAfterExit=yes [Install] WantedBy=multi-user.target
/usr/bin/kdumpctlは単なるシェルスクリプトでkdumpでダンプするための設定ファイルを呼んでkexecを実行するのが主要処理。
このファイルの冒頭部分を見ると設定ファイルが2個あるのが分かります。
#! /bin/sh KEXEC=/sbin/kexec KDUMP_KERNELVER="" KDUMP_COMMANDLINE="" KEXEC_ARGS="" KDUMP_CONFIG_FILE="/etc/kdump.conf" MKDUMPRD="/sbin/mkdumprd -f" SAVE_PATH=/var/crash SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" DUMP_TARGET="" . /lib/kdump/kdump-lib.sh standard_kexec_args="-p" if [ -f /etc/sysconfig/kdump ]; then . /etc/sysconfig/kdump fi
まずは/etc/kdump.confから見てみます。
長いので中略してますが、一番下の2行(pathとcore_collector)以外はコメントアウトされています。ダンプをリモートのサーバに送る場合は設定が必要ですね。
# Configures where to put the kdump /proc/vmcore files # # This file contains a series of commands to perform (in order) when a # kernel crash has happened and the kdump kernel has been loaded. Directives in # this file are only applicable to the kdump initramfs, and have no effect if # the root filesystem is mounted and the normal init scripts are processed # ~中略~ #force_rebuild 1 #dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3" path /var/crash core_collector makedumpfile -c -d 31
このファイルは冒頭にも書いてある通りダンプをどこに置くかというところがメインな設定でしょうか。
次に/etc/sysconfig/kdumpを。
# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump # If no version is specified, then the init script will try to find a # kdump kernel with the same version number as the running kernel. KDUMP_KERNELVER="" # The kdump commandline is the command line that needs to be passed off to # the kdump kernel. This will likely match the contents of the grub kernel # line. For example: # KDUMP_COMMANDLINE="ro root=LABEL=/" # Dracut depends on proper root= options, so please make sure that appropriate # root= options are copied from /proc/cmdline. In general it is best to append # command line options using "KDUMP_COMMANDLINE_APPEND=". # If a command line is not specified, the default will be taken from # /proc/cmdline KDUMP_COMMANDLINE="" # This variable lets us append arguments to the current kdump commandline # As taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory mce=off numa=off udev.children-max=2 panic=10 rootflags=nofail" # Any additional kexec arguments required. In most situations, this should # be left empty # # Example: # KEXEC_ARGS="--elf32-core-headers" KEXEC_ARGS="" #Where to find the boot image KDUMP_BOOTDIR="/boot" #What is the image type used for kdump KDUMP_IMG="vmlinuz" #What is the images extension. Relocatable kernels don't have one KDUMP_IMG_EXT=""
このファイルはkexecに渡す引数の設定ですが特に設定無しでOKです。
kdumpの使い方の説明をググるとダンプ取得用のカーネルはSMP無しでビルドするかmaxcpu=1を渡すなどの説明がありますけども、x86/x86_64でリロケータブルなカーネルならカーネルをわける必要がないのですがKDUMP_COMMANDLINE_APPENDのnr_cpus=1としているところでcpuコアを一つだけ使うようにしていますね。
ここで使っているオプションは/usr/share/doc/kexec-tools/kexec-kdump-howto.txtにあるやつよりも細かく設定しています。
設定を弄るとしたら通常は/etc/kdump.confでしょうね。/etc/sysconfig/kdumpはあまり弄る必要ないと思います。
というわけでkdumpのメモでした。