以系统内建 dmidecode 解析硬件配备

系统有个名为 dmidecode 的软件,它可以解析 CPU 型号、主板型号与内存相 关的型号等等~

[root@study ~]# dmidecode -t type
选项与参数:
详细的 type 项目请 man dmidecode 查询更多的数据,这里仅列出比较常用的项目:
1 :详细的系统数据,含主板的型号与硬件的基础数据等
4 :CPU 的相关资料,包括倍频、外频、核心数、核心绪数等
9 :系统的相关插槽格式,包括 PCI, PCI-E 等等的插槽规格说明
17:每一个内存插槽的规格,若内有内存,则列出该内存的容量与型号

范例一:秀出整个系统的硬件信息,例如主板型号等等
[root@study ~]# dmidecode -t 1
# dmidecode 2.12
SMBIOS 2.4 present.

Handle 0x0100, DMI type 1, 27 bytes
System Information
        Manufacturer: Red Hat
        Product Name: KVM
        Version: RHEL 6.6.0 PC
        Serial Number: Not Specified
        UUID: AA3CB5D1-4F42-45F7-8DBF-575445D3887F
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Red Hat Enterprise Linux

范例二:那内存相关的数据呢?
[root@study ~]# dmidecode -t 17
# dmidecode 2.12
SMBIOS 2.4 present.

Handle 0x1100, DMI type 17, 21 bytes
Memory Device
        Array Handle: 0x1000
        Error Information Handle: 0x0000
        Total Width: 64 bits
        Data Width: 64 bits
        Size: 3072 MB
        Form Factor: DIMM
        Set: None
        Locator: DIMM 0
        Bank Locator: Not Specified
        Type: RAM
        Type Detail: None

硬件资源的收集与分析

那除了直接呼叫出 /proc 底下的文件内容之外,其实 Linux 有提供几个简单的指令来将核心所侦测 到的硬件叫出来的~ 常见的指令有底下这些:

  • gdisk:可以使用 gdisk -l 将分区表列出;
  • dmesg: 观察核心运作过程当中所显示的各项讯息记录;
  • vmstat:可分析系统 (CPU/RAM/IO) 目前的状态;
  • lspci:列出整个 PC 系统的 PCI 接口装置!很有用的指令;
  • lsusb:列出目前系统上面各个 USB 端口口的状态,与连接的 USB 装置;
  • iostat:与 vmstat 类似,可实时列出整个 CPU 与接口设备的 Input/Output 状态。

  • lspci
[root@study ~]# lspci [-vvn]
选项与参数:
-v :显示更多的 PCI 接口装置的详细信息;
-vv :比 -v 还要更详细的细部信息;
n :直接观察 PCI 的 ID 而不是厂商名称

范例一:查阅您系统内的 PCI 总线相关装置:
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Red Hat, Inc. QXL paravirtual graphic card (rev 04)
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
00:04.0 SCSI storage controller: Red Hat, Inc Virtio block device
00:05.0 RAM memory: Red Hat, Inc Virtio memory balloon
00:06.0 Audio device: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio
        Controller (rev 01)
00:1d.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03)
00:1d.1 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03)
00:1d.2 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03)
00:1d.7 USB controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03)
# 不必加任何的参数,就能够显示出目前主机上面的各个 PCI 接口的装置呢!

如果你还想要了解某个设备的详细信息时,可以加上 -v 或 -vv 来显示更多的信息喔! 举例来说, 鸟哥想要知道那个以太网络卡更详细的信息时,可以使用如下的选项来处理:

[root@study ~]# lspci -s 00:03.0 -vv

-s 后面接的那个怪东西每个设备的总线、插槽与相关函数功能啦!那个是我们硬件侦测所得到的数 据啰! 你可以对照底下这个文件来了解该串数据的意义:

  • /usr/share/hwdata/pci.ids

其实那个就是 PCI 的标准 ID 与厂牌名称的对应表啦!此外,刚刚我们使用 lspci 时,其实所有的 数据都是由 /proc/bus/pci/ 目录下的数据所取出的呢!由于硬件的发展太过 迅速,所以你的 pci.ids 文件可能会落伍了~那怎办? 没关系~可以使用底下的方式来在线更新你 的对应档:

[root@study ~]# update-pciids

  • lsusb

如果是想要知道系统接了多少个 USB 装置呢?那就使用 lsusb 吧! 这个指令也是很简单的!

[root@study ~]# lsusb [-t]

选项与参数:
-t :使用类似树状目录来显示各个 USB 端口口的相关性

范例一:列出目前鸟哥的测试用主机 USB 各端口口状态
[root@study ~]# lsusb
Bus 002 Device 002: ID 0627:0001 Adomax Technology Co., Ltd 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
# 如上所示,主机在 Bus 002 有接了一个设备,
# 该设备的 ID 是 0627:0001,对应的厂商与产品为 Adomax 的设备。

  • iostat

