CentOS7でcrashコマンドの準備

CentOS7でcrashコマンドを実行し、ライブカーネルの状態を見られるようになるまでの準備（メモ）。

# パッケージのインストール

## crashコマンド

yumで普通に入る。

```
# yum install crash
Loaded plugins: fastestmirror
base                                                     | 3.6 kB     00:00
epel/x86_64/metalink                                     | 6.3 kB     00:00
epel                                                     | 4.4 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
epel/x86_64/primary_db                                     | 3.3 MB   00:00
(1/2): epel/x86_64/updateinfo                              |  35 kB   00:00
(2/2): epel/x86_64/pkgtags                                 | 1.3 MB   00:00
Loading mirror speeds from cached hostfile
 * base: mirrors.hust.edu.cn
 * epel: mirrors.yun-idc.com
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: mirrors.yun-idc.com
Resolving Dependencies
--> Running transaction check
---> Package crash.x86_64 0:7.0.2-7.el7_0.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package        Arch            Version                  Repository        Size
================================================================================
Installing:
 crash          x86_64          7.0.2-7.el7_0.1          updates          2.5 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 2.5 M
Installed size: 7.0 M
Is this ok [y/d/N]: y
Downloading packages:
crash-7.0.2-7.el7_0.1.x86_64.rpm                           | 2.5 MB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : crash-7.0.2-7.el7_0.1.x86_64                                 1/1
  Verifying  : crash-7.0.2-7.el7_0.1.x86_64                                 1/1

Installed:
  crash.x86_64 0:7.0.2-7.el7_0.1

Complete!
```


## kernel-debuginfo

カーネルのシンボル情報とか、vmlinuxとかのパッケージ。

