Linux 硬件操作命令汇总

发布时间: 更新时间: 总字数:1897 阅读时间:4m 作者: 分享

Linux 硬件操作命令汇总

获取硬件信息

  • iostat
iostat -xm -o JSON /dev/sdb |grep disk_device
iostat -x 1 2 -o JSON /dev/sdb
  • dmidecode
$ dmidecode -t 1
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0100, DMI type 1, 27 bytes
System Information
	Manufacturer: Alibaba Cloud
	Product Name: Alibaba Cloud ECS
	Version: pc-i440fx-2.1
	Serial Number: 702ebfc5-005d-493f-9146-441f447a2529
	UUID: 702EBFC5-005D-493F-9146-441F447A2529
	Wake-up Type: Power Switch
	SKU Number: Not Specified
	Family: Not Specified
  • lshw
lshw
$ yum install -y lshw
$ lshw
a1.xiexianbin.cn
    description: Computer
    product: Alibaba Cloud ECS
    vendor: Alibaba Cloud
    version: pc-i440fx-2.1
    serial: 702ebfc5-005d-493f-9146-441f447a2529
    width: 64 bits
    capabilities: smbios-2.8 dmi-2.8 vsyscall32
    configuration: boot=normal uuid=C5BF2E70-5D00-3F49-9146-441F447A2529
  *-core
       description: Motherboard
       physical id: 0
     *-firmware
          description: BIOS
          vendor: SeaBIOS
          physical id: 0
          version: 3288b3c
          date: 04/01/2014
          size: 96KiB
     *-cpu
          description: CPU
          product: Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
          vendor: Intel Corp.
          vendor_id: GenuineIntel
          physical id: 400
          bus info: cpu@0
          version: 6.79.1
          slot: CPU 0
          width: 64 bits
          capabilities: fpu fpu_exception wp 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 x86-64 constant_tsc rep_good nopl eagerfpu 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 ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt spec_ctrl intel_stibp
          configuration: cores=1 enabledcores=1 microcode=0 threads=2
     *-memory
          description: System Memory
          physical id: 1000
          size: 2GiB
          capacity: 2GiB
          capabilities: ecc
          configuration: errordetection=multi-bit-ecc
        *-bank
             description: DIMM RAM
             vendor: Alibaba Cloud
             physical id: 0
             slot: DIMM 0
             size: 2GiB
     *-pci
          description: Host bridge
          product: 440FX - 82441FX PMC [Natoma]
          vendor: Intel Corporation
          physical id: 100
          bus info: pci@0000:00:00.0
          version: 02
          width: 32 bits
          clock: 33MHz
        *-isa
             description: ISA bridge
             product: 82371SB PIIX3 ISA [Natoma/Triton II]
             vendor: Intel Corporation
             physical id: 1
             bus info: pci@0000:00:01.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: isa
             configuration: latency=0
        *-ide
             description: IDE interface
             product: 82371SB PIIX3 IDE [Natoma/Triton II]
             vendor: Intel Corporation
             physical id: 1.1
             bus info: pci@0000:00:01.1
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: ide isa_compat_mode bus_master
             configuration: driver=ata_piix latency=0
             resources: irq:0 ioport:1f0(size=8) ioport:3f6 ioport:170(size=8) ioport:376 ioport:c0c0(size=16)
        *-usb
             description: USB controller
             product: 82371SB PIIX3 USB [Natoma/Triton II]
             vendor: Intel Corporation
             physical id: 1.2
             bus info: pci@0000:00:01.2
             version: 01
             width: 32 bits
             clock: 33MHz
             capabilities: uhci bus_master
             configuration: driver=uhci_hcd latency=0
             resources: irq:11 ioport:c040(size=32)
           *-usbhost
                product: UHCI Host Controller
                vendor: Linux 3.10.0-862.14.4.el7.x86_64 uhci_hcd
                physical id: 1
                bus info: usb@1
                logical name: usb1
                version: 3.10
                capabilities: usb-1.10
                configuration: driver=hub slots=2 speed=12Mbit/s
              *-usb
                   description: Mouse
                   product: QEMU USB Tablet
                   vendor: QEMU
                   physical id: 1
                   bus info: usb@1:1
                   version: 0.00
                   serial: 42
                   capabilities: usb-2.00
                   configuration: driver=usbhid maxpower=100mA speed=12Mbit/s
        *-bridge
             description: Bridge
             product: 82371AB/EB/MB PIIX4 ACPI
             vendor: Intel Corporation
             physical id: 1.3
             bus info: pci@0000:00:01.3
             version: 03
             width: 32 bits
             clock: 33MHz
             capabilities: bridge
             configuration: driver=piix4_smbus latency=0
             resources: irq:9
        *-display
             description: VGA compatible controller
             product: GD 5446
             vendor: Cirrus Logic
             physical id: 2
             bus info: pci@0000:00:02.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: vga_controller rom
             configuration: driver=cirrus latency=0
             resources: irq:0 memory:fc000000-fdffffff memory:febd0000-febd0fff memory:febc0000-febcffff
        *-network
             description: Ethernet controller
             product: Virtio network device
             vendor: Red Hat, Inc.
             physical id: 3
             bus info: pci@0000:00:03.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: msix bus_master cap_list rom
             configuration: driver=virtio-pci latency=0
             resources: irq:10 ioport:c060(size=32) memory:febd1000-febd1fff memory:feb80000-febbffff
           *-virtio0
                description: Ethernet interface
                physical id: 0
                bus info: virtio@0
                logical name: eth0
                serial: 00:16:3e:08:ec:f1
                capabilities: ethernet physical
                configuration: broadcast=yes driver=virtio_net driverversion=1.0.0 ip=172.31.8.211 link=yes multicast=yes
        *-communication
             description: Communication controller
             product: Virtio console
             vendor: Red Hat, Inc.
             physical id: 4
             bus info: pci@0000:00:04.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: msix bus_master cap_list
             configuration: driver=virtio-pci latency=0
             resources: irq:11 ioport:c080(size=32) memory:febd2000-febd2fff
           *-virtio1 UNCLAIMED
                description: Virtual I/O device
                physical id: 0
                bus info: virtio@1
                configuration: driver=virtio_console
        *-scsi
             description: SCSI storage controller
             product: Virtio block device
             vendor: Red Hat, Inc.
             physical id: 5
             bus info: pci@0000:00:05.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: scsi msix bus_master cap_list
             configuration: driver=virtio-pci latency=0
             resources: irq:10 ioport:c000(size=64) memory:febd3000-febd3fff
           *-virtio2
                description: Virtual I/O device
                physical id: 0
                bus info: virtio@2
                logical name: /dev/vda
                size: 40GiB (42GB)
                capabilities: partitioned partitioned:dos
                configuration: driver=virtio_blk logicalsectorsize=512 sectorsize=512 signature=0008d73a
              *-volume
                   description: EXT4 volume
                   vendor: Linux
                   physical id: 1
                   bus info: virtio@2,1
                   logical name: /dev/vda1
                   logical name: /
                   logical name: /var/lib/docker/containers
                   logical name: /var/lib/docker/overlay2
                   version: 1.0
                   serial: eb448abb-3012-4d8d-bcde-94434d586a31
                   size: 39GiB
                   capacity: 39GiB
                   capabilities: primary bootable journaled extended_attributes large_files huge_files dir_nlink recover extents ext4 ext2 initialized
                   configuration: created=2017-10-15 23:18:59 filesystem=ext4 lastmountpoint=/ modified=2019-06-26 23:34:59 mount.fstype=ext4 mount.options=rw,relatime,data=ordered mounted=2019-06-26 15:35:03 state=mounted
        *-generic
             description: Unclassified device
             product: Virtio memory balloon
             vendor: Red Hat, Inc.
             physical id: 6
             bus info: pci@0000:00:06.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: bus_master
             configuration: driver=virtio-pci latency=0
             resources: irq:11 ioport:c0a0(size=32)
           *-virtio3 UNCLAIMED
                description: Virtual I/O device
                physical id: 0
                bus info: virtio@3
                configuration: driver=virtio_balloon
     *-pnp00:00
          product: PnP device PNP0b00
          physical id: 1
          capabilities: pnp
          configuration: driver=rtc_cmos
     *-pnp00:01
          product: PnP device PNP0303
          physical id: 2
          capabilities: pnp
          configuration: driver=i8042 kbd
     *-pnp00:02
          product: PnP device PNP0f13
          physical id: 3
          capabilities: pnp
          configuration: driver=i8042 aux
     *-pnp00:03
          product: PnP device PNP0700
          physical id: 4
          capabilities: pnp
     *-pnp00:04
          product: PnP device PNP0501
          physical id: 5
          capabilities: pnp
          configuration: driver=serial
  *-network:0
       description: Ethernet interface
       physical id: 1
       logical name: vethfe4b025
       serial: f2:27:43:49:86:e7
       size: 10Gbit/s
       capabilities: ethernet physical
       configuration: autonegotiation=off broadcast=yes driver=veth driverversion=1.0 duplex=full link=yes multicast=yes port=twisted pair speed=10Gbit/s
  *-network:1
       description: Ethernet interface
       physical id: 2
       logical name: docker0
       serial: 02:42:20:2b:43:9d
       capabilities: ethernet physical
       configuration: broadcast=yes driver=bridge driverversion=2.3 firmware=N/A ip=172.17.0.1 link=yes multicast=yes

