如何在 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 次瀏覽

啟動您的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.