在Linux系统中查询硬件信息可以通过多种命令行工具完成,本章主要讲述如何查询Linux硬件信息。
操作系统:
CentOS Stream 9
操作步骤:
指令uname -a
: 显示内核版本、硬件名称、操作系统等基本信息。
[root@localhost ~]# uname -a
Linux localhost.localdomain 5.14.0-427.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Feb 23 04:45:07 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
指令 lscpu
: 提供CPU架构、速度、核心数等详细信息。
cat /proc/cpuinfo
: 查看更详细的CPU信息,包括每个核心的具体情况。
[root@localhost ~]# lscpu
架构: x86_64CPU 运行模式: 32-bit, 64-bitAddress sizes: 45 bits physical, 48 bits virtual字节序: Little Endian
CPU: 4在线 CPU 列表: 0-3
厂商 ID: GenuineIntelBIOS Vendor ID: GenuineIntel型号名称: 13th Gen Intel(R) Core(TM) i5-13500HBIOS Model name: 13th Gen Intel(R) Core(TM) i5-13500HCPU 系列: 6型号: 186每个核的线程数: 1每个座的核数: 2座: 2步进: 2BogoMIPS: 6374.39标记: 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 rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni arat umip pku ospke gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize flush_l1d arch_capabilities
Virtualization features: 超管理器厂商: VMware虚拟化类型: 完全
Caches (sum of all): L1d: 192 KiB (4 instances)L1i: 128 KiB (4 instances)L2: 5 MiB (4 instances)L3: 36 MiB (2 instances)
NUMA: NUMA 节点: 1NUMA 节点0 CPU: 0-3
Vulnerabilities: Gather data sampling: Not affectedItlb multihit: KVM: Mitigation: VMX unsupportedL1tf: Not affectedMds: Not affectedMeltdown: Not affectedMmio stale data: Unknown: No mitigationsRetbleed: Not affectedSpec rstack overflow: Not affectedSpec store bypass: Mitigation; Speculative Store Bypass disabled via prctlSpectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitizationSpectre v2: Mitigation; Enhanced / Automatic IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequenceSrbds: Not affectedTsx async abort: Not affected
[root@localhost ~]# cat /proc/meminfo
MemTotal: 3976796 kB
MemFree: 3624840 kB
MemAvailable: 3557308 kB
Buffers: 1664 kB
Cached: 81480 kB
SwapCached: 0 kB
Active: 102800 kB
Inactive: 20920 kB
Active(anon): 38464 kB
Inactive(anon): 11340 kB
Active(file): 64336 kB
Inactive(file): 9580 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Zswap: 0 kB
Zswapped: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 40576 kB
Mapped: 38016 kB
Shmem: 9228 kB
KReclaimable: 31008 kB
Slab: 86580 kB
SReclaimable: 31008 kB
SUnreclaim: 55572 kB
KernelStack: 5808 kB
PageTables: 1576 kB
SecPageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1988396 kB
Committed_AS: 168032 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 55748 kB
VmallocChunk: 0 kB
Percpu: 47616 kB
HardwareCorrupted: 0 kB
AnonHugePages: 10240 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
FileHugePages: 0 kB
FilePmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
Unaccepted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 147264 kB
DirectMap2M: 2998272 kB
DirectMap1G: 3145728 kB
[root@localhost ~]#
指令:lsblk
: 列出所有可用的块设备及其挂载点、大小等。
df -h
: 显示已挂载文件系统的磁盘空间使用情况。
fdisk -l
: 列出所有磁盘的分区布局。
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 4.7G 0 part /boot
└─sda2 8:2 0 15.3G 0 part └─cs_bogon-root 253:0 0 15.3G 0 lvm /
sr0 11:0 1 1024M 0 rom
[root@localhost ~]#
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 777M 9.1M 768M 2% /run
/dev/mapper/cs_bogon-root 16G 2.0G 14G 13% /
/dev/sda1 4.6G 220M 4.4G 5% /boot
tmpfs 389M 0 389M 0% /run/user/1000
[root@localhost ~]# fdisk -l
Disk /dev/sda:20 GiB,21474836480 字节,41943040 个扇区
磁盘型号:VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0482781b设备 启动 起点 末尾 扇区 大小 Id 类型
/dev/sda1 * 2048 9766911 9764864 4.7G 83 Linux
/dev/sda2 9766912 41943039 32176128 15.3G 8e Linux LVMDisk /dev/mapper/cs_bogon-root:15.34 GiB,16471031808 字节,32169984 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost ~]#
指令 ip addr
或 ifconfig
: 显示网络接口的IP地址、掩码、广播地址等
[root@localhost ~]# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.0.11 netmask 255.255.255.0 broadcast 192.168.0.255inet6 fe80::20c:29ff:fed2:4aaa prefixlen 64 scopeid 0x20<link>ether 00:0c:29:d2:4a:aa txqueuelen 1000 (Ethernet)RX packets 990 bytes 463809 (452.9 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 946 bytes 102679 (100.2 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (Local Loopback)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@localhost ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000link/ether 00:0c:29:d2:4a:aa brd ff:ff:ff:ff:ff:ffaltname enp3s0inet 192.168.0.11/24 brd 192.168.0.255 scope global noprefixroute ens160valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fed2:4aaa/64 scope link noprefixroute valid_lft forever preferred_lft forever
[root@localhost ~]#