您磁盘由开机到现在,已经存取多少数据呢?这个时候就得要 iostat 这个指令的帮忙了!

[root@study ~]# iostat [-c|-d] [-k|-m] [-t] [间隔秒数] [侦测次数]
选项与参数:
-c :仅显示 CPU 的状态;
-d :仅显示储存设备的状态,不可与 -c 一起用;
-k :默认显示的是 block ,这里可以改成 K bytes 的大小来显示;
-m :与 -k 类似,只是以 MB 的单位来显示结果。
-t :显示日期出来;

范例一:显示一下目前整个系统的 CPU 与储存设备的状态
[root@study ~]# iostat
Linux 3.10.0-229.el7.x86_64 (study.centos.vbird)  09/02/2015   _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.08    0.01    0.02    0.00    0.01   99.88

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               0.46         5.42         3.16     973670     568007
scd0              0.00         0.00         0.00        154          0
sda               0.01         0.03         0.00       4826          0
dm-0              0.23         4.59         3.09     825092     555621
# 瞧!上面数据总共分为上下两部分,上半部显示的是 CPU 的当下信息;
# 下面数据则是显示储存装置包括 /dev/vda 的相关数据,他的数据意义:
# tps    :平均每秒钟的传送次数!与数据传输『次数』有关,非容量!
# kB_read/s :开机到现在平均的读取单位;
# kB_wrtn/s :开机到现在平均的写入单位;
# kB_read :开机到现在,总共读出来的文件单位;
# kB_wrtn :开机到现在,总共写入的文件单位;

范例二:仅针对 vda ,每两秒钟侦测一次,并且共侦测三次储存装置
[root@study ~]# iostat -d 2 3 vda
Linux 3.10.0-229.el7.x86_64 (study.centos.vbird)  09/02/2015   _x86_64_    (4 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               0.46         5.41         3.16     973682     568148

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               1.00         0.00         0.50          0          1

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               0.00         0.00         0.00          0          0
# 仔细看一下,如果是有侦测次数的情况,那么第一次显示的是『从开机到现在的数据』,
# 第二次以后所显示的数据则代表两次侦测之间的系统传输值!举例来说,上面的信息中, 
# 第二次显示的数据,则是两秒钟内(本案例)系统的总传输量与平均值。

了解磁盘的健康状态

SMART 其实是『 Self-Monitoring, Analysis and Reporting Technology System 』的缩写,主要用来监 测目前常见的 ATA 与 SCSI 界面的磁盘, 只是,要被监测的磁盘也必须要支持 SMART 的协议 才行!否则 smartd 就无法去下达指令,让磁盘进行自我健康检查。

smartd 提供一只指令名为 smartctl,这个指令功能非常多!不过我们底下只想要介绍数个基本的操作,让各位了解一下如何确认你的磁盘是好是坏!

# 1. 用 smartctl 来显示完整的 /dev/sda 的信息
[root@study ~]# smartctl -a /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-229.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

# 首先来输出一下这部磁盘的整体信息状况!包括制造商、序号、格式、SMART 支持度等等!
=== START OF INFORMATION SECTION === 
Device Model:     QEMU HARDDISK
Serial Number:    QM00002
Firmware Version: 0.12.1
User Capacity:    2,148,073,472 bytes [2.14 GB]
Sector Size:      512 bytes logical/physical
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ATA/ATAPI-7, ATA/ATAPI-5 published, ANSI NCITS 340-2000
Local Time is:    Wed Sep  2 18:10:38 2015 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

# 接下来则是一堆基础说明!这里先略过这段资料喔!
General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                                        was completed without error.
                                        Auto Offline Data Collection: Enabled.
.....(中間省略).....
# 再来则是有没有曾经发生过磁盘错乱的问题登录!
SMART Error Log Version: 1
No Errors Logged

# 当你下达过磁盘自我检测的过程,就会被记录在这里了!
SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%      4660         -
# 2  Short offline       Completed without error       00%      4660         -

# 2. 命令磁盘进行一次自我检测的动作,然后再次观察磁盘状态!
[root@study ~]# smartctl -t short /dev/sda
[root@study ~]# smartctl -a /dev/sda
.....(前面省略).....
# 底下会多出一个第三笔的测试信息!看一下 Status 的状态,没有问题就是好消息!
SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%      4660         -
# 2  Short offline       Completed without error       00%      4660         -
# 3  Short offline       Completed without error       00%      4660         -
posted on 2017-11-03 14:40  uetucci  阅读(391)  评论(0编辑  收藏  举报