如何在 Linux 上查找硬盘规格/详细信息
Linux 附带各种命令来查找有关硬盘的信息。我推荐使用 hdparm 命令,它为现有 Linux ATA/IDE 设备驱动程序子系统支持的各种硬盘 ioctl 提供了命令行界面。此命令直接从驱动器读取/请求识别信息(如磁盘大小、描述等),这些信息以新的扩展格式显示。让我们看看各种 Linux 磁盘信息命令,它们用于在屏幕上打印硬盘驱动器详细信息。
教程详细信息 | |
---|---|
难度等级 | 简单的 |
Root 权限 | 是的 |
要求 | Linux 终端 |
类别 | 系统管理 |
操作系统兼容性 | Alma • Alpine • Arch • Debian • Fedora • Linux • macOS • Mint • openSUSE • pop!_os • RHEL • Rocky • Stream • SUSE • Ubuntu |
预计阅读时间 | 10 分钟 |
使用 lsblk 命令查看 Linux 硬盘信息
运行如下 lsblk 命令来列出有关所有可用或指定块设备的信息:
所以我有两个处于 RAID-1 模式且带有加密分区的 NVMe SSD:
# lsblk
# lsblk /dev/DISK
# lsblk /dev/sda
nvme0n1 259:0 0 953.9G 0 disk ├─nvme0n1p1 259:1 0 953M 0 part /boot/efi ├─nvme0n1p2 259:2 0 3.7G 0 part │ └─md0 9:0 0 3.7G 0 raid1 /boot └─nvme0n1p3 259:3 0 949.2G 0 part └─md1 9:1 0 949.1G 0 raid1 └─md1_crypt 253:0 0 949.1G 0 crypt ├─example-swap 253:1 0 119.2G 0 lvm [SWAP] └─example-root 253:2 0 829.9G 0 lvm / nvme1n1 259:4 0 953.9G 0 disk ├─nvme1n1p1 259:5 0 953M 0 part ├─nvme1n1p2 259:6 0 3.7G 0 part │ └─md0 9:0 0 3.7G 0 raid1 /boot └─nvme1n1p3 259:7 0 949.2G 0 part └─md1 9:1 0 949.1G 0 raid1 └─md1_crypt 253:0 0 949.1G 0 crypt ├─example-swap 253:1 0 119.2G 0 lvm [SWAP] └─example-root 253:2 0 829.9G 0 lvm /
另一个选择是运行以下 ls 命令来列出所有磁盘及其名称:
# ls -lF /dev/disk/by-id/
Linux 显示块设备如硬盘驱动器的属性
打开终端应用程序,然后输入 blkid 命令:
# blkid
/dev/sda1: UUID="35D0-69B0" TYPE="vfat" PARTUUID="50f81f2e-9c4c-43ce-896d-7a55bee67397" /dev/sda2: UUID="985b0131-765b-4d1e-94fa-8c86491dad4d" TYPE="ext4" PARTUUID="00c44b9a-47b7-4ad3-b5ed-66a011f924b1
使用 hdparm 命令在 Linux 上查找硬盘驱动器规格
打开终端并输入以下命令来查找有关 /dev/sda 的信息:
# hdparm -I /dev/sda
或者
$ sudo hdparm -I /dev/sda
这是我所看到的:
/dev/sda: ATA device, with non-removable media Model Number: ST3500630AS Serial Number: 9XXYZ845YZ Firmware Revision: 3.AAK Standards: Supported: 7 6 5 4 Likely used: 7 Configuration: Logical max current cylinders 16383 16383 heads 16 16 sectors/track 63 63 -- CHS current addressable sectors: 16514064 LBA user addressable sectors: 268435455 LBA48 user addressable sectors: 976773168 device size with M = 1024*1024: 476940 MBytes device size with M = 1000*1000: 500107 MBytes (500 GB) Capabilities: LBA, IORDY(can be disabled) Queue depth: 32 Standby timer values: spec'd by Standard, no device specific minimum R/W multiple sector transfer: Max = 16 Current = 16 Recommended acoustic management value: 254, current value: 0 DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6 Cycle time: min=120ns recommended=120ns PIO: pio0 pio1 pio2 pio3 pio4 Cycle time: no flow control=120ns IORDY flow control=120ns Commands/features: Enabled Supported: * SMART feature set Security Mode feature set * Power Management feature set * Write cache * Look-ahead * Host Protected Area feature set * WRITE_BUFFER command * READ_BUFFER command * DOWNLOAD_MICROCODE SET_MAX security extension * 48-bit Address feature set * Device Configuration Overlay feature set * Mandatory FLUSH_CACHE * FLUSH_CACHE_EXT * SMART error logging * SMART self-test * General Purpose Logging feature set * SATA-I signaling speed (1.5Gb/s) * SATA-II signaling speed (3.0Gb/s) * Native Command Queueing (NCQ) * Phy event counters Device-initiated interface power management * Software settings preservation Security: Master password revision code = 65534 supported not enabled not locked frozen not expired: security count not supported: enhanced erase Checksum: correct
lshw 命令
您需要使用 apt-get 或 yum 命令安装 lshw 命令。要显示系统中的所有磁盘和存储控制器,请输入:
# lshw -class disk -class storage
从我的 Linux 机器:
*-storage description: Mass storage controller product: 5-in-1 Multimedia Card Reader (SD/MMC/MS/MS PRO/xD) vendor: Texas Instruments physical id: 1.2 bus info: pci@0000:03:01.2 version: 00 width: 32 bits clock: 33MHz capabilities: storage pm bus_master cap_list configuration: driver=tifm_7xx1 latency=64 maxlatency=4 mingnt=7 resources: irq:19 memory:f19fa000-f19fafff *-storage description: SATA controller product: 5 Series/3400 Series Chipset 6 port SATA AHCI Controller vendor: Intel Corporation physical id: 1f.2 bus info: pci@0000:00:1f.2 logical name: scsi0 logical name: scsi1 logical name: scsi2 version: 05 width: 32 bits clock: 66MHz capabilities: storage msi pm ahci_1.0 bus_master cap_list emulated configuration: driver=ahci latency=0 resources: irq:32 ioport:6e70(size=8) ioport:6e78(size=4) ioport:6e80(size=8) ioport:6e88(size=4) ioport:6ea0(size=32) memory:fed1e000-fed1e7ff *-disk:0 description: ATA Disk product: TOSHIBA MK5061GS vendor: Toshiba physical id: 0 bus info: scsi@0:0.0.0 logical name: /dev/sda version: MF00 serial: 71XYZYYYY size: 465GiB (500GB) capabilities: partitioned partitioned:dos configuration: ansiversion=5 signature=00025d42 *-cdrom description: DVD-RAM writer product: BD-RE UJ232A vendor: MATSHITA physical id: 1 bus info: scsi@1:0.0.0 logical name: /dev/cdrom logical name: /dev/cdrw logical name: /dev/dvd logical name: /dev/dvdrw logical name: /dev/scd0 logical name: /dev/sr0 logical name: /media/cdrom0 version: 1.10 capabilities: removable audio cd-r cd-rw dvd dvd-r dvd-ram configuration: ansiversion=5 mount.fstype=udf mount.options=ro,nosuid,nodev,noexec,relatime,utf8 state=mounted status=ready *-medium physical id: 0 logical name: /dev/cdrom logical name: /media/cdrom0 configuration: mount.fstype=udf mount.options=ro,nosuid,nodev,noexec,relatime,utf8 state=mounted *-disk:1 description: ATA Disk product: ST9500420ASG vendor: Seagate physical id: 0.0.0 bus info: scsi@2:0.0.0 logical name: /dev/sdb version: 0004 serial: 5VXYZYYYY size: 465GiB (500GB) capabilities: gpt-1.00 partitioned partitioned:gpt configuration: ansiversion=5 guid=8795c9fc-5238-11e1-84e2-00216aca9b10
仅查找 Linux 磁盘名称
以下 lshw 命令将快速列出已安装的磁盘,包括 CD/DVD/BD 驱动程序:
# lshw -short -C disk
示例输出:
H/W path Device Class Description ======================================================== /0/100/1f.2/0 /dev/sda disk 500GB TOSHIBA MK5061GS /0/100/1f.2/1 /dev/cdrom disk BD-RE UJ232A /0/100/1f.2/1/0 /dev/cdrom disk /0/100/1f.2/0.0.0 /dev/sdb disk 500GB ST9500420ASG
另一个选择是运行 fdisk 命令,如下所示:
# fdisk -l
使用grep 命令/ egrep 命令过滤掉环回和其他不需要的设备:
# fdisk -l | grep '^Disk /dev/'
# fdisk -l | grep '^Disk /dev/' | egrep -v '/dev/(loop|mapper|md)'
Disk /dev/nvme0n1: 953.89 GiB, 1024209543168 bytes, 2000409264 sectors Disk /dev/nvme1n1: 953.89 GiB, 1024209543168 bytes, 2000409264 sectors
Linux GUI 磁盘实用程序
Gnome 用户可以使用 gnome-disk-utility/gnome-disks 来做以下事情:
- 获取有关已安装磁盘及其当前运行状况的信息。
- 管理和配置磁盘驱动器。
- 配置媒体。
- 设置软件 RAID 设备等等。
键入以下命令或通过访问“应用程序”>“系统工具”>“磁盘实用程序”来启动“磁盘实用程序”:
# palimpsest
或
# gnome-disks
图 01:Linux 列出硬盘 GUI 工具和命令 - 点击放大
图02:硬盘的Samrtdata
smartctl 命令
smartctl 命令充当 Linux 和类 Unix 操作系统下 SMART 磁盘的控制和监视实用程序。输入以下命令获取有关 /dev/sda(SATA 磁盘)的信息:
# smartctl -d ata -a -i /dev/sda
从我的笔记本电脑:
smartctl 5.40 2010-07-12 r3124 [x86_64-unknown-linux-gnu] (local build) Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge.net === START OF INFORMATION SECTION === Device Model: TOSHIBA MK5061GSYF Serial Number: 71XXXYYZ Firmware Version: MF000D User Capacity: 500,107,862,016 bytes Device is: Not in smartctl database [for details use: -P showall] ATA Version is: 8 ATA Standard is: Exact ATA specification draft version not indicated Local Time is: Fri Feb 24 05:27:29 2012 IST SMART support is: Available - device has SMART capability. SMART support is: Enabled === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED General SMART Values: Offline data collection status: (0x00) Offline data collection activity was never started. Auto Offline Data Collection: Disabled. Self-test execution status: ( 36) The self-test routine was interrupted by the host with a hard or soft reset. Total time to complete Offline data collection: ( 120) seconds. Offline data collection capabilities: (0x5b) SMART execute Offline immediate. Auto Offline data collection on/off support. Suspend Offline collection upon new command. Offline surface scan supported. Self-test supported. No Conveyance Self-test supported. Selective Self-test supported. SMART capabilities: (0x0003) Saves SMART data before entering power-saving mode. Supports SMART auto save timer. Error logging capability: (0x01) Error logging supported. General Purpose Logging supported. Short self-test routine recommended polling time: ( 2) minutes. Extended self-test routine recommended polling time: ( 136) minutes. SCT capabilities: (0x003d) SCT Status supported. SCT Error Recovery Control supported. SCT Feature Control supported. SCT Data Table supported. SMART Attributes Data Structure revision number: 128 Vendor Specific SMART Attributes with Thresholds: ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 1 Raw_Read_Error_Rate 0x000b 100 100 050 Pre-fail Always - 0 3 Spin_Up_Time 0x0027 100 100 001 Pre-fail Always - 1650 5 Reallocated_Sector_Ct 0x0033 100 100 050 Pre-fail Always - 0 9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 34237 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 120 191 G-Sense_Error_Rate 0x0032 100 100 000 Old_age Always - 42 192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 23 193 Load_Cycle_Count 0x0032 099 099 000 Old_age Always - 13971 194 Temperature_Celsius 0x0022 100 100 000 Old_age Always - 39 (Lifetime Min/Max 21/48) 199 UDMA_CRC_Error_Count 0x0032 100 100 000 Old_age Always - 3536073 200 Multi_Zone_Error_Rate 0x0032 100 100 000 Old_age Always - 9143982 240 Head_Flying_Hours 0x0032 099 099 000 Old_age Always - 28415 241 Total_LBAs_Written 0x0032 100 100 000 Old_age Always - 741418060 242 Total_LBAs_Read 0x0032 100 100 000 Old_age Always - 450708673 254 Free_Fall_Sensor 0x0032 100 100 000 Old_age Always - 0 SMART Error Log Version: 1 No Errors Logged SMART Self-test log structure revision number 1 Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error # 1 Short offline Interrupted (host reset) 40% 343 - # 2 Short offline Completed without error 00% 186 - # 3 Short offline Completed without error 00% 71 - # 4 Short offline Completed without error 00% 0 - # 5 Short offline Completed without error 00% 0 - SMART Selective self-test log data structure revision number 1 SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS 1 0 0 Not_testing 2 0 0 Not_testing 3 0 0 Not_testing 4 0 0 Not_testing 5 0 0 Not_testing Selective self-test flags (0x0): After scanning selected spans, do NOT read-scan remainder of disk. If Selective self-test is pending on power-up, resume after 0 minute delay.
关于 RAID 和 SCSI 磁盘的说明
对基于 SCSI 和硬件 RAID 的设备尝试以下命令:
- sdparm 命令——获取SCSI/SATA设备信息。
- scsi_id 命令–通过 SCSI INQUIRY 重要产品数据 (VPD)查询SCSI 设备。
- 使用smartctl 检查Adaptec RAID控制器后面的磁盘
- 使用smartctl 检查3Ware RAID卡后面的硬盘
结论
您了解了如何在 Linux 上查找硬盘驱动器信息。要获取有关硬盘的更多信息,请参阅我们的其他文章和教程:
- 如何在 Linux 或 UNIX 中查找或了解硬盘大小
- 如何:Linux 检查 IDE/SATA 硬盘传输速度
- Linux:使用 hddtemp 监控硬盘温度
- 如何测试我的 Linux 服务器 SCSI/SATA 硬盘是否出现故障?
- Linux:如何备份硬盘分区表(MBR)
- Linux 使用命令行查找 NVMe SSD 温度
- 如何通过 Shell 提示符查找硬盘每分钟转速 (RPM)
- Linux 检查 IDE / SATA SSD 硬盘传输速度
- Linux 和 Unix 使用 dd 命令测试磁盘 I/O 性能
还可以使用 man 命令或 help 命令阅读以下手册页,以了解 Linux 下的硬盘规格:
$ man lsblk
$ man blkid
$ man hdparm
$ man lshw
$ man fdisk
$ man smartctl
- 测试 Linux 服务器 SCSI/SATA/SSD 硬盘是否出现故障
- Linux / UNIX:Smartctl 检查 3Ware RAID 卡后面的硬盘
- Linux 使用 smartctl 检查 Adaptec RAID 控制器后面的磁盘
- 在 Linux 或 UNIX 操作系统下使用 smartd 监控硬盘健康状况
- FreeBSD:使用 smartd 工具获取/读取硬盘温度
- Linux 使用 hddtemp 监控硬盘温度
- Linux 命令查找 SATA 链接速度(如 1.5 / 3.0 / 6.0 Gbps)[硬盘]
- 如何在 Linux 上查找硬盘规格/详细信息
- FreeBSD insatll smartctl top 检查硬盘健康状况