Linux基础学习(3)系统硬件查询

李博明老师讲的Linux课程笔记。

系统为debian系统,主要内容包括:如何查看硬件信息。

正确的硬件认识才能做出故障排除。


正确的硬件认识才能做出故障排除

主要的硬件如下:

  1. CPU型号
  2. 存储器(Memory)容量
  3. 硬盘数量与容量
  4. 显卡
  5. 各种硬件型号与驱动(界面卡)

1. 查看CPU型号

1
cat /proc/cpuinfo

一般而言,这种信息的都比较长,常转换为.log的日志形式进行查看

1
2
3
4
~$ cat /proc/cpuinfo > cpuinfo.log
~$ vim cpuinfo.log
...
...

例1:

树莓派4b:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
processor	: 0
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3

processor : 1
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3

processor : 2
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3

processor : 3
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3

Hardware : BCM2835
Revision : b03114
Serial : 1000000055f1022c
Model : Raspberry Pi 4 Model B Rev 1.4

由上文可知:

  1. 树莓派4B为4核心/线程处理器
  2. Hardware:告诉我们树莓派4B的型号是BCM2835

例2:

个人电脑虚拟机:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
processor	: 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping : 9
microcode : 0xde
cpu MHz : 2711.999
cache size : 3072 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves arat md_clear flush_l1d arch_capabilities
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips : 5423.99
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:

processor : 1
...
processor : 2
...
processor : 3
...

由上文可知:

  1. 虚拟机有四个线程(processor)
  2. vendor_id:该CPU是Intel做的
  3. model name:CPU型号是i5-7200U;运行速度2.50GHz,这个可以在cpu MHz得到验证。
  4. cpu MHz: CPU的运行速度。一般现代的多核CPU每个核的运行速度是不同的,但是由于此处是虚拟机,故速度相同(文中未列出)。不同的CPU运行速度旨在根据系统需求调整CPU运转速率,当不需要大量的计算的时候,可以节约能耗。
  5. cache size:内存大小为3072KB
  6. siblings:此处告诉我们CPU有两个同胞。如果siblings=cpu cores,说明CPU的超执行绪( HT, Hyper- Threading)没有打开。如果打开的话,则siblings=2×cpu cores
  7. cpu cores:CPU的核心数
  8. flags:可以认为是CPU支持的指令集,或者说是CPU支持的功能
  9. bugs:指CPU存在的硬件bug;这几个bug是长久以来就存在的了,如今都是使用软件的方式规避掉硬件的bug。(这些bug的存在并不会影响日常使用)
  10. bogomips:Linux对于CPU的测速标准。这个标准并不是准确评判标准。简单而言,该数值越大,CPU跑的越快。

2. 查看磁盘挂载、使用情况

1
2
3
lsblk
df -kh
free

3. 查看界面卡

拆机查看硬件型号已经成为过去:

  1. 如今的主机大多数已经封装,为了芯片的散热,往往芯片外面有风扇、散热片等,拆机查看硬件型号也更加复杂。
  2. 而且,如见芯片功能愈加强大,音效卡、网卡往往也整合到系统芯片中,如南北桥,此时拆机也看不见具体的硬件型号。

3.1 初步判别

1
lspci

由于本人没有Linux实机,只能用虚拟机代替(虚拟机和实体机差别巨大)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:10.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)
02:00.0 USB controller: VMware USB1.1 UHCI Controller
02:01.0 Ethernet controller: Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] (rev 10)
02:02.0 Multimedia audio controller: Ensoniq ES1371/ES1373 / Creative Labs CT2518 (rev 02)
02:03.0 USB controller: VMware USB2 EHCI Controller
02:05.0 SATA controller: VMware SATA AHCI controller

对上文进行说明:

  1. Host bridge:北桥(DRAM控制晶片)
  2. PCI bridge:南桥(PCIe控制晶片)。如图所示,如今南桥和北桥已经合并到同一颗晶片中,其生产商为Intel,型号为440BX/ZX/DX-8244BX/ZX/DX
  3. VGA compatible controller:集成显卡型号
  4. Ethernet controller:网卡
  5. USB controller:USB控制器
  6. Multimedia audio controller:音效卡
  7. SATA controllerSATA控制器, 磁盘控制器

3.2 进一步了解——驱动模组

3.2.1 了解不同的界面卡和驱动程序

1
lspci -k

结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
Subsystem: VMware Virtual Machine Chipset
Kernel driver in use: agpgart-intel
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
...
...
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
Subsystem: VMware SVGA II Adapter
Kernel driver in use: vmwgfx
Kernel modules: vmwgfx
00:10.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
Subsystem: VMware LSI Logic Parallel SCSI Controller
Kernel driver in use: mptspi
Kernel modules: mptspi
...
...
02:00.0 USB controller: VMware USB1.1 UHCI Controller
Subsystem: VMware USB1.1 UHCI Controller
Kernel driver in use: uhci_hcd
02:01.0 Ethernet controller: Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] (rev 10)
Subsystem: Advanced Micro Devices, Inc. [AMD] PCnet - Fast 79C971
Kernel driver in use: pcnet32
Kernel modules: pcnet32
02:02.0 Multimedia audio controller: Ensoniq ES1371/ES1373 / Creative Labs CT2518 (rev 02)
Subsystem: Ensoniq Audio PCI 64V/128/5200 / Creative CT4810/CT5803/CT5806 [Sound Blaster PCI]
Kernel driver in use: snd_ens1371
Kernel modules: snd_ens1371
02:03.0 USB controller: VMware USB2 EHCI Controller
Subsystem: VMware USB2 EHCI Controller
Kernel driver in use: ehci-pci
02:05.0 SATA controller: VMware SATA AHCI controller
Subsystem: VMware SATA AHCI controller
Kernel driver in use: ahci
Kernel modules: ahci

