【Linux】ハードウェア系確認コマンド

Linux-OS上で確認できるHW周りの情報を取得するコマンドメモ。

# HW情報確認コマンド
`lshw`で見られるが、出力がとても長くなる。
よく使うHW情報を確認するなら、`dmidecode`コマンド。
これもそのまま打つとずらっと出てくるが、tオプションで情報を指定できる。メーカーだけでなく型番やらシリアルも確認できちゃう。
```console
[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は以下。Firmのversionもみれる。
```console
[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

```

# CPU
物理CPUが2つ,1CPUのコア数が36,ハイパースレッドONの場合の例

```console
[dango@host01 ~]$ lscpu
アーキテクチャ: x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                144
On-line CPU(s) list:   0-143
コアあたりのスレッド数:2
ソケットあたりのコア数:36
Socket(s):             2
NUMAノード:         4
ベンダーID:        GenuineIntel
CPUファミリー:    6
モデル:             106
Model name:            Intel(R) Xeon(R) Platinum 8352V CPU @ 2.10GHz
ステッピング:    6
CPU MHz:               2100.000
BogoMIPS:              4200.00
仮想化:             VT-x
L1d キャッシュ:   48K
L1i キャッシュ:   32K
L2 キャッシュ:    1280K
L3 キャッシュ:    55296K
NUMAノード 0 CPU:   0-17,72-89
NUMAノード 1 CPU:   18-35,90-107
NUMAノード 2 CPU:   36-53,108-125
NUMAノード 3 CPU:   54-71,126-143
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 invpcid_single intel_pt ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq md_clear pconfig spec_ctrl intel_stibp flush_l1d arch_capabilities
```

`/proc/cpuinfo`でプロセッサごとの情報を表示
```console
[dango@host01 ~]$ fgrep 'physical id' /proc/cpuinfo | sort -u | wc -l
2
[dango@host01 ~]$ 
[dango@host01 ~]$ fgrep 'cpu cores' /proc/cpuinfo | sort -u | sed 's/.*: //'
36
[dango@host01 ~]$ 
[dango@host01 ~]$ fgrep 'processor' /proc/cpuinfo | wc -l
144
[dango@host01 ~]$ 
```

```console
[dango@raspi01 ~]# cat /proc/cpuinfo
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        : c03114
Serial          : 1000000080401a8a
Model           : Raspberry Pi 4 Model B Rev 1.4
```

# メモリ
```console
[dango@raspi01 ~]# cat /proc/meminfo
MemTotal:        3881060 kB
MemFree:          218228 kB
MemAvailable:    3299576 kB
Buffers:          123048 kB
Cached:          2965772 kB
SwapCached:          100 kB
Active:          2150524 kB
Inactive:        1147088 kB
Active(anon):       3656 kB
Inactive(anon):   196816 kB
Active(file):    2146868 kB
Inactive(file):   950272 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       1048572 kB
SwapFree:        1043196 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:        207500 kB
Mapped:           127132 kB
Shmem:              3552 kB
KReclaimable:     176116 kB
Slab:             262560 kB
SReclaimable:     176116 kB
SUnreclaim:        86444 kB
KernelStack:        4320 kB
PageTables:         4696 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2989100 kB
Committed_AS:    1014316 kB
VmallocTotal:   133143592960 kB
VmallocUsed:       21884 kB
VmallocChunk:          0 kB
Percpu:             3216 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
CmaTotal:         327680 kB
CmaFree:          109336 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
```
メインメモリとスワップの使用量を簡易的に調べるなら`free -ht`コマンド

# ディスク
```console
[dango@raspi01 ~]# cat /proc/diskstats
   7       0 loop0 14 0 34 1 0 0 0 0 0 16 1 0 0 0 0 0 0
   7       1 loop1 123 0 4384 572 0 0 0 0 0 296 572 0 0 0 0 0 0
   7       2 loop2 113 0 2926 239 0 0 0 0 0 284 239 0 0 0 0 0 0
   7       3 loop3 58 0 2198 473 0 0 0 0 0 392 473 0 0 0 0 0 0
   7       4 loop4 1005 0 45298 1483 0 0 0 0 0 3896 1483 0 0 0 0 0 0
   7       5 loop5 1038 0 56160 973 0 0 0 0 0 2972 973 0 0 0 0 0 0
   7       6 loop6 326 0 8404 894 0 0 0 0 0 1152 894 0 0 0 0 0 0
   7       7 loop7 232 0 8792 348 0 0 0 0 0 800 348 0 0 0 0 0 0
 179       0 mmcblk0 78621 12115 5928704 461151 321865 303307 26572025 19383750 0 1953408 20532003 19445 421 44908200 687100 0 0
 179       1 mmcblk0p1 217 146 11504 1444 1681 1062 597089 204423 0 18908 207247 6 6 294736 1379 0 0
 179       2 mmcblk0p2 78287 11969 5913576 459616 320184 302245 25974936 19179327 0 1948548 20324663 19439 415 44613464 685720 0 0
   8       0 sda 130 0 6304 734 0 0 0 0 0 536 734 0 0 0 0 0 0
   8       1 sda1 74 0 4192 459 0 0 0 0 0 316 459 0 0 0 0 0 0
   7       8 loop8 115 0 4394 585 0 0 0 0 0 544 585 0 0 0 0 0 0
   7       9 loop9 115 0 4390 700 0 0 0 0 0 668 700 0 0 0 0 0 0
   7      10 loop10 53 0 2128 1507 0 0 0 0 0 584 1507 0 0 0 0 0 0
   7      11 loop11 152 0 5248 1392 0 0 0 0 0 708 1392 0 0 0 0 0 0
   7      12 loop12 869 0 56354 2191 0 0 0 0 0 4004 2191 0 0 0 0 0 0
   7      13 loop13 1164 0 28574 1950 0 0 0 0 0 1612 1950 0 0 0 0 0 0
   7      14 loop14 183 0 2740 563 0 0 0 0 0 500 563 0 0 0 0 0 0
   7      15 loop15 112 0 2952 82 0 0 0 0 0 136 82 0 0 0 0 0 0
   7      16 loop16 5962 0 428672 1147 0 0 0 0 0 24512 1147 0 0 0 0 0 0
   7      17 loop17 18 0 102 43 0 0 0 0 0 52 43 0 0 0 0 0 0
   7      18 loop18 31 0 556 121 0 0 0 0 0 180 121 0 0 0 0 0 0
   7      19 loop19 14 0 52 1 0 0 0 0 0 16 1 0 0 0 0 0 0
   7      20 loop20 12 0 40 1 0 0 0 0 0 24 1 0 0 0 0 0 0
   7      21 loop21 41 0 686 515 0 0 0 0 0 532 515 0 0 0 0 0 0
   7      22 loop22 48 0 710 479 0 0 0 0 0 504 479 0 0 0 0 0 0
   7      23 loop23 343 0 7414 26 0 0 0 0 0 372 26 0 0 0 0 0 0
   7      24 loop24 208 0 6598 13 0 0 0 0 0 308 13 0 0 0 0 0 0
   7      25 loop25 676 0 43852 69 0 0 0 0 0 2508 69 0 0 0 0 0 0
   7      26 loop26 336 0 7330 20 0 0 0 0 0 404 20 0 0 0 0 0 0
   7      27 loop27 247 0 11076 20 0 0 0 0 0 528 20 0 0 0 0 0 0
```
ディスク空き容量は`df -H`コマンド、ディレクトリごとのディスク使用量は`du -h /XXX`コマンド、パーティション情報は`lsblk`コマンドで確認できる。
※RAIDは各ベンダーでユーティリティツールのコマンドを使用する他、redfishでも確認できる。

# NIC
```
[dango@host01 ~]# lspci |grep Eth
22:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
22:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
22:00.2 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
22:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
37:00.0 Ethernet controller: Intel Corporation Ethernet Controller E810-XXV for SFP (rev 02)
37:00.1 Ethernet controller: Intel Corporation Ethernet Controller E810-XXV for SFP (rev 02)
a0:00.0 Ethernet controller: Intel Corporation Ethernet Controller E810-XXV for SFP (rev 02)
a0:00.1 Ethernet controller: Intel Corporation Ethernet Controller E810-XXV for SFP (rev 02)
```

# IF情報確認
認識されているIF情報は`ifconfig` や `ip` でもいいが、物理/論理/仮想含めたデバイス全一覧を取得したい場合は
`ls /sys/class/net/` で確認できる。
ボンディングIFのみであれば`ls /proc/net/bonding/`。
ブリッジデバイスは`brctl show`。
```console
[root@dango01 ~]# ls -l /sys/class/net/
bond0
bond0.1111
ens0
ens1
```
物理的にマシンに刺さっているデバイス名のみ欲しい場合は以下。
```console
[root@dango01 ~]# for DEV in `find /sys/devices -name net | grep -v virtual`; do ls $DEV/; done
ens0
ens1
```
<br></br>
`ethtool`を使うとIFの状態を確認できる。
```console
[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 ~]$
```
```console
[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 ~]$


[root@dango01 ~]# ethtool -i ens1
driver: ice
version: 5.14.0-427.13.1.el9_4.x86_64
firmware-version: 4.30 0x8001af27 1.3429.0
expansion-rom-version: 
bus-info: 0000:12:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: yes
```
`-i` でバージョン等も確認できる.
モノが対応していれば、`-m` を付けることでモジュールの詳細を確認できる。

# NICのドライバ情報確認
```dmesg | grep インターフェース名```
でドライバ確認。
```console
[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
```
⇒iceドライバが使われている。

```console
[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
```
⇒igbドライバが使われている。
```modinfo ドライバ名```
で確認。
```console
[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
```
```console
[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 version`やら`-F description`でパラメータの指定可。

# (おまけ)OS基本情報
カーネルの起動オプション確認。
GRUBなどのブートローダによってカーネルに渡されるパラメータ。
```console
[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
```
カーネルのバージョン確認
```console
[root@host01 ~]# uname -r
3.10.0-1160.el7.x86_64
```
CentOS/RHELであれば
```console
[dango@host01 ~]$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
```
でOSバージョンの確認ができるが、
`/etc/redhat-release`はファイルで、このファイルが含まれるパッケージを調べたのが以下。割と色々見れる。
```console
[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`というパッケージがあることがわかる。
パッケージに含まれるファイルをみてみる。
```console
[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`もわりとまとめてみられる。
```console
[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 ~]#
```

いじょ。