linux dmesg命令详解?
linux dmesg命令参数及用法详解(linux显示开机信息命令)
功能说明:显示开机信息。
语 法:dmesg
补充说明:kernel会将开机信息存储在ring buffer中。您若是开机时来不及查看信息,可利用dmesg来查看。开机信息亦保存在/var/log目录中,名称为dmesg的文件里。
参 数:
-c 显示信息后,清除ring buffer中的内容。
-s<缓冲区大小> 预设置为8196,刚好等于ring buffer的大小。
-n 设置记录信息的层级。扩展阅读一:dmesg命令主要用途
主要应用:
dmesg用来显示内核环缓冲区(kernel-ring buffer)内容,内核将各种消息存放在这里。在系统引导时,内核将与硬件和模块初始化相关的信息填到这个缓冲区中。内核环缓冲区中的消息对于诊断系统问题 通常非常有用。在运行dmesg时,它显示大量信息。通常通过less或grep使用管道查看dmesg的输出,这样可以更容易找到待查信息。例如,如果发现硬盘性能低下,可以使用dmesg来检查它们是否运行在DMA模式:
$dmesg | grep DMA
…
ide0: BM-DMA at 0xf000-0xf007, BIOS settings: hda:DMA, hdb:DMA
ide1: BM-DMA at 0xf008-0xf00f, BIOS settings: hdc:DMA, hdd:DMA
…上面几行可以说明每个IDE设备正在什么模式下运行。如果以太网连接出现问题,那么可以在dmesg日志中搜索eth:
$dmesg | grep eth
forcedeth.c: Reverse Engineered nForce
ethernet driver. Version 0.49.
eth0: forcedeth.c: subsystem: 0147b:1c00
bound to 0000:00:04.0
eth0: no IPv6 routers present如果一切正常,那么dmesg显示每个网卡的硬件配置信息。如果某项系统服务未能得到正确的配置,dmesg日志很快就填满错误消息,这是诊断故障的良好起点。
还可以用来探测系统内核模块的加载情况,比如要检测ACPI的加载情况,使用dmesg | grep acpi
dmesg |egrep -i ”(apm|acpi)”
Kernel command line: vga=274 quiet console=ttyS3,9600acpi=no-idleoot=/dev/hda3
ACPI: Core Subsystem version
ACPI: Subsystem enabled
ACPI: System firmware supports: C2
ACPI: plvl2lat=99 plvl3lat=1001
ACPI: C2 enter=1417 C2 exit=354
ACPI: C3 enter=-1 C3 exit=-1
ACPI: Not using ACPI idle
ACPI: System firmware supports: S0 S1 S4 S5
扩展阅读二:dmesg命令使用示例
使用示例
示例一 将开机信息发邮件
man dmesg 写道
The program helps users to print out their bootup messages. Instead of copying the messages by hand, the user need only:
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their problem.
# dmesg >boot.messages
# ls -l boot.messages
-rw-r–r– 1 root root 15838 12-09 12 begin_of_the_skype_highlighting
15838 12-09 12 免费 end_of_the_skype_highlighting:55 boot.messages# mail -s “Boot Log of Linux Server” public@web3q.net <boot.messages
#示例二 浏览dmesg输出的信息
# uname -a
Linux new55 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:43 EDT 2010 i686 i686 i386 GNU/Linux# dmesg | less
Linux version 2.6.18-194.el5 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Tue Mar 16 21:52:43 EDT 2010
BIOS-provided physical RAM map:
BIOS-e820: 0000000000010000 – 000000000009fc00 (usable)
BIOS-e820: 000000000009fc00 – 00000000000a0000 (reserved)
BIOS-e820: 00000000000e0000 – 0000000000100000 (reserved)
BIOS-e820: 0000000000100000 – 000000001f7d0000 (usable)
BIOS-e820: 000000001f7d0000 – 000000001f7efc00 (reserved)
BIOS-e820: 000000001f7efc00 – 000000001f7fb000 (ACPI NVS)
BIOS-e820: 000000001f7fb000 – 000000001f800000 (reserved)
BIOS-e820: 00000000e0000000 – 00000000f0000000 (reserved)
BIOS-e820: 00000000fec00000 – 00000000fec02000 (reserved)
BIOS-e820: 00000000fed20000 – 00000000fed9b000 (reserved)
BIOS-e820: 00000000feda0000 – 00000000fedc0000 (reserved)
BIOS-e820: 00000000ffb00000 – 00000000ffc00000 (reserved)
BIOS-e820: 00000000fff00000 – 0000000100000000 (reserved)
0MB HIGHMEM available.
503MB LOWMEM available.
Memory for crash kernel (0x0 to 0x0) notwithin permissible range
disabling kdump
Using x86 segment limits to approximate NX protection
On node 0 totalpages: 128976
DMA zone: 4096 pages, LIFO batch:0
Normal zone: 124880 pages, LIFO batch:31
DMI 2.3 present.
Using APIC driver default
ACPI: RSDP (v000 HP ) @ 0x000fe270
ACPI: RSDT (v001 HP 30C4 0x31100620 HP 0x00000001) @ 0x1f7efc84
ACPI: FADT (v002 HP 30C4 0x00000002 HP 0x00000001) @ 0x1f7efc00
ACPI: MADT (v001 HP 30C4 0x00000001 HP 0x00000001) @ 0x1f7efcb8
ACPI: MCFG (v001 HP 30C4 0x00000001 HP 0x00000001) @ 0x1f7efd14
ACPI: SSDT (v001 HP HPQPpc 0x00001001 MSFT 0x0100000e) @ 0x1f7f6698
ACPI: DSDT (v001 HP DAU00 0x00010000 MSFT 0x0100000e) @ 0x00000000
ACPI: PM-Timer IO Port: 0x1008
ACPI: Local APIC address 0xfec01000
ACPI: LAPIC (acpi_id lapic_id enabled)
Processor #0 6:13 APIC version 20
ACPI: LAPIC_NMI (acpi_id high edge lint)
ACPI: IOAPIC (id address gsi_base)
IOAPIC: apic_id 1, version 32, address 0xfec00000, GSI 0-23
:
示例三 查看dmesg尾部的信息
# dmesg | tail
Bluetooth: L2CAP ver 2.8
Bluetooth: L2CAP socket layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM ver 1.8
Bluetooth: HIDP (Human Interface Emulation) ver 1.1
eth0: no IPv6 routers present
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
NFSD: Using /var/lib/nfs/v4recovery as the NFSv4 state recovery directory
NFSD: starting 90-second grace period
#
示例四 安装SS7卡驱动时的内核日志
# cd SS7HD_DRIVER/
# ls
bbdddlnx_iss.h bbd_hbi.h bbd_ioc.c bbd_isr.c bbd_pci.c BSD_license.txt GPL_V2-only_license.txt install_ss7hd.sh Makefile26
bbd_def.h bbd_hs.c bbd_ioc.h bbd_lnx.c bbd_pro.h build_ss7hd.sh i21555.h Makefile24
# ./build_ss7hd.sh
make: Entering directory `/usr/src/kernels/2.6.9-22.EL-i686′
CC /root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_hs.o
CC /root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_ioc.o
CC /root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_isr.o
CC /root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_pci.o
CC /root/setup/ss7dpklnx/SS7HD_DRIVER/bbd_lnx.o
LD /root/setup/ss7dpklnx/SS7HD_DRIVER/ss7hddvr26.o
Building modules, stage 2.
MODPOST
CC /root/setup/ss7dpklnx/SS7HD_DRIVER/ss7hddvr26.mod.o
LD /root/setup/ss7dpklnx/SS7HD_DRIVER/ss7hddvr26.ko
make: Leaving directory `/usr/src/kernels/2.6.9-22.EL-i686’http://www.linuxso.com/command/dmesg.html# ./install_ss7hd.sh
# lsmod | grep ss7
ss7hddvr26 25808 0
# dmesg | tail
ACPI: PCI interrupt 0000:02:0d.0 -> GSI 9 (level, low) -> IRQ 9
BBD 64bit
SS7HD – suspend
Dialogic SS7HD Device Driver V100.00 (Source V1.21)
Copyright (C) Dialogic Corporation 2003-2010. All Rights Reserved
Using major device number 251.
ACPI: PCI interrupt 0000:02:0d.0 -> GSI 9 (level, low) -> IRQ 9
BBD 64bit
# ./install_ss7hd.sh remove
# lsmod | grep ss7
# dmesg | tail
BBD 64bit
SS7HD – suspend
Dialogic SS7HD Device Driver V100.00 (Source V1.21)
Copyright (C) Dialogic Corporation 2003-2010. All Rights Reserved
Using major device number 251.
ACPI: PCI interrupt 0000:02:0d.0 -> GSI 9 (level, low) -> IRQ 9
BBD 64bit
SS7HD – suspend
#
示例五 打印并清除内核环形缓冲区
# dmesg -c
Linux version 2.6.18-194.el5 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Tue Mar 16 21:52:43 EDT 2010
BIOS-provided physical RAM map:
BIOS-e820: 0000000000010000 – 000000000009fc00 (usable)
BIOS-e820: 000000000009fc00 – 00000000000a0000 (reserved)
BIOS-e820: 00000000000e0000 – 0000000000100000 (reserved)
BIOS-e820: 0000000000100000 – 000000001f7d0000 (usable)
BIOS-e820: 000000001f7d0000 – 000000001f7efc00 (reserved)
BIOS-e820: 000000001f7efc00 – 000000001f7fb000 (ACPI NVS)
BIOS-e820: 000000001f7fb000 – 000000001f800000 (reserved)
BIOS-e820: 00000000e0000000 – 00000000f0000000 (reserved)
BIOS-e820: 00000000fec00000 – 00000000fec02000 (reserved)
BIOS-e820: 00000000fed20000 – 00000000fed9b000 (reserved)
BIOS-e820: 00000000feda0000 – 00000000fedc0000 (reserved)
BIOS-e820: 00000000ffb00000 – 00000000ffc00000 (reserved)
BIOS-e820: 00000000fff00000 – 0000000100000000 (reserved)
0MB HIGHMEM available.
503MB LOWMEM available.
Memory for crash kernel (0x0 to 0x0) notwithin permissible range
disabling kdump
Using x86 segment limits to approximate NX protection
On node 0 totalpages: 128976
DMA zone: 4096 pages, LIFO batch:0
Normal zone: 124880 pages, LIFO batch:31
DMI 2.3 present.省略输出
Bluetooth: HIDP (Human Interface Emulation) ver 1.1
eth0: no IPv6 routers present
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
NFSD: Using /var/lib/nfs/v4recovery as the NFSv4 state recovery directory
NFSD: starting 90-second grace period
# dmesg# less /var/log/dmesg
Linux version 2.6.18-194.el5 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Tue Mar 16 21:52:43 EDT 2010
BIOS-provided physical RAM map:
BIOS-e820: 0000000000010000 – 000000000009fc00 (usable)
BIOS-e820: 000000000009fc00 – 00000000000a0000 (reserved)
BIOS-e820: 00000000000e0000 – 0000000000100000 (reserved)
BIOS-e820: 0000000000100000 – 000000001f7d0000 (usable)
BIOS-e820: 000000001f7d0000 – 000000001f7efc00 (reserved)
BIOS-e820: 000000001f7efc00 – 000000001f7fb000 (ACPI NVS)
BIOS-e820: 000000001f7fb000 – 000000001f800000 (reserved)
BIOS-e820: 00000000e0000000 – 00000000f0000000 (reserved)
BIOS-e820: 00000000fec00000 – 00000000fec02000 (reserved)
BIOS-e820: 00000000fed20000 – 00000000fed9b000 (reserved)
BIOS-e820: 00000000feda0000 – 00000000fedc0000 (reserved)
BIOS-e820: 00000000ffb00000 – 00000000ffc00000 (reserved)
BIOS-e820: 00000000fff00000 – 0000000100000000 (reserved)
0MB HIGHMEM available.
503MB LOWMEM available.
Memory for crash kernel (0x0 to 0x0) notwithin permissible range
disabling kdump
Using x86 segment limits to approximate NX protection
On node 0 totalpages: 128976
DMA zone: 4096 pages, LIFO batch:0
Normal zone: 124880 pages, LIFO batch:31
DMI 2.3 present.
Using APIC driver default
ACPI: RSDP (v000 HP ) @ 0x000fe270
ACPI: RSDT (v001 HP 30C4 0x31100620 HP 0x00000001) @ 0x1f7efc84
ACPI: FADT (v002 HP 30C4 0x00000002 HP 0x00000001) @ 0x1f7efc00
ACPI: MADT (v001 HP 30C4 0x00000001 HP 0x00000001) @ 0x1f7efcb8
ACPI: MCFG (v001 HP 30C4 0x00000001 HP 0x00000001) @ 0x1f7efd14
ACPI: SSDT (v001 HP HPQPpc 0x00001001 MSFT 0x0100000e) @ 0x1f7f6698
ACPI: DSDT (v001 HP DAU00 0x00010000 MSFT 0x0100000e) @ 0x00000000
ACPI: PM-Timer IO Port: 0x1008
ACPI: Local APIC address 0xfec01000
ACPI: LAPIC (acpi_id lapic_id enabled)
Processor #0 6:13 APIC version 20
ACPI: LAPIC_NMI (acpi_id high edge lint)
ACPI: IOAPIC (id address gsi_base)
IOAPIC: apic_id 1, version 32, address 0xfec00000, GSI 0-23
#
Linux编写内核模块编译时找不到头文件?
-I /usr/src/linux-headers-2.6.32-24/include 其中, -I和后面的路径没有空格 -I/usr/src/linux-headers-2.6.32-24/include 一般也很少直接用gcc命令, 大部分是用makefile, make -C kernel_path modules
Linux是开源的,那么如何查看源代码?
Linux的内核源代码可以从很多途径得到。一般来讲,在安装的linux系统下,/usr/src/linux目录下的东西就是内核源代码。
Linux内核版本号的规则?
Linux内核版本有两种:稳定版和开发版 ,Linux内核版本号由3个数字组成:r.x.y
r:目前发布的内核主版本。
x:偶数表示稳定版本;奇数表示开发中版本。
y:错误修补的次数。
内核版本号每位都代表什么 ?
以版本号为例: 2.6.9-5.ELsmp ,
r: 2 , 主版本号
x: 6 , 次版本号,表示稳定版本
y: 9 , 修订版本号 , 表示修改的次数
头两个数字合在一齐可以描述内核系列。如稳定版的2.6.0,它是2.6版内核系列。
5: 表示这个当前版本的第5次微调patch , 而ELsmp指出了当前内核是为ELsmp特别调校的
EL : Enterprise Linux ; smp : 表示支持多处理器 , 表示该内核版本支持多处理器
知识延伸
一般的有三种
1 smp
2 bigmem
3 一般的内核
Red Hat Linux开机的时候,GRUB的启动菜单会有两个选项,分别是
Red Hat Enterprise Linux ES (版本号.ELsmp)
Red Hat Enterprise Linux ES-up (版本号.EL)
这两个分别是代表什么含义呢?
其实这个就是系统开机时由GRUB引导启动 - 单处理器 与 对称多处理器启动核心文件的区别。
Red Hat Enterprise Linux ES (版本号.ELsmp) multiple processor (symmetric multiprocessing )
Red Hat Enterprise Linux ES-up (版本号.EL) uniprocessor
下面就把SUSE与Red Hat启动菜单内可选择的选项,列举出来
SUSE
版本号-default: SUSE Linux kernel for uniprocessor machines 默认选项,支持单处理器机器
版本号-smp: SUSE Linux kernel that supports symmetric multiprocessing and up to 4 GB of RAM
支持4GB内存的对称多处理器机器
版本号-bigsmp: SUSE Linux kernel supports symmetric multiprocessing and up to 64 GB
支持64GB内存的对称多处理器机器
Red Hat Linux
版本号.EL: Red Hat Linux kernel for uniprocessor machines 支持单处理器机器
版本号.ELhugemem: Red Hat Linux kernel that supports up to 64 GB of RAM
支持64GB内存的对称多处理器机器
版本号.ELsmp: Red Hat Linux kernel that supports symmetric multiprocessing 对称多处理器机器,支持4G内存
有些情况下你需要支持1和2特性,那么你可以:重新编译一下内核,在处理器及内存选择项上选择与你配置相对应的选项即可。
如何下载对应内核版本的源代码 ?
一般情况下,可以直接到官网:http://www.kernel.org下载,
缺点是:对于任何内核做过特殊优化调校的发行版是不合适的,尤其是fedora ubuntu 这一类的,毕竟他们在内核中打了大量的补丁,做了很多优化,如果直接使用官方源码 ,你就无法享受到这些东西 ,内核不是越新越好的 越合适越好
因此最好到发行商的官网去下载,因为官方已经提供了编译好的源码rpm包。
如何使用对应的内核源码包 ?
以fedora官方提供的内核源码: kernel-2.6.23.9-85.fc8.src.rpm 为例
首先,安装源码
# rpm -ivh kernel-2.6.23.9-85.fc8.src.rpm
然后,转换源码
转换之前,请确保/usr/src/目录下有redhat目录(一般/usr/src/是空目录)。
# rpmbuild -bp –target=$(uname -m) /usr/src/redhat/SPECS/kernel.spec
这样会将源码放置在/usr/src/redhat/BUILD/kernel-2.6.23/。
这里有两个有用的文件夹:.
linux-2.6.23.ARCH——这个是kernel.org 提供的包经过Fedora 补丁和升级得到的。也就是 2.6.23.9-85.fc8 这个 打过补丁的内核
ARCH 与uname-m 的输出结果一致,通常为i686。如果你想得到不同的输出,你可以使用
“–target=”这个选项来进行指定。
vanilla——这个是标准的、由kernel.org 提供的没有经过补丁和升级的源码。
linux哪个目录放内核?
1、是在/boot目录下
2、/usr/src目录一般是系统内核代码目录
3、你看/boot/grub/grub.conf文件,kernel那行是vmlinuz…,就是代表内zhuan核的名字
4、Linux是一shu个一体化内核(monolithic kernel)系统。“内核”指的是一个提供硬件抽象层、磁盘及文件系统控制、多任务等功能的系统软件。一个内核不是一套完整的操作系统。一套基于Linux内核的完整操作系统叫作Linux操作系统,或是GNU/Linux。设备驱动程序可以完全访问硬件。Linux内的设备驱动程序可以方便地以模块化(modularize)的形式设置,并在系统运行期间可直接装载或卸载。