kernelデバッグを有効にする
前提
- debian wheezy
- kernel panic になるため、解析したい
方法
kernelのデバッグ用パッケージやkdumpをインストール
$ uname -a Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux $ uname -r 3.2.0-4-amd64 $ sudo aptitude install kdump-config linux-image-$(uname -r)-dbg (snip)
kdumpのセットアップ
sudo vi /etc/default/kdump-tools
#USE_KDUMP=0 USE_KDUMP=1 (snip) # 圧縮を有効にし、corefileは現在使用しているページのみに限定する MAKEDUMP_ARGS="-c -d 31" (snip) # 4G以上のメモリを搭載する場合(x64)は次の設定が必要 #KDUMP_KEXEC_ARGS="" KDUMP_KEXEC_ARGS="--elf64-core-headers"
なお、ほかのkernelを使用したい等の場合は、KDUMP_KERNELやKDUMP_INITRDを設定すること。
ダンプの保存先はKDUMP_COREDIRに記載。(通常は/var/crash)
/usr/lib/debug/vmlinux-$(uname -r)
grubのセットアップ
sudo vi /etc/default/grub
#GRUB_CMDLINE_LINUX_DEFAULT="quiet" GRUB_CMDLINE_LINUX_DEFAULT="quiet crashkernel=64M" GRUB_CMDLINE_LINUX=""
設定などの反映
$ sudo update-grub (snip) $ sudo reboot (snip)
状態の確認
$ sudo service kdump-tools status
current state : ready to kdump
TODO
- ダンプを取得できたら、解析する...おそらくドライバ上で無限プールに陥っていて、戻ってきていない可能性が高い。
- rootfsが暗号化lvmの場合、ダンプ取得できず... (2014/04/21追記)
参考文献
- http://ym.fumizuki.net/tips/005/debian606_grub.shtml
- Gmane Loom
- 第26章 kdump クラッシュリカバリーサービス - Red Hat Customer Portal - コアダンプの解析等についてわかりやすい
- Linuxマシン突然再起動に関する備忘録 | OpenGroove - panic時の再起動設定
2014/04/21 kernelパラメータ を発見
high,lowとかのオプション表記を発見。これをつけたほうがいいのかな?まだ説明は読んでいない。
crashkernel=size[KMG][@offset[KMG]] [KNL] Using kexec, Linux can switch to a 'crash kernel' upon panic. This parameter reserves the physical memory region [offset, offset + size] for that kernel image. If '@offset' is omitted, then a suitable offset is selected automatically. Check Documentation/kdump/kdump.txt for further details. [KNL] kexecを使用すると、Linuxは「クラッシュカーネル」へ切り替わります。 このパラメータはそのクラッシュカーネルのイメージのために物理メモリ領域 [offset, offset + size]を割り当てます。@offsetが省略される場合、自動的 に適切なオフセットが選択されます。 crashkernel=range1:size1[,range2:size2,...][@offset] [KNL] Same as above, but depends on the memory in the running system. The syntax of range is start-[end] where start and end are both a memory unit (amount[KMG]). See also Documentation/kdump/kdump.txt for an example. crashkernel=size[KMG],high [KNL, x86_64] range could be above 4G. Allow kernel to allocate physical memory region from top, so could be above 4G if system have more than 4G ram installed. Otherwise memory region will be allocated below 4G, if available. It will be ignored if crashkernel=X is specified. crashkernel=size[KMG],low [KNL, x86_64] range under 4G. When crashkernel=X,high is passed, kernel could allocate physical memory region above 4G, that cause second kernel crash on system that require some amount of low memory, e.g. swiotlb requires at least 64M+32K low memory. Kernel would try to allocate 72M below 4G automatically. This one let user to specify own low range under 4G for second kernel instead. 0: to disable low allocation. It will be ignored when crashkernel=X,high is not used or memory reserved is below 4G.