硬體資訊
在Linux系統中,有很多命令可以用於查詢主機的硬體資訊,有些命令僅僅針對於特定的硬體部件,比如cpu,記憶體等,而有些命令可以查詢很多的硬體資訊。
這篇帖子簡單地帶大家瞭解一下最常用的查詢各種硬體資訊的命令,其中包括lscpu、hwinfo、lshw、dmidecode、lspci等等。
1. lscpu
lscpu命令可以用來查詢處理器cpu的詳細資訊,只需要簡單地輸入lscpu即可,如下所示,它本身也沒有提供更多選項和功能可供選擇。
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 23
Stepping: 10
CPU MHz: 1998.000
BogoMIPS: 5302.48
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 2048K
NUMA node0 CPU(s): 0-3
2. lshw - 顯示硬體資訊列表
這個命令用途廣泛,它可以根據你的需求以詳細或概要的形式列出許多個不同硬體的引數資訊,其中包括cpu,記憶體,磁碟,usb控制器,網路卡等等,lshw實質上是從/proc檔案目錄下的不同檔案中提取對應的硬體資訊。
$ sudo lshw -short
H/W path Device Class Description
===================================================
system ()
/0 bus DG35EC
/0/0 processor Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz
/0/0/1 memory 2MiB L2 cache
/0/0/3 memory 32KiB L1 cache
/0/2 memory 32KiB L1 cache
/0/4 memory 64KiB BIOS
/0/14 memory 8GiB System Memory
/0/14/0 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
/0/14/1 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
/0/14/2 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
/0/14/3 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
/0/100 bridge 82G35 Express DRAM Controller
/0/100/2 display 82G35 Express Integrated Graphics Controller
/0/100/2.1 display 82G35 Express Integrated Graphics Controller
/0/100/19 eth0 network 82566DC Gigabit Network Connection
/0/100/1a bus 82801H (ICH8 Family) USB UHCI Controller #4
/0/100/1a.1 bus 82801H (ICH8 Family) USB UHCI Controller #5
/0/100/1a.7 bus 82801H (ICH8 Family) USB2 EHCI Controller #2
/0/100/1b multimedia 82801H (ICH8 Family) HD Audio Controller
/0/100/1c bridge 82801H (ICH8 Family) PCI Express Port 1
/0/100/1c.1 bridge 82801H (ICH8 Family) PCI Express Port 2
/0/100/1c.2 bridge 82801H (ICH8 Family) PCI Express Port 3
/0/100/1c.2/0 storage JMB368 IDE controller
/0/100/1d bus 82801H (ICH8 Family) USB UHCI Controller #1
/0/100/1d.1 bus 82801H (ICH8 Family) USB UHCI Controller #2
/0/100/1d.2 bus 82801H (ICH8 Family) USB UHCI Controller #3
/0/100/1d.7 bus 82801H (ICH8 Family) USB2 EHCI Controller #1
/0/100/1e bridge 82801 PCI Bridge
/0/100/1e/5 bus FW322/323 [TrueFire] 1394a Controller
/0/100/1f bridge 82801HB/HR (ICH8/R) LPC Interface Controller
/0/100/1f.2 storage 82801H (ICH8 Family) 4 port SATA Controller [IDE mode]
/0/100/1f.3 bus 82801H (ICH8 Family) SMBus Controller
/0/100/1f.5 storage 82801HR/HO/HH (ICH8R/DO/DH) 2 port SATA Controller [IDE m
/0/1 scsi3 storage
/0/1/0.0.0 /dev/sda disk 500GB ST3500418AS
/0/1/0.0.0/1 /dev/sda1 volume 70GiB Windows NTFS volume
/0/1/0.0.0/2 /dev/sda2 volume 395GiB Extended partition
/0/1/0.0.0/2/5 /dev/sda5 volume 97GiB HPFS/NTFS partition
/0/1/0.0.0/2/6 /dev/sda6 volume 97GiB Linux filesystem partition
/0/1/0.0.0/2/7 /dev/sda7 volume 1952MiB Linux swap / Solaris partition
/0/1/0.0.0/2/8 /dev/sda8 volume 198GiB Linux filesystem partition
/0/3 scsi4 storage
/0/3/0.0.0 /dev/cdrom disk DVD RW DRU-190A
點選下面的帖子,可以對lshw有更多的瞭解。
在Linux上使用lshw命令獲取硬體資訊
3. hwinfo - Hardware Information
hwinfo同樣是一個使用非常廣泛的硬體資訊查詢命令,類似於lshw,它同樣可以詳細或概要地報告多個部件的硬體資訊,但不同的是,它有時可以給出比lshw更多的資訊。
$ hwinfo --short
cpu:
Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2000 MHz
Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2000 MHz
Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2666 MHz
Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2666 MHz
keyboard:
/dev/input/event2 AT Translated Set 2 keyboard
mouse:
/dev/input/mice Microsoft Basic Optical Mouse v2.0
graphics card:
Intel 965G-1
Intel 82G35 Express Integrated Graphics Controller
sound:
Intel 82801H (ICH8 Family) HD Audio Controller
storage:
Intel 82801H (ICH8 Family) 4 port SATA IDE Controller
Intel 82801H (ICH8 Family) 2 port SATA IDE Controller
JMicron JMB368 IDE controller
network:
eth0 Intel 82566DC Gigabit Network Connection
network interface:
eth0 Ethernet network interface
lo Loopback network interface
disk:
/dev/sda ST3500418AS
partition:
/dev/sda1 Partition
/dev/sda2 Partition
/dev/sda5 Partition
/dev/sda6 Partition
/dev/sda7 Partition
/dev/sda8 Partition
cdrom:
/dev/sr0 SONY DVD RW DRU-190A
usb controller:
Intel 82801H (ICH8 Family) USB UHCI Controller #4
Intel 82801H (ICH8 Family) USB UHCI Controller #5
Intel 82801H (ICH8 Family) USB2 EHCI Controller #2
Intel 82801H (ICH8 Family) USB UHCI Controller #1
Intel 82801H (ICH8 Family) USB UHCI Controller #2
Intel 82801H (ICH8 Family) USB UHCI Controller #3
Intel 82801H (ICH8 Family) USB2 EHCI Controller #1
bios:
BIOS
... TRUNCATED ...
點選下面的連結可以檢視更多關於hwinfo的資訊。
在Linux上使用hwinfo命令獲取硬體資訊
4. lspci - 顯示pci匯流排相關資訊
lscpi命令可以列出pci匯流排上資訊,以及所有連線到pci匯流排上的裝置資訊,比如VGA介面卡,顯示卡,網路卡,usb埠,sata控制器等等。
$ lspci
00:00.0 Host bridge: Intel Corporation 82G35 Express DRAM Controller (rev 03)
00:02.0 VGA compatible controller: Intel Corporation 82G35 Express Integrated Graphics Controller (rev 03)
00:02.1 Display controller: Intel Corporation 82G35 Express Integrated Graphics Controller (rev 03)
00:19.0 Ethernet controller: Intel Corporation 82566DC Gigabit Network Connection (rev 02)
00:1a.0 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #4 (rev 02)
00:1a.1 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #5 (rev 02)
00:1a.7 USB controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #2 (rev 02)
00:1b.0 Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller (rev 02)
00:1c.0 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 1 (rev 02)
00:1c.1 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 2 (rev 02)
00:1c.2 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 3 (rev 02)
00:1d.0 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #1 (rev 02)
00:1d.1 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #2 (rev 02)
00:1d.2 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #3 (rev 02)
00:1d.7 USB controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #1 (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev f2)
00:1f.0 ISA bridge: Intel Corporation 82801HB/HR (ICH8/R) LPC Interface Controller (rev 02)
00:1f.2 IDE interface: Intel Corporation 82801H (ICH8 Family) 4 port SATA Controller [IDE mode] (rev 02)
00:1f.3 SMBus: Intel Corporation 82801H (ICH8 Family) SMBus Controller (rev 02)
00:1f.5 IDE interface: Intel Corporation 82801HR/HO/HH (ICH8R/DO/DH) 2 port SATA Controller [IDE mode] (rev 02)
03:00.0 IDE interface: JMicron Technology Corp. JMB368 IDE controller
04:05.0 FireWire (IEEE 1394): LSI Corporation FW322/323 [TrueFire] 1394a Controller (rev 70)
可以使用grep命令篩選出特定的裝置資訊。
$ lspci -v | grep "VGA" -A 12
5. lsscsi - 列出scsi裝置資訊
列出scsi/sata裝置資訊,比如硬碟驅動器,光碟驅動器。
$ lsscsi
[3:0:0:0] disk ATA ST3500418AS CC38 /dev/sda
[4:0:0:0] cd/dvd SONY DVD RW DRU-190A 1.63 /dev/sr0
6. lsusb - 列出usb匯流排資訊,及裝置資訊
該命令可以顯示USB控制器及連線到控制的裝置資訊。預設情況下,只顯示概要資訊,可以透過-v選項指示其顯示更多的硬體資訊。
$ lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 002: ID 045e:00cb Microsoft Corp. Basic Optical Mouse v2.0
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
上面資訊顯示,在該系統中,有一個usb埠正被滑鼠占用。
7. Inxi
inxi命令是一個大的bash指令碼檔案,其透過從不同的資訊來源和命令中獲取硬體資訊,最後能給出一個顏色高亮的,適合於非專業人員閱讀的硬體資訊報告。
$ inxi -Fx
8. lsblk - 列出塊裝置資訊
列出所有塊裝置資訊,其中包括硬碟分割槽資訊,以及其他儲存裝置,如光碟,快閃記憶體等。
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 70G 0 part
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 97.7G 0 part /media/4668484A68483B47
├─sda6 8:6 0 97.7G 0 part /
├─sda7 8:7 0 1.9G 0 part [SWAP]
└─sda8 8:8 0 198.5G 0 part /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
sr0 11:0 1 1024M 0 rom
9. df - 顯示檔案系統的磁碟空間資訊
報告各種掛載的檔案系統資訊,其中包括掛載點,已用的,可用的磁碟空間。
$ df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 104G 26G 73G 26% /
none 4.1k 0 4.1k 0% /sys/fs/cgroup
udev 4.2G 4.1k 4.2G 1% /dev
tmpfs 837M 1.6M 835M 1% /run
none 5.3M 0 5.3M 0% /run/lock
none 4.2G 13M 4.2G 1% /run/shm
none 105M 21k 105M 1% /run/user
/dev/sda8 210G 149G 51G 75% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda5 105G 31G 75G 30% /media/4668484A68483B47
10. pydf - python版本的df
一個增強型的python版的df命令,可以以不同的顏色顯示所查詢的資訊,看起來比df更好看。
$ pydf
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 96G 23G 68G 24.4 [#.....] /
/dev/sda8 195G 138G 47G 70.6 [####..] /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda5 98G 28G 69G 29.2 [##....] /media/4668484A68483B47
11. fdisk
fdisk命令可以用來修改硬碟分割槽表資訊,也可以用來顯示硬碟分割槽表資訊
$ sudo fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x30093008
Device Boot Start End Blocks Id System
/dev/sda1 * 63 146801969 73400953+ 7 HPFS/NTFS/exFAT
/dev/sda2 146802031 976771071 414984520+ f W95 Ext'd (LBA)
/dev/sda5 146802033 351614654 102406311 7 HPFS/NTFS/exFAT
/dev/sda6 351614718 556427339 102406311 83 Linux
/dev/sda7 556429312 560427007 1998848 82 Linux swap / Solaris
/dev/sda8 560429056 976771071 208171008 83 Linux
12. mount
mount命令可以用來掛載裝置,當然也可以用來檢視系統中裝置的掛載情況。
$ mount | column -t
/dev/sda6 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
/dev/sda8 on /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 type ext4 (rw,nosuid,nodev,errors=remount-ro)
/dev/sda5 on /media/4668484A68483B47 type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=enlightened)
同樣,可以使用grep命令來篩選出想看的檔案系統資訊。
$ mount | column -t | grep ext
13. free - 檢視RAM資訊
檢視系統中RAM的使用情況,包括已使用空間,未使用空間,以及總空間。
$ free -m
total used free shared buffers cached
Mem: 7975 5865 2110 0 24 622
-/+ buffers/cache: 5218 2757
Swap: 1951 921 1030
14. dmidecode
dmidecode命令不同於其他的命令,它是透過讀取SMBOIS資料結構(也稱為DMI表)中資料來提取硬體資訊。
# 顯示處理器資訊
$ sudo dmidecode -t processor
# 顯示記憶體資訊
$ sudo dmidecode -t memory
# 顯示bios資訊
$ sudo dmidecode -t bios
檢視man手冊獲取更多資訊。
15. /proc 檔案系統
在/proc目錄下的許多虛擬檔案包含了很多有關硬體引數及配置的資訊。
CPU、記憶體資訊
# cpu資訊
$ cat /proc/cpuinfo
# 記憶體資訊
$ cat /proc/meminfo
Linux核心資訊
$ cat /proc/version
Linux version 3.11.0-12-generic (buildd@allspice) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu7) ) #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013
SCSI/Sata裝置資訊
$ cat /proc/scsi/scsi
Attached devices:
Host: scsi3 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: ST3500418AS Rev: CC38
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
Vendor: SONY Model: DVD RW DRU-190A Rev: 1.63
Type: CD-ROM ANSI SCSI revision: 05
分割槽資訊
$ cat /proc/partitions
major minor #blocks name
8 0 488386584 sda
8 1 73400953 sda1
8 2 1 sda2
8 5 102406311 sda5
8 6 102406311 sda6
8 7 1998848 sda7
8 8 208171008 sda8
11 0 1048575 sr0
16. hdparm
hdparm命令可以獲取sata裝置如硬碟等裝置資訊。
$ sudo hdparm -i /dev/sda
/dev/sda:
Model=ST3500418AS, FwRev=CC38, SerialNo=9VMJXV1N
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
BuffType=unknown, BuffSize=16384kB, MaxMultSect=16, MultSect=16
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=976773168
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
AdvancedPM=no WriteCache=enabled
Drive conforms to: unknown: ATA/ATAPI-4,5,6,7
* signifies the current active mode
總結
每一個命令在獲取資訊的方式會稍微有些不同,在查詢某一裝置時,你也有可能要結合多個命令才能獲取你想要的硬體資訊。不過,這些命令都可以在大多數的linux發行版中找到,可以很容易地從預設的倉庫中獲取安裝。