Linux 查看系统硬件信息

1322 字
7 分钟
Linux 查看系统硬件信息
Linux 查看系统硬件信息

Linux 查看系统硬件信息(2021.06.22)#

1. CPU#

Terminal window
# 查看 cpu 的统计信息
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Thread(s) per core: 2
Core(s) per socket: 16
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz
Stepping: 7
CPU MHz: 2294.616
BogoMIPS: 4594.28
......
# /proc/cpuinfo 包含 cpu 的详细信息,如型号、主频等
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 85
model name : Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz
stepping : 7
microcode : 0x5002f01
cpu MHz : 2294.616
cache size : 22528 KB
......
# 查看 cpu 型号
$ cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
64 Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz
# 查看 cpu 数量
$ cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
2
# 查看每个 cpu 的核心数
$ cat /proc/cpuinfo | grep "cpu cores" | uniq
cpu cores : 16
# 查看每个核心的线程数
$ cat /proc/cpuinfo | grep "processor" | wc -l
64

2. 内存#

Terminal window
# 查看内存使用情况,参数 -m 以 megabytes 为单位输出
$ free -m
total used free shared buff/cache available
Mem: 128343 51772 4333 186 72237 75399
Swap: 4095 0 4095
# /proc/meminfo 包含了内存的详细使用信息
$ cat /proc/meminfo
MemTotal: 131423944 kB
MemFree: 2672916 kB
MemAvailable: 76649028 kB
Buffers: 152 kB
Cached: 70588932 kB
SwapCached: 100 kB
Active: 78479944 kB
Inactive: 43857400 kB
Active(anon): 43494740 kB
Inactive(anon): 8445316 kB
Active(file): 34985204 kB
......
# 查看内存硬件信息,参数 -t 指定类型
$ dmidecode -t memory
# dmidecode 3.2
# SMBIOS entry point at 0x68e3b000
Found SMBIOS entry point in EFI, reading table from /dev/mem.
SMBIOS 3.2 present.
Handle 0x1000, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 7680 GB
Error Information Handle: Not Provided
Number Of Devices: 24
Handle 0x1100, DMI type 17, 84 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: 16384 MB
Form Factor: DIMM
Set: 1
Locator: A1
Bank Locator: Not Specified
Type: DDR4
Type Detail: Synchronous Registered (Buffered)
Speed: 2933 MT/s
Manufacturer: 00AD00B300AD
Serial Number: 93440CDD
Asset Tag: 01193161
......

3. 硬盘#

Terminal window
# 列出硬盘和分区情况
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 256G 0 disk
sdb 8:16 0 256G 0 disk /
# 查看硬盘和分区的详细信息
$ fdisk -l
Disk /dev/sda: 1919.7 GB, 1919716163584 bytes, 3749445632 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 411647 200M EFI System EFI System Partition
2 411648 1435647 500M Microsoft basic
3 1435648 3749443583 1.8T Linux LVM
......

4. 网卡#

Terminal window
# 查看网卡硬件信息,参数 -i 忽略大小写
$ lspci | grep -i ethernet
01:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
01:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)

5. 显卡#

Terminal window
# 参数 -i 忽略大小写
$ lspci | grep -i vga
03:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 41)
3b:00.0 VGA compatible controller: NVIDIA Corporation GV102 (rev a1)
86:00.0 VGA compatible controller: NVIDIA Corporation GV102 (rev a1)
af:00.0 VGA compatible controller: NVIDIA Corporation GV102 (rev a1)

6. BIOS#

Terminal window
$ dmidecode -t bios
# dmidecode 3.2
# SMBIOS entry point at 0x68e3b000
Found SMBIOS entry point in EFI, reading table from /dev/mem.
SMBIOS 3.2 present.
Handle 0x0000, DMI type 0, 26 bytes
BIOS Information
Vendor: Dell Inc.
Version: 2.7.7
Release Date: 05/04/2020
Address: 0xF0000
Runtime Size: 64 kB
ROM Size: 32 MB
......

7. 内核版本#

Terminal window
$ uname -a
Linux irecog 4.15.0-129-generic #132~16.04.1-Ubuntu SMP Wed Dec 16 06:46:04 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/version
Linux version 4.15.0-129-generic (buildd@lcy01-amd64-028) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)) #132~16.04.1-Ubuntu SMP Wed Dec 16 06:46:04 UTC 2020

8. 系统版本#