GPU

  • VGA
$ lspci | grep -i vga
00:02.0 VGA compatible controller: Device 1234:1111 (rev 02)
00:06.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
00:07.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
  • NVIDIA GPU
$ lspci | grep -i nvidia
00:06.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
00:07.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
  • 显卡详细信息
$ lspci -v -s 00:06.0  # 00:06.0 位置代号
00:06.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1) (prog-if 00 [VGA controller])
	Subsystem: Dell GP102 [GeForce GTX 1080 Ti]
	Physical Slot: 6
	Flags: bus master, fast devsel, latency 0, IRQ 33
	Memory at fc000000 (32-bit, non-prefetchable) [size=16M]
	Memory at d0000000 (64-bit, prefetchable) [size=256M]
	Memory at f0000000 (64-bit, prefetchable) [size=32M]
	I/O ports at c000 [size=128]
	[virtual] Expansion ROM at fe000000 [disabled] [size=512K]
	Capabilities: [60] Power Management version 3
	Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
	Capabilities: [78] Express Legacy Endpoint, MSI 00
	Kernel driver in use: nvidia
	Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia

NVIDIA 工具

nvidia-smi(NVIDIA System Management Interface) 是基于 nvmlGPU 的系统管理接口,主要用于显卡的管理和状态监控。

$ nvidia-smi
Thu Sep 12 11:34:46 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.67       Driver Version: 460.67       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:00:06.0 Off |                  N/A |
| 32%   55C    P2   168W / 250W |   4693MiB / 11178MiB |    100%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:00:07.0 Off |                  N/A |
| 31%   55C    P2   170W / 250W |   4693MiB / 11178MiB |    100%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A     11973      C   /root/chrome                     4691MiB |
|    1   N/A  N/A     11973      C   /root/chrome                     4691MiB |
+-----------------------------------------------------------------------------+

