10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモリーイメージをライブダンプで取得する手順

Posted at

トラブルシュートの際に運用中のLinux環境のOSを落とさずにメモリーダンプ取得する方法のご紹介です。

テスト環境:
Fedora 24(x86_64)
kernel-4.11.12-100.fc24
kernel-debuginfo, kernel-debuginfo-common がインストールされていること。
Memory と同じサイズのストレージの空容量があること。

#手順1: crashのソースを取得しコンパイル

$ git clone https://github.com/crash-utility/crash.git
$ cd crash
$ make lzo

#手順2: crashの拡張モジュールをコンパイル

$ make extentions

#手順3: crashのライブセッションを始める

# /path/to/crash 
crash 7.2.0++
Copyright (C) 2002-2017  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"...

WARNING: kernel relocated [320MB]: patching 87096 gdb minimal_symbol values

      KERNEL: /usr/lib/debug/lib/modules/4.11.12-100.fc24.x86_64/vmlinux
    DUMPFILE: /dev/crash
        CPUS: 4
        DATE: Fri Dec  5 23:03:15 2017
      UPTIME: 2 days, 13:22:44
LOAD AVERAGE: 0.88, 0.86, 0.84
       TASKS: 514
    NODENAME: abc12345
     RELEASE: 4.11.12-100.fc24.x86_64
     VERSION: #1 SMP Fri Jul 21 17:35:20 UTC 2017
     MACHINE: x86_64  (1696 Mhz)
      MEMORY: 11.9 GB
         PID: 8143
     COMMAND: "crash"
        TASK: ffff8c552d072580  [THREAD_INFO: ffff8c552d072580]
         CPU: 0
       STATE: TASK_RUNNING (ACTIVE)
crash> 

#手順4: 拡張モジュールのロード

crash> extend /path/to/crash/extensions/snap.so
/path/to/crash/extensions/snap.so: shared object loaded
crash>

#手順5: 使用方法の確認

 crash> help snap

 NAME
   snap - take a memory snapshot

SYNOPSIS
  snap [-n] dumpfile

DESCRIPTION
  This command takes a snapshot of physical memory and creates an ELF vmcore.
  The default vmcore is a kdump-style dumpfile.  Supported on x86, x86_64,
  ia64 and ppc64 architectures only.
 
    -n  create a netdump-style vmcore (n/a on x86_64).

#手順6: メモリーイメージをダンプする

crash> snap /path/to/vmcore 
/path/to/vmcore: [100%] 
-rw-r--r-- 1 root root 13956543232 12月  5 23:10 /path/to/vmcore
crash>

#手順7: ライブダンプで取得したメモリーイメージを開けることを確認する

# crash /boot/vmlinux-4.11.12-100.fc24 /path/to/vmcore 
<snip>
WARNING: kernel relocated [320MB]: patching 87096 gdb minimal_symbol values

      KERNEL: /boot/vmlinux-4.11.12-100.fc24                           
    DUMPFILE: /path/to/vmcore  [LIVE DUMP]
        CPUS: 4
        DATE: Fri Dec  5 23:10:55 2017
      UPTIME: 2 days, 13:30:28
      LOAD AVERAGE: 1.50, 0.97, 0.88
       TASKS: 509
    NODENAME: abc12345
     RELEASE: 4.11.12-100.fc24.x86_64
     VERSION: #1 SMP Fri Jul 21 17:35:20 UTC 2017
     MACHINE: x86_64  (1696 Mhz)
      MEMORY: 11.9 GB
       PANIC: ""
         PID: 8192
     COMMAND: "crash"
        TASK: ffff8c53aee98000  [THREAD_INFO: ffff8c53aee98000]
         CPU: 0
       STATE: TASK_RUNNING (ACTIVE)

注意事項:kdumpのように使用してないメモリーページを取らないとか、vmcoreを圧縮するといったことはできません。
ダンプ先の空き容量を確認した上で行ってください。 
ぜひ誤家庭のLinux server環境でお試しください。

10
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?