Terminal window
# 适用于所有 linux 发行版
$ cat /etc/issue
Ubuntu 16.04.3 LTS \n \l
# 适用于 redhat 系的 linux
$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
# 适用于所有 linux 发行版
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

lsb_release命令找不到的解决方法:

redhat系列:sudo yum install redhat-lsb

debian系列:sudo apt install lsb-core

9. 系统脚本#

#!/bin/bash
# ========================================
# Linux 硬件信息采集脚本
# ========================================
export LANG=C
export LC_ALL=C
echo "=============================="
echo "服务器型号"
echo "=============================="
if command -v dmidecode >/dev/null 2>&1; then
manufacturer=$(dmidecode -s system-manufacturer)
product_name=$(dmidecode -s system-product-name)
serial_number=$(dmidecode -s system-serial-number)
echo "厂商: $manufacturer"
echo "型号: $manufacturer $product_name"
echo "序列号: $serial_number"
else
echo "⚠️ 未安装 dmidecode,无法读取服务器型号"
fi
echo ""
echo "=============================="
echo "CPU 信息"
echo "=============================="
# CPU 型号
cpu_model=$(lscpu | grep -E "^Model name" | awk -F: '{print $2}' | sed 's/^ *//')
# 物理 CPU 数量
cpu_physical=$(grep "physical id" /proc/cpuinfo | sort -u | wc -l)
# 逻辑核心数量
cpu_cores=$(grep -c "^processor" /proc/cpuinfo)
echo "CPU 型号: $cpu_model * $cpu_physical"
echo "逻辑核心数: $cpu_cores"
echo ""
echo "=============================="
echo "内存信息"
echo "=============================="
# 总内存
mem_total=$(free -h | awk '/Mem:/{print $2}')
echo "内存总量: $mem_total"
# 每条内存
if command -v dmidecode >/dev/null 2>&1; then
echo "内存条详情:"
dmidecode -t memory | awk '
/^\s*Size:/ {
if ($2 != "No") size=$2" "$3
}
/^\s*Speed:/ {
if ($2 ~ /^[0-9]+$/) speed=$2" "$3
}
/^\s*Type:/ {
if ($2 != "Detail:") type=$2
}
/^\s*Manufacturer:/ {
manu=$2
}
/^\s*Serial Number:/ {
serial=$3
}
/^\s*Part Number:/ {
part=$3
}
/^\s*Locator:/ {
loc=$2
}
/^$/ {
if (size != "" && size != "No") {
printf("插槽: %-12s 大小: %-8s 频率: %-10s 类型: %-6s 厂商: %-10s 序列号: %-12s 型号: %s\n",
loc, size, speed, type, manu, serial, part)
}
size=""; speed=""; type=""; manu=""; serial=""; part=""; loc=""
}
' | grep -v "No Module Installed"
else
echo "⚠️ 未安装 dmidecode,无法读取内存条详情,请使用 root 权限安装: sudo apt install dmidecode 或 yum install dmidecode"
fi
echo ""
echo "=============================="
echo "硬盘信息"
echo "=============================="
if command -v lsblk >/dev/null 2>&1; then
echo "硬盘列表:"
lsblk -d -o NAME,SIZE,MODEL | grep -E "^sd|^nvme"
else
echo "⚠️ 未安装 lsblk,尝试使用 fdisk:"
fdisk -l | grep "Disk /dev/"
fi
echo ""
echo "=============================="
echo "显卡信息"
echo "=============================="
if command -v lspci >/dev/null 2>&1; then
gpu_info=$(lspci | grep -iE "3d")
if [ -n "$gpu_info" ]; then
echo "$gpu_info"
gpu_count=$(echo "$gpu_info" | wc -l)
echo "显卡数量: $gpu_count"
else
echo "未检测到独立显卡"
fi
else
echo "⚠️ 未安装 lspci,请安装 pciutils 以检测显卡: sudo apt install pciutils"
fi
echo ""
echo "=============================="
echo "信息采集完成"
echo "=============================="

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Linux 查看系统硬件信息
https://xiaoqqya.qzz.io/posts/linux/linux-查看系统硬件信息/
作者
xiaoQQya
发布于
2021-06-22
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
xiaoQQya
仰望星空,脚踏实地,不要在该奋斗的年纪选择了安逸!
公告
欢迎来到我的博客!
分类
标签
站点统计
文章
11
分类
8
标签
24
总字数
10,614
运行时长
0 天
最后活动
0 天前
站点信息
博客版本
Firefly v6.16.9
文章许可
CC BY-NC-SA 4.0
文章目录