其中最重要的有两行:

1
2
Kernel driver in use: 模组名称
Kernel modules: 模组名称

其中:

Kernel modules: 指该硬件需要什么样的驱动程序模组才能驱动

Kernel driver in use:目前正在使用这个模组驱动该硬件

如果没有Kernel driver in use,则说明该驱动模组并没有载入。

3.2.2 观察目前系统载入的核心模组

1
lsmod

该命令执行的结果,并不按照”字母“排序

如果想要按照”字母“进行排序,则执行(有缺点:标题Module ...也会参与排序)

1
lsmod | sort

从结果来看,可以看到上文Kernel driver in use:提到的许多模组。同时可以看到该模组目前有没有被其他模组使用(by栏),这取决了模组之间的相依关系

3.3 载入、删除核心模组

如果我们需要的模组(假设模组名为AAA)没有在lsmod中出现,我们就需要自己安装,执行

1
sudo modprobe AAA

如果想要移除,则执行

1
sudo rmmod AAA

如果该模组和其他模组有相依关系(其他模组正在使用着该模组),可能无法移除,此时只能将这些模组一并移除。

一般而言,如果模组出了问题,我们不希望通过关机重启的方法进行修复,我们希望使用其他的办法对模组进行修复。

4. 使用dmesg查看系统信息

dmesg报告相当的长,我们一般采用dmesg > filename.log,再利用vi或者vim进行阅读。

4.1 编译核心

如下文

1
[    0.000000] Linux version 5.10.42-Release-OPENFANS+20210611-v8 (root@cavium) (gcc-10.2.0 (GCC) 10.2.0, GNU ld (GNU Binutils for Ubuntu) 2.26.1) #1 SMP PREEMPT Fri Jun 11 17:19:45 CST 2021

由上文可知,Linux核心的版本是5.10.42,编译核心的人是root@cavium,使用的是gcc-10.2.0编译的

4.2 CPU信息

(前面也可以看到,这里不赘述)

4.3 网络信息

1
[    3.499713] pcnet32 0000:02:01.0 ens33: renamed from eth0

可见,驱动模组是pcnet32

使用lspci -k,可见

1
2
3
4
02:01.0 Ethernet controller: Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] (rev 10)
Subsystem: Advanced Micro Devices, Inc. [AMD] PCnet - Fast 79C971
Kernel driver in use: pcnet32
Kernel modules: pcnet32

其中,Kernel driver in usepcnet32

使用lsmod,可见

1
2
Module		Size Used by
pcnet32 45056 0

其中,pcnet32已经被加载

4.3 硬盘信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[    4.123960] sd 32:0:0:0: Attached scsi generic sg1 type 0
[ 4.123986] sd 32:0:0:0: [sda] 41943040 512-byte logical blocks: (21.5 GB/20.0 GiB)
[ 4.124201] sd 32:0:0:0: [sda] Write Protect is off
[ 4.124206] sd 32:0:0:0: [sda] Mode Sense: 61 00 00 00
[ 4.124770] sd 32:0:0:0: [sda] Cache data unavailable
[ 4.124774] sd 32:0:0:0: [sda] Assuming drive cache: write through
[ 4.124880] sd 32:0:1:0: Attached scsi generic sg2 type 0
[ 4.125500] sd 32:0:1:0: [sdb] 314572800 512-byte logical blocks: (161 GB/150 GiB)
[ 4.125659] sd 32:0:1:0: [sdb] Write Protect is off
[ 4.125664] sd 32:0:1:0: [sdb] Mode Sense: 61 00 00 00
[ 4.125989] sd 32:0:1:0: [sdb] Cache data unavailable
[ 4.125995] sd 32:0:1:0: [sdb] Assuming drive cache: write through
[ 4.127227] sda: sda1
[ 4.128478] sdb: sdb1
[ 4.138067] sd 32:0:0:0: [sda] Attached SCSI disk
[ 4.139102] sd 32:0:1:0: [sdb] Attached SCSI disk

可以看到,一共有两个硬盘:sdasdb,还可以看到硬盘容量。

5. dmidecode查看系统信息

dmidecode是一个可以解码主机BIOS的DMI/SMBIOS内的信息,输入

1
dmidecode

该命令的输出很长,但是十分重要。

5.1 BIOS信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
BIOS Information
Vendor: Phoenix Technologies LTD
Version: 6.00
Release Date: 07/29/2019
Address: 0xEA480
Runtime Size: 88960 bytes
ROM Size: 64 kB
Characteristics:
ISA is supported
PCI is supported
PC Card (PCMCIA) is supported
PNP is supported
...
...
BIOS Revision: 4.6
Firmware Revision: 0.0

内容包括BIOS的版本(6.00)、厂商(Phoenix Technologies LTD)、释出日期(07/29/2019)、其所支持的版本等等

5.2 主机信息

1
2
System Information
...

5.3 主板信息

1
2
Base Board Information
...

5.4 CPU信息

1
2
Processor Information
...

5.5 缓存信息(有相关的补充)

1
2
3
4
5
6
Cache Information
Socket Designation: L1
...
Cache Information
Socket Designation: L2
...

包括一阶缓存、二阶缓存等等…

补充说明:cache(缓存)

image-20220501195400330

电脑的所有指令中,话得时间最长的是存档,之后就是读档。

有些存储器的地址特别常用,就会优先存到Cache中。实际的读写中,由于不同Level的Cache存储的地址不同,于是产生了击中(Hit)和失误(Miss)的概念。

5.6 内存条(tw:记忆体、US:Momery)信息

1
Memory Device

小贴士:如果电脑有多个内存条,我们希望购买同一个厂家、同一个型号、同一个批次、同一个容量的内存条,这样搭建的服务器稳定。

等等…信息