【Linux】硬件确认命令
在Linux操作系统上获取硬件相关信息的命令备忘录。
查询硬件信息命令
如果使用lshw命令来查看,输出会很长。
如果要检查常用的硬件信息,可以使用dmidecode命令。
直接运行该命令会显示很多信息,但是可以使用-t选项指定要查看的信息,不仅可以确认制造商,还可以确认型号和序列号等。
[dango@host01 ~]# /usr/sbin/dmidecode -t system
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.4.0 present.
# SMBIOS implementations newer than version 3.2.0 are not
# fully supported by this version of dmidecode.
Handle 0x0082, DMI type 1, 27 bytes
System Information
Manufacturer: HPE
Product Name: ProLiant DL360 Gen10
Version: Not Specified
Serial Number: JPNXXXXXX
UUID: 39383250-3834-504a-4e31-XXXXXXXXXXX
Wake-up Type: Power Switch
SKU Number: PXXXXX-XXX
Family: ProLiant
Handle 0x00CD, DMI type 32, 11 bytes
System Boot Information
Status: No errors detected
[dango@host01 ~]#
BIOS的内容如下,还可以查看固件的版本。
[dango@host01 ~]# /usr/sbin/dmidecode -t bios
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.4.0 present.
# SMBIOS implementations newer than version 3.2.0 are not
# fully supported by this version of dmidecode.
Handle 0x0002, DMI type 0, 26 bytes
BIOS Information
Vendor: HPE
Version: U46
Release Date: 08/11/2022
Address: 0xF0000
Runtime Size: 64 kB
ROM Size: 64 MB
Characteristics:
PCI is supported
PNP is supported
BIOS is upgradeable
BIOS shadowing is allowed
ESCD support is available
Boot from CD is supported
Selectable boot is supported
EDD is supported
5.25"/360 kB floppy services are supported (int 13h)
5.25"/1.2 MB floppy services are supported (int 13h)
3.5"/720 kB floppy services are supported (int 13h)
Print screen service is supported (int 5h)
8042 keyboard services are supported (int 9h)
Serial services are supported (int 14h)
Printer services are supported (int 17h)
CGA/mono video services are supported (int 10h)
ACPI is supported
USB legacy is supported
BIOS boot specification is supported
Function key-initiated network boot is supported
Targeted content distribution is supported
UEFI is supported
BIOS Revision: 1.64
Firmware Revision: 2.72
情报确认指令
如果想要获取包括物理/逻辑/虚拟设备在内的所有设备列表,可以使用 ls /sys/class/net/ 进行确认。对于绑定(Bonding)接口信息,只需要使用 ls /proc/net/bonding/。桥接(Bridge)设备信息则可以通过 brctl show 命令来查看。
[root@dango01 ~]# ls -l /sys/class/net/
bond0
bond0.1111
ens0
ens1
如果您只需要机器上物理连接的设备名称,请参考以下选项。
[root@dango01 ~]# for DEV in `find /sys/devices -name net | grep -v virtual`; do ls $DEV/; done
ens0
ens1
使用ethtool工具可以检查接口的状态。
[root@dango01 ~]$ ethtool ens0
Settings for ens0:
Supported ports: [ FIBRE ]
Supported link modes: Not reported
Supported pause frame use: Symmetric
Supports auto-negotiation: No
Supported FEC modes: Not reported
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Advertised FEC modes: Not reported
Speed: 25000Mb/s
Duplex: Full
Port: FIBRE
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
Cannot get wake-on-lan settings: Operation not permitted
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
[root@dango01 ~]$
[root@dango01 ~]$ ethtool ens1
Settings for ens1:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: on (auto)
Cannot get wake-on-lan settings: Operation not permitted
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
[root@dango01 ~]$
如果物件有对应的话,可以通过添加“-m”来查看模块的详细信息。
确认NIC的驱动程序信息
通过运行命令 “dmesg | grep インターフェース名” 来确认该驱动程序。
[root@dango01 ~]# dmesg | grep ens0
[ 16.397642] ice 0000:0f:00.0 ens0: already using mac b4:96:XX:XX:XX:XX
[ 16.719498] ice 0000:0f:00.0 ens0: NIC Link is up 25 Gbps, Flow Control: Unknown
[ 16.727262] 8021q: adding VLAN 0 to HW filter on device ens0
[ 16.739408] bond0: Enslaving ens0 as a backup interface with an up link
⇒正在使用冰驱动器。
[root@dango01 ~]# dmesg | grep ens1
[ 18.381323] 8021q: adding VLAN 0 to HW filter on device ens1
[ 18.387455] bond2: Enslaving ens1 as a backup interface with a down link
[ 22.113002] igb 0000:48:00.0 ens1: igb: ens1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[ 22.208608] bond2: link status up for interface ens1, enabling it in 10000 ms
可以使用modinfo命令进行确认,查看使用的是igb驱动。
[root@dango01 ~]# modinfo ice
filename: /lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/net/ethernet/intel/ice/ice.ko.xz
version: 0.7.2-k
license: GPL v2
description: Intel(R) Ethernet Connection E800 Series Linux Driver
author: Intel Corporation, <linux.nics@intel.com>
rhelversion: 7.9
[root@dango01 ~]# modinfo igb
filename: /lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/net/ethernet/intel/igb/igb.ko.xz
version: 5.6.0-k
license: GPL v2
description: Intel(R) Gigabit Ethernet Network Driver
author: Intel Corporation, <e1000-devel@lists.sourceforge.net>
retpoline: Y
rhelversion: 7.9
可以在F版本或F描述中指定参数。
(附加)操作系统基本信息。
检查内核启动选项。
由GRUB等引导加载程序传递给内核的参数。
[root@host01 ~]# cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-3.10.0-1160.el7.x86_64 root=UUID=b91a1330-4dce-478a-8857-da1f37a1XXXX ro crashkernel=auto biosdevname=0 console=ttyS0,115200 net.ifnames=1
请确认内核的版本。
[root@host01 ~]# uname -r
3.10.0-1160.el7.x86_64
如果是使用CentOS/RHEL的话
[dango@host01 ~]$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
虽然可以通过操作系统(OS)版本来确认,但是`/etc/redhat-release`是一个文件,以下是调查包含该文件的软件包列表。可以看到相当多的内容。
[root@host01 ~]$ rpm -qif /etc/redhat-release
Name : centos-release
Version : 7
Release : 9.2009.1.el7.centos
Architecture: x86_64
Install Date: 2020年10月04日 16時54分09秒
Group : System Environment/Base
Size : 44787
License : GPLv2
Signature : RSA/SHA256, 2020年12月03日 01時35分28秒, Key ID 24c6a8a7f4a80eb5
Source RPM : centos-release-7-9.2009.1.el7.centos.src.rpm
Build Date : 2020年11月24日 00時08分41秒
Build Host : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
Summary : CentOS Linux release file
Description :
CentOS Linux release files
我发现了一个名为ceontos-release的软件包。
让我来看一下这个软件包中包含的文件。
[root@host01 ~]$ rpm -ql centos-release
/etc/centos-release
/etc/centos-release-upstream
/etc/issue
/etc/issue.net
/etc/os-release
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Testing-7
/etc/redhat-release
/etc/rpm/macros.dist
/etc/system-release
/etc/system-release-cpe
/etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-CR.repo
/etc/yum.repos.d/CentOS-Debuginfo.repo
/etc/yum.repos.d/CentOS-Media.repo
/etc/yum.repos.d/CentOS-Sources.repo
/etc/yum.repos.d/CentOS-Vault.repo
/etc/yum.repos.d/CentOS-fasttrack.repo
/etc/yum.repos.d/CentOS-x86_64-kernel.repo
/etc/yum/vars/contentdir
/etc/yum/vars/infra
/usr/lib/os-release
/usr/lib/systemd/system-preset/85-display-manager.preset
/usr/lib/systemd/system-preset/90-default.preset
/usr/share/centos-release/EULA
/usr/share/doc/centos-release/Contributors
/usr/share/doc/centos-release/GPL
/usr/share/doc/redhat-release
/usr/share/redhat-release
每次检查版本时,我总是无意间看/etc/redhat-release,原来是这个意思啊…
剩下的就是hostnamectl可以相对容易地总结一下。
[root@host01 ~]# hostnamectl
Static hostname: host01
Icon name: computer-server
Chassis: server
Machine ID: 638128914a9249d0a03b20cadXXXXXXX
Boot ID: d37024b5ce6c446b8b17cd626XXXXXXX
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.el7.x86_64
Architecture: x86-64
[root@host01 ~]#
哎哟。