如何在 Linux 中检查硬盘的开机时间 -
在这篇如何在 Linux 中检查硬盘驱动器开机时间的文章中,您将了解如何通过了解系统存储设备的“开机”时间(运行时)、读写次数或坏块等详细信息来防止灾难,确定硬盘的整体健康状况和老化情况。
对于此任务最有用的工具是 smartctl
命令,该命令已在 Linux 上通过 smartmontools 软件包找到并可供安装。在本教程中,我们将通过一些命令示例来了解如何确定当前硬盘驱动器的状态和整体运行状况。您还将了解如何在主要 Linux 发行版上安装 smartmontools 软件包。
在本教程中您将学习:
如何在主要 Linux 发行版上安装 smartmontools
如何查看硬盘的开机时间(总运行时间)
如何使用
smartctl
检查硬盘的整体运行状况
在主要 Linux 发行版上安装 smartmontools
要在 Linux 上使用 smartctl
命令,您首先需要安装 smartmontools
软件包。您可以使用下面适当的命令通过系统的包管理器安装该程序。
要在 Ubuntu、Debian 和 Linux Mint 上安装 smartmontools:
$ sudo apt install smartmontools
要在 CentOS、Fedora、AlmaLinux 和 Red Hat 上安装 smartmontools:
$ sudo dnf install smartmontools
要在 Arch Linux 和 Manjaro 上安装 smartmontools:
$ sudo pacman -S smartmontools
安装软件包后,请继续阅读以下部分,了解如何使用 smartctl
命令。
查看硬盘统计信息和健康状况
在这些示例中,我们使用 /dev/sda
作为硬盘驱动器。您可以将此设备文件替换为您想要测试的任何磁盘的文件。
要查看硬盘驱动器的“开机”时间(总运行时间),请使用以下命令。
# smartctl --attributes "${disk}" | grep Power_On_Hours Power_On_Hours 0x0032 087 087 000 Old_age Always - 12131
要检查硬盘驱动器的整体运行状况,我们可以使用
-H
选项。# smartctl -H /dev/sda === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED
smartctl 命令还允许系统管理员运行自检以确定硬盘驱动器的状况。要启动运行状况自检,请使用以下参数之一运行以下命令:
offline, short, long, conveyance, force, vendor,N, select,M-N, pending,N, afterselect,[on|off]
# smartctl -t short /dev/sda Please wait 1 minutes for test to complete.
运行上述命令后,
smartctl
命令将指示您需要等待测试完成的时间。稍后可以通过以下方式检索自检结果:# smartctl -l selftest /dev/sda smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.14.8-200.fc20.x86_64] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF READ SMART DATA SECTION === SMART Self-test log structure revision number 1 Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error # 1 Vendor (0x50) Completed without error 00% 5007 - # 2 Offline Completed without error 00% 5006 -
可以通过以下方式获取有关硬盘驱动器的最全面的健康状态信息:
# smartctl --xall /dev/sda
这将打印出通用设备统计表和物理事件计数器表:
Device Statistics (GP Log 0x04) Page Offset Size Value Description 1 ===== = = == General Statistics (rev 2) == 1 0x008 4 3878 Lifetime Power-On Resets 1 0x010 4 5007 Power-on Hours 1 0x018 6 13095790289 Logical Sectors Written 1 0x020 6 677113980 Number of Write Commands 1 0x028 6 6489046492 Logical Sectors Read 1 0x030 6 74059526 Number of Read Commands 4 ===== = = == General Errors Statistics (rev 1) == 4 0x008 4 0 Number of Reported Uncorrectable Errors 4 0x010 4 0 Resets Between Cmd Acceptance and Completion 6 ===== = = == Transport Statistics (rev 1) == 6 0x008 4 23933 Number of Hardware Resets 6 0x010 4 10275 Number of ASR Events 6 0x018 4 0 Number of Interface CRC Errors 7 ===== = = == Solid State Device Statistics (rev 1) == 7 0x008 1 0 Percentage Used Endurance Indicator SATA Phy Event Counters (GP Log 0x11) ID Size Value Description 0x0001 4 0 Command failed due to ICRC error 0x0004 4 0 R_ERR response for host-to-device data FIS 0x0007 4 0 R_ERR response for host-to-device non-data FIS 0x0008 4 0 Device-to-host non-data FIS retries 0x0009 4 1 Transition from drive PhyRdy to drive PhyNRdy 0x000a 4 2 Device-to-host register FISes sent due to a COMRESET 0x000b 4 0 CRC errors within host-to-device FIS 0x000d 4 0 Non-CRC errors within host-to-device FIS 0x000f 4 0 R_ERR response for host-to-device data FIS, CRC 0x0010 4 0 R_ERR response for host-to-device data FIS, non-CRC 0x0012 4 0 R_ERR response for host-to-device non-data FIS, CRC 0x0013 4 0 R_ERR response for host-to-device non-data FIS, non-CRC
结束语
在本如何检查硬盘驱动器开机时间教程中,我们学习了如何查看硬盘驱动器的开机时间、其寿命和整体运行状况。我们还了解了如何在任何主要 Linux 发行版上使用 smartctl
对硬盘执行不同类型的测试。监控硬盘驱动器的运行状况是系统管理的重要组成部分,可以帮助预测即将发生的故障。