# 实时刷新
$ nvidia-smi -l

# 获取型号和 UUID
$ nvidia-smi -L
GPU 0: GeForce GTX 1080 Ti (UUID: GPU-8c46c14a-b9f8-76cc-1ca0-578288422e7d)
GPU 1: GeForce GTX 1080 Ti (UUID: GPU-ea7ca19c-8e5e-82e2-3730-77eb4fbb5331)

# Json 格式,https://github.com/Cheedoong/xml2json
$ nvidia-smi -x -q | xml2json | jq

说明:

  • GPU:序号
  • Fan:显示风扇转速,数值在0到100之间;如果不是通过风扇冷却或者风扇故障,显示为 N/A
  • Name:GPU名称为 GeForce GTX
  • Temp:显卡内部的温度,单位是摄氏度
  • Perf:表征性能状态,范围在P0到P12之间,P0表示最大性能,P12表示状态最小性能
  • Persistence-M:关闭
  • Pwr:Usage/Cap:当前能耗 / 总能耗
  • Bus-Id:总线信息
  • Disp.A:Display Active,表示 GPU 的显示是否初始化
  • Memory Usage:显存使用量 / 总量
  • Volatile GPU-Util:浮动的 GPU 利用率
  • Uncorr. ECC:ECC相关
  • Compute M:计算模式
  • MIG M.