CentOSの[debuginfoレポジトリ](http://wiki.centos.org/de/AdditionalResources/Repositories/)に入っている。

CentOS7では、レポジトリ定義は既に "/etc/yum.repos.d/CentOS-Base.repo" 内にあり、disableされているだけ。`--enablerepo`を渡して有効にしてあげる。

```
# yum install --enablerepo=base-debuginfo kernel-debuginfo-`uname -r`
Loaded plugins: fastestmirror
base-debuginfo                                           | 2.5 kB     00:00
base-debuginfo/x86_64/primary_db                           | 465 kB   00:01
Loading mirror speeds from cached hostfile
 * base: mirrors.hust.edu.cn
 * epel: mirrors.yun-idc.com
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: mirrors.yun-idc.com
======================== N/S matched: kernel-debuginfo =========================
kernel-debuginfo-common-x86_64.x86_64 : Kernel source files used by
                                      : kernel-debuginfo packages
kernel-debuginfo.x86_64 : Debug information for package kernel

  Name and summary matches only, use "search all" for everything.
[root@localhost yum.repos.d]# yum install --enablerepo=base-debuginfo kernel-deb
uginfo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.hust.edu.cn
 * epel: mirrors.yun-idc.com
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: mirrors.yun-idc.com
Resolving Dependencies
--> Running transaction check
---> Package kernel-debuginfo.x86_64 0:3.10.0-123.8.1.el7 will be installed
--> Processing Dependency: kernel-debuginfo-common-x86_64 = 3.10.0-123.8.1.el7 for package: kernel-debuginfo-3.10.0-123.8.1.el7.x86_64
--> Running transaction check
---> Package kernel-debuginfo-common-x86_64.x86_64 0:3.10.0-123.8.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                        Arch   Version             Repository      Size
================================================================================
Installing:
 kernel-debuginfo               x86_64 3.10.0-123.8.1.el7  base-debuginfo 247 M
Installing for dependencies:
 kernel-debuginfo-common-x86_64 x86_64 3.10.0-123.8.1.el7  base-debuginfo  39 M

Transaction Summary
================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 286 M
Installed size: 1.3 G
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base-debuginfo/packages/kernel-debuginfo-common-x86_64-3.10.0-123.8.1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID b6792c39: NOKEY
Public key for kernel-debuginfo-common-x86_64-3.10.0-123.8.1.el7.x86_64.rpm is not installed
(1/2): kernel-debuginfo-common-x86_64-3.10.0-123.8.1.el7.x |  39 MB   00:46
(2/2): kernel-debuginfo-3.10.0-123.8.1.el7.x86_64.rpm      | 247 MB   04:55
--------------------------------------------------------------------------------
Total                                              989 kB/s | 286 MB  04:55
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
Importing GPG key 0xB6792C39:
 Userid     : "CentOS-7 Debug (CentOS-7 Debuginfo RPMS) <security@centos.org>"
 Fingerprint: 759d 690f 6099 2d52 6a35 8cbd d0f2 5a3c b679 2c39
 Package    : centos-release-7-0.1406.el7.centos.2.5.x86_64 (@updates)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : kernel-debuginfo-common-x86_64-3.10.0-123.8.1.el7.x86_64     1/2
  Installing : kernel-debuginfo-3.10.0-123.8.1.el7.x86_64                   2/2
  Verifying  : kernel-debuginfo-common-x86_64-3.10.0-123.8.1.el7.x86_64     1/2
  Verifying  : kernel-debuginfo-3.10.0-123.8.1.el7.x86_64                   2/2

Installed:
  kernel-debuginfo.x86_64 0:3.10.0-123.8.1.el7

Dependency Installed:
  kernel-debuginfo-common-x86_64.x86_64 0:3.10.0-123.8.1.el7

Complete!
```

結構大きい。

```
Total download size: 286 M
Installed size: 1.3 G
```


# 起動してみる

実行中のカーネルバージョン（unamer -r）と、上でインストールした kernel-debuginfo のバージョンが一致していれば、引数不要。

```
# crash

crash 7.0.2-7.el7_0.1
Copyright (C) 2002-2013  Red Hat, Inc.
Copyright (C) 2004, 2005, 2006, 2010  IBM Corporation
Copyright (C) 1999-2006  Hewlett-Packard Co
Copyright (C) 2005, 2006, 2011, 2012  Fujitsu Limited
Copyright (C) 2006, 2007  VA Linux Systems Japan K.K.
Copyright (C) 2005, 2011  NEC Corporation
Copyright (C) 1999, 2002, 2007  Silicon Graphics, Inc.
Copyright (C) 1999, 2000, 2001, 2002  Mission Critical Linux, Inc.
This program is free software, covered by the GNU General Public License,
and you are welcome to change it and/or distribute copies of it under
certain conditions.  Enter "help copying" to see the conditions.
This program has absolutely no warranty.  Enter "help warranty" for details.

GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...

      KERNEL: /usr/lib/debug/lib/modules/3.10.0-123.8.1.el7.x86_64/vmlinux
    DUMPFILE: /dev/crash
        CPUS: 1
        DATE: Thu Oct  9 13:09:22 2014
      UPTIME: 16:55:43
LOAD AVERAGE: 0.16, 0.05, 0.06
       TASKS: 280
    NODENAME: localhost.localdomain
     RELEASE: 3.10.0-123.8.1.el7.x86_64
     VERSION: #1 SMP Mon Sep 22 19:06:58 UTC 2014
     MACHINE: x86_64  (3392 Mhz)
      MEMORY: 1 GB
         PID: 5644
     COMMAND: "crash"
        TASK: ffff88003af78b60  [THREAD_INFO: ffff88001382c000]
         CPU: 0
       STATE: TASK_RUNNING (ACTIVE)

crash> bt -t
PID: 5644   TASK: ffff88003af78b60  CPU: 0   COMMAND: "crash"
              START: __schedule at ffffffff815e75dd
  [ffff88001382df08] vfs_read at ffffffff811af54c
  [ffff88001382df38] sys_read at ffffffff811b0078
  [ffff88001382df80] system_call_fastpath at ffffffff815f2a59
    RIP: 00007fc7087d3850  RSP: 00007fffd0b45f00  RFLAGS: 00010246
    RAX: 0000000000000000  RBX: ffffffff815f2a59  RCX: 00000000000001f8
    RDX: 0000000000001000  RSI: 0000000000e84fc0  RDI: 0000000000000004
    RBP: 0000000000000004   R8: 000000001382d000   R9: 0000000000000002
    R10: 0000000000000001  R11: 0000000000000246  R12: 0000000000e84fc0
    R13: 0000000000e84fc0  R14: 0000000000001000  R15: 0000000000001000
    ORIG_RAX: 0000000000000000  CS: 0033  SS: 002b
crash> quit
```

## 参考リンク

crashコマンドの使い方など。

 - [Oracle® Linux管理者ガイド,リリース6 | 第10章 システムのダンプの分析 | 10.2 crashデバッガの使用](http://docs.oracle.com/cd/E39368_01/e48214/ch10s02.html)
 - [Crash | Anderson people.redhat.com](http://people.redhat.com/~anderson/) - Online Helpなど