用sysrq-trigger实现ARM Linux一键内核崩溃、一键关机、一键dump信息等

sysrq有多种功能,对于ARM Linux这种嵌入式没键盘的系统来说,也可以通过/proc/sysrq-trigger来进行操作。

实验平台:QEMU模拟的ARM Linux

内核版本: 

# uname -a

Linux (none) 4.0.0-rc1+ #46 SMP Thu Nov 2 20:43:41 CST 2017 armv7l GNU/Linux

640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1

一键内核崩溃

# cd /proc/

# echo c > sysrq-trigger 

[  372.703889] sysrq: SysRq : Trigger a crash

[  372.705883] Unable to handle kernel NULL pointer dereference at virtual address 00000000

[  372.707831] pgd = 9ed5c000

[  372.708459] [00000000] *pgd=7f661831, *pte=00000000, *ppte=00000000

[  372.710189] Internal error: Oops: 817 [#1] SMP ARM

[  372.711290] Modules linked in:

[  372.712699] CPU: 0 PID: 705 Comm: sh Not tainted 4.0.0-rc1+ #46

[  372.715446] Hardware name: ARM-Versatile Express

[  372.722231] task: 9ec9b700 ti: 9ed5a000 task.ti: 9ed5a000

[  372.725480] PC is at sysrq_handle_crash+0x30/0x40

[  372.727546] LR is at sysrq_handle_crash+0x28/0x40

[  372.728286] pc : [<802903d8>]    lr : [<802903d0>]    psr: a0000013

[  372.728286] sp : 9ed5bf18  ip : 00000000  fp : 0016d22c

[  372.729548] r10: 76f55000  r9 : 9ed5a000  r8 : 00000007

[  372.729788] r7 : 00000000  r6 : 00000063  r5 : 80650494  r4 : 80658ea8

[  372.730066] r3 : 00000000  r2 : 00000001  r1 : 00000000  r0 : 00000063

[  372.730394] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user

[  372.730716] Control: 10c5387d  Table: 7ed5c06a  DAC: 00000015

[  372.730970] Process sh (pid: 705, stack limit = 0x9ed5a210)

[  372.731239] Stack: (0x9ed5bf18 to 0x9ed5c000)

[  372.731549] bf00:                                                       802903a8 80290ba4

[  372.731887] bf20: 00000002 00000001 00000000 00000000 9eff0d80 80290cb0 00000000 80122bd8

[  372.732299] bf40: 9f5f5000 00000002 76f55000 9ed5bf80 00000002 800da168 0016d22c 800240f0

[  372.732618] bf60: 00000003 00000000 00000000 9f5f5000 9f5f5000 00000002 76f55000 800da488

[  372.732954] bf80: 00000000 00000000 00000000 00000002 76f55000 00166cd8 00000004 8000e7a8

[  372.733286] bfa0: 00000000 8000e5e0 00000002 76f55000 00000001 76f55000 00000002 00000000

[  372.733592] bfc0: 00000002 76f55000 00166cd8 00000004 000c49ae 0016c4c0 00000002 0016d22c

[  372.733928] bfe0: 00000002 7eb2f8c0 000a2235 00008e7c 60000010 00000001 00000000 00000000

[  372.735094] [<802903d8>] (sysrq_handle_crash) from [<80290ba4>] (__handle_sysrq+0x90/0x164)

[  372.735580] [<80290ba4>] (__handle_sysrq) from [<80290cb0>] (write_sysrq_trigger+0x38/0x48)

[  372.736221] [<80290cb0>] (write_sysrq_trigger) from [<80122bd8>] (proc_reg_write+0x5c/0x84)

[  372.738252] [<80122bd8>] (proc_reg_write) from [<800da168>] (vfs_write+0xa0/0x1a8)

[  372.740445] [<800da168>] (vfs_write) from [<800da488>] (SyS_write+0x40/0x8c)

[  372.742670] [<800da488>] (SyS_write) from [<8000e5e0>] (ret_fast_syscall+0x0/0x40)

[  372.745287] Code: 0a000000 e12fff33 e3a03000 e3a02001 (e5c32000) 

[  372.748107] ---[ end trace 22610ffc8a0b80b3 ]---

[  372.749418] Kernel panic - not syncing: Fatal exception

[  372.751070] CPU1: stopping

[  372.752136] CPU: 1 PID: 0 Comm: swapper/1 Tainted: G      D         4.0.0-rc1+ #46

[  372.752457] Hardware name: ARM-Versatile Express

[  372.753464] [<80015790>] (unwind_backtrace) from [<80011a10>] (show_stack+0x10/0x14)

[  372.753854] [<80011a10>] (show_stack) from [<804842bc>] (dump_stack+0x74/0x90)

[  372.754240] [<804842bc>] (dump_stack) from [<80013b2c>] (handle_IPI+0x134/0x170)

[  372.754632] [<80013b2c>] (handle_IPI) from [<800086a4>] (gic_handle_irq+0x54/0x5c)

[  372.755039] [<800086a4>] (gic_handle_irq) from [<80012500>] (__irq_svc+0x40/0x54)

[  372.755458] Exception stack(0x9f487f90 to 0x9f487fd8)

[  372.755872] 7f80:                                     ffffffed 9f487fe0 ffffffed 8001c020

[  372.756322] 7fa0: 8064a454 00000000 00000000 80647540 80646c08 8064a4a8 00000000 8064a4a0

[  372.756753] 7fc0: 00000000 9f487fd8 8000f7d8 8000f7dc 60000013 ffffffff

[  372.757150] [<80012500>] (__irq_svc) from [<8000f7dc>] (arch_cpu_idle+0x30/0x3c)

[  372.757581] [<8000f7dc>] (arch_cpu_idle) from [<8004f0cc>] (cpu_startup_entry+0x1e4/0x2c4)

[  372.758187] [<8004f0cc>] (cpu_startup_entry) from [<60008744>] (0x60008744)

[  372.778966] CPU2: stopping

[  372.779266] CPU: 2 PID: 0 Comm: swapper/2 Tainted: G      D         4.0.0-rc1+ #46


0?wx_fmt=jpeg

一键导出内存管理信息

# echo m > sysrq-trigger 

[  137.476259] sysrq: SysRq : Show Memory

[  137.476530] Mem-info:

[  137.476768] Normal per-cpu:

[  137.476893] CPU    0: hi:  186, btch:  31 usd:  67

[  137.477034] CPU    1: hi:  186, btch:  31 usd: 155

[  137.477182] CPU    2: hi:  186, btch:  31 usd:  87

[  137.477422] CPU    3: hi:  186, btch:  31 usd:  56

[  137.477747] active_anon:16 inactive_anon:0 isolated_anon:0

[  137.477747]  active_file:308 inactive_file:53 isolated_file:0

[  137.477747]  unevictable:0 dirty:1 writeback:0 unstable:0

[  137.477747]  free:125418 slab_reclaimable:296 slab_unreclaimable:923

[  137.477747]  mapped:274 shmem:0 pagetables:7 bounce:0

[  137.477747]  free_cma:0

[  137.478878] Normal free:501672kB min:2864kB low:3580kB high:4296kB active_anon:64kB inactive_anon:0kB active_file:1232kB inactive_file:212kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:524288kB managed:513016kB mlocked:0kB dirty:4kB writeback:0kB mapped:1096kB shmem:0kB slab_reclaimable:1184kB slab_unreclaimable:3692kB kernel_stack:408kB pagetables:28kB unstable:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? no

[  137.479821] lowmem_reserve[]: 0 0

[  137.480035] Normal: 2*4kB (UE) 4*8kB (U) 2*16kB (UM) 1*32kB (M) 1*64kB (E) 0*128kB 1*256kB (U) 1*512kB (E) 3*1024kB (M) 3*2048kB (EM) 120*4096kB (MR) = 501672kB

[  137.480824] 362 total pagecache pages

[  137.480985] 0 pages in swap cache

[  137.481101] Swap cache stats: add 0, delete 0, find 0/0

[  137.481311] Free swap  = 0kB

[  137.481393] Total swap = 0kB

[  137.488594] 131072 pages of RAM

[  137.488882] 125849 free pages

[  137.489062] 2818 reserved pages

[  137.489319] 641 slab pages

[  137.489498] 517 pages shared

[  137.489717] 0 pages swap cached

0?wx_fmt=jpeg

终止除init外的所有进程

# echo e > sysrq-trigger 

[  104.903722] sysrq: SysRq : Terminate All Tasks


其他的功能还有很多很多,具体的列表:

0?wx_fmt=jpeg

其他功能

通过定位,可以调整模板整体大小和段前后距

 echo > sysrq-trigger 

[  271.111610] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) show-blocked-tasks(w) 




你可能感兴趣的:(用sysrq-trigger实现ARM Linux一键内核崩溃、一键关机、一键dump信息等)