如何在 Linux 硬盘上查找坏扇区


Badblocks 是一个 Linux 实用程序,用于评估磁盘驱动器上的不健康扇区。它会创建一个这些扇区的列表,可以与 mkfs 等其他应用程序一起使用,这样这些扇区就不会在某些时候被使用,因此不会损坏数据。本文解释了如何找到 Linux 硬盘上的坏扇区(即坏块)。

要获取有关计算机上块设备的信息,请使用以下命令:

$ lsblk

检查坏扇区

有很多复杂的可用方法可以查找坏块。最常用的方法如下所示:

要获取有关坏块状态的信息,请在 Ubuntu 上安装以下软件包,如下所示:

$ sudo apt-get install smartmontools

示例输出应如下所示:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
   s-nail
Suggested packages:
   exim4 | mail-transport-agent gsmartcontrol smart-notifier
The following NEW packages will be installed:
   s-nail smartmontools
0 upgraded, 2 newly installed, 0 to remove and 284 not upgraded.
Need to get 795 kB of archives.
After this operation, 2,398 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 s-nail amd64 14.8.6-1 [353 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 smartmontools amd64 6.4+svn4214-1 [442 kB]
Fetched 795 kB in 1s (541 kB/s)
Selecting previously unselected package s-nail.
(Reading database ... 174772 files and directories currently installed.)
Preparing to unpack .../s-nail_14.8.6-1_amd64.deb ...
Unpacking s-nail (14.8.6-1) ...
.............................................................................................

要获取有关 smartctl 的更多信息,请使用以下命令:

$ smartctl -h

示例输出应如下所示:

smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.4.0-31-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

Usage: smartctl [options] device

============================================ SHOW INFORMATION OPTIONS =====

   -h, --help, --usage
   Display this help and exit

   -V, --version, --copyright, --license
   Print license, copyright, and version information and exit

   -i, --info
   Show identity information for device

   --identify[=[w][nvb]]
   Show words and bits from IDENTIFY DEVICE data (ATA)

   -g NAME, --get=NAME
   Get device setting: all, aam, apm, lookahead, security, wcache, rcache, wcreorder

   -a, --all
   Show all SMART information for device

   -x, --xall
   Show all information for device

   --scan
   Scan for devices

   --scan-open
   Scan for devices and try to open each device

================================== SMARTCTL RUN-TIME BEHAVIOR OPTIONS =====

   -q TYPE, --quietmode=TYPE (ATA)
      Set smartctl quiet mode to one of: errorsonly, silent, noserial

   -d TYPE, --device=TYPE
      Specify device type to one of: ata, scsi, sat[,auto][,N][+TYPE], usbcypress[,X], usbjmicron[,p][,x][,N],    usbsunplus, marvell, areca,N/E, 3ware,N, hpt,L/M/N, megaraid,N, aacraid,H,L,ID, cciss,N, auto, test

   -T TYPE, --tolerance=TYPE (ATA)
      Tolerance: normal, conservative, permissive, verypermissive

   -b TYPE, --badsum=TYPE (ATA)
      Set action on bad checksum to one of: warn, exit, ignore

   -r TYPE, --report=TYPE
      Report transactions (see man page)

   -n MODE, --nocheck=MODE (ATA)
      No check if: never, sleep, standby, idle (see man page)

.........................................................................................

验证硬盘健康状况

要验证硬盘健康状况,请使用以下命令:

$ sudo smartctl -H /dev/sda

示例输出应如下所示:

smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.4.0-31-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

如果上述结果显示故障信息,请使用以下命令扫描坏块。

$ sudo badblocks -v /dev/sdb

检查硬盘需要几分钟时间。在我的例子中,它给出了以下结果:

Checking blocks 0 to 3595263
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found. (0/0/0 errors)

恭喜!现在,您知道“如何在 Linux 硬盘上查找坏扇区(即坏块)”了。我们将在下一篇文章中学习更多关于这些命令的信息。继续关注!

更新于:2019年10月22日

893 次浏览

启动您的职业生涯

通过完成课程获得认证

开始
广告