其他数据格式:

# help
$ nvidia-smi --help-query-gpu

# 获取 csv 格式数据
$ nvidia-smi --query-gpu=index,name,uuid,memory.used,memory.total --format=csv,noheader
0, GeForce GTX 1080 Ti, GPU-8c46c14a-b9f8-76cc-1ca0-578288422e7d, 4693 MiB, 11178 MiB
1, GeForce GTX 1080 Ti, GPU-ea7ca19c-8e5e-82e2-3730-77eb4fbb5331, 4693 MiB, 11178 MiB

$ nvidia-smi --query-gpu=timestamp,name,pci.bus_id,driver_version,pstate,pcie.link.gen.max,pcie.link.gen.current,temperature.gpu,utilization.gpu,utilization.memory,memory.total,memory.free,memory.used --format=csv
timestamp, name, pci.bus_id, driver_version, pstate, pcie.link.gen.max, pcie.link.gen.current, temperature.gpu, utilization.gpu [%], utilization.memory [%], memory.total [MiB], memory.free [MiB], memory.used [MiB]
2021/09/12 13:39:31.884, GeForce GTX 1080 Ti, 00000000:00:06.0, 460.67, P2, 3, 3, 55, 100 %, 73 %, 11178 MiB, 6485 MiB, 4693 MiB
2021/09/12 13:39:31.885, GeForce GTX 1080 Ti, 00000000:00:07.0, 460.67, P2, 3, 3, 55, 100 %, 73 %, 11178 MiB, 6485 MiB, 4693 MiB

$ nvidia-smi --query-gpu=index,name,serial,uuid,pci.bus_id,fan.speed,temperature.gpu,pstate,power.draw,power.limit,memory.used,memory.total,utilization.gpu --format=csv,noheader
0, GeForce GTX 1080 Ti, [N/A], GPU-8c46c14a-b9f8-76cc-1ca0-578288422e7d, 00000000:00:06.0, 32 %, 55, P2, 168.90 W, 250.00 W, 4693 MiB, 11178 MiB, 100 %
1, GeForce GTX 1080 Ti, [N/A], GPU-ea7ca19c-8e5e-82e2-3730-77eb4fbb5331, 00000000:00:07.0, 32 %, 55, P2, 170.57 W, 250.00 W, 4693 MiB, 11178 MiB, 100 %

Disk

  • 磁盘详情
apt install -y smartmontools
smartctl -i /dev/sdi
smartctl --json -i /dev/sdi
  • 容量
df -B1
df -B1GiB
df -B1GB
  • 区分是机械盘还是SSD/VNME

根据是否可以转判断。如上是机械盘为 1,否则为 0

$ cat /sys/block/sdi/queue/rotational
  • 分区
$ blkid /dev/vda1
/dev/vda1: UUID="eb448abb-3012-4d8d-bcde-94434d586a31" TYPE="ext4"
  • VNME 设备

NVME(Non-Volatile Memory Express)

$ apt install -y nvme-cli
$ nvme list

$ fdisk -l  | grep nvme
Disk /dev/nvme0n1: 3.65 TiB, 4000787030016 bytes, 7814037168 sectors
最新评论
加载中...
Home Archives Categories Tags