最後更新: 2019-10-15
介紹
Bad blocks <- 一些 read 唔到的 sector
A modern disk handles bad sectors internally (transparently remapping)
those sectors from a reserved set of sectors during writes.
目錄
- badblock
- filefrag
- Print block device size
- Identification of HDD by SATA port number
badblock - 對 File System 進行測試
[方式1] 強制 fsck 進行 badblock 檢查
fsck -fc /dev/sda
e2fsck 1.41.3 (12-Oct-2008) Checking for bad blocks (read-only test): 9.25% done, 2:04 elapsed
[方式1] badblocks Bad sector 測試
對 partion 進行 read 測試
smartctl -i /dev/sde | grep Sizes # Sector Sizes: 512 bytes logical, 4096 bytes physica
badblocks -v -s -b 4096 /dev/sda1
- -v # Verbose mode.
- -s # Show the progress of the scan by writing out rough percentage
- -b block-size # Specify the size of blocks in bytes. The default is 1024 byte
- -p num_passes # test 多小次 (Default is 0)
Output
Checking blocks 0 to 96255 Checking for bad blocks (read-only test): 58.11% done, 0:01 elapsed
對 umount 了的 partion 進行 read+write 測試
# -n Use non-destructive "read-write" mode.
badblocks -s -n /dev/sda1
Checking for bad blocks (non-destructive read-write test)
Testing with random pattern: 31.52% done, 0:03 elapsed
Checking for bad blocks (non-destructive read-write test)
Testing with random pattern: done
P.S.
A non-destructive read-write test (-n) makes a backup of the original content of a sector before testing and
then restoring the content from the backup.
破壞性 Read/Write Test
它一共有兩個步驟. 先係 write, 之後就 read
# -w Use write-mode test. 破壞性的 (write patterns: 0xaa)
badblocks -v -s -w /dev/sdd
Checking for bad blocks in read-write mode From block 0 to 1465138583 Testing with pattern 0xaa: done Reading and comparing: 46.60% done, 19:58:22 elapsed. (0/0/0 errors)
filefrag - 查看檔案的 fragment 情況
filefrag winxp.sp3-ide8g.idv
winxp.sp3-ide8g.idv: 13 extents found
filefrag -v winxp.sp3-ide8g.idv
Filesystem type is: ef53 File size of winxp.sp3-ide8g.idv is 4694508032 (1146121 blocks, blocksize 4096) Discontinuity: Block 16 is at 2545216 (was 4754073) Discontinuity: Block 10240 is at 2555904 (was 2555440) Discontinuity: Block 75776 is at 2656256 (was 2621440) Discontinuity: Block 565248 is at 3178496 (was 3145728) Discontinuity: Block 894976 is at 4472832 (was 3508224) Discontinuity: Block 1017856 is at 4601856 (was 4595712) Discontinuity: Block 1020169 is at 11300 (was 4604169) Discontinuity: Block 1040384 is at 382976 (was 31515) Discontinuity: Block 1132544 is at 477184 (was 475136) Discontinuity: Block 1142784 is at 499712 (was 487424) Discontinuity: Block 1144832 is at 505856 (was 501760) Discontinuity: Block 1145865 is at 31515 (was 506889) winxp.sp3-ide8g.idv: 13 extents found
Print block device size
blockdev --getsize64 /dev/sda returns size in bytes.
fdisk -l /dev/sda
lsblk | grep sda
Identification of HDD by SATA port number
lshw -c storage -c disk
*-scsi:0
physical id: 1
logical name: scsi2
capabilities: emulated
*-disk
description: ATA Disk
product: ST500DM002-1BC14
vendor: Seagate
physical id: 0.1.0
bus info: scsi@2:0.1.0
logical name: /dev/sda
version: JC4B
serial: S2A38N69
size: 465GiB (500GB)
capabilities: partitioned partitioned:dos
configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 signature=0000440f
遇上 Bad Sector
dmesg
... ata1.00: exception Emask 0x0 SAct 0x10000000 SErr 0x0 action 0x0 ... ata1.00: irq_stat 0x40000008 ... ata1.00: failed command: READ FPDMA QUEUED ... ata1.00: cmd 60/08:e0:30:bd:88/00:00:14:00:00/40 tag 28 ncq dma 4096 in ... res 51/40:38:00:00:00/00:00:00:00:00/00 Emask 0x409 (media error) <F> ... ata1.00: status: { DRDY ERR } ... ata1.00: error: { UNC } ... ata1.00: configured for UDMA/133 ... sd 0:0:0:0: [sda] tag#28 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE cmd_age=0s ... sd 0:0:0:0: [sda] tag#28 Sense Key : Medium Error [current] ... sd 0:0:0:0: [sda] tag#28 Add. Sense: Unrecovered read error - auto reallocate failed ... sd 0:0:0:0: [sda] tag#28 CDB: Read(10) 28 00 14 88 bd 30 00 00 08 00 ... blk_update_request: I/O error, dev sda, sector 344505648 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0 ... Buffer I/O error on dev sda, logical block 43063206, async page read ... ata1: EH complete
smartctl -A /dev/sda | grep -e Reallocated -e Uncorrectable_Error_Cnt
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0 160 Uncorrectable_Error_Cnt 0x0032 100 100 050 Old_age Always - 0 196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 0
在 read 情況不會 remap sector, 這情況一共有兩個方案
1. 在 FS level remap 佢
2. write 一次那 block 去 trigger remap
# 查看 socker size
hdparm -I /dev/sda | grep 'Sector size'
Logical Sector size: 512 bytes Physical Sector size: 512 bytes
# 4k (bs=512 count=8) (344505648 -> 344505655) # 心得: 有問題時, 多數是 4k size 出事.
dd if=/dev/sda of=/dev/null bs=512 count=8 skip=344505648
dd: error reading '/dev/sda': Input/output error
hdparm (completely bypassing the usual block layer read/write mechanisms)
# hdparm will issue a low-level read for the specified sector.
hdparm --read-sector 344505648 /dev/sda
/dev/sda: reading sector 344505648: SG_IO: bad/missing sense data, sb[]: ... succeeded ...
# hdparm will issue a low-level write zeros to the specified sector.
# --yes-i-know-what-i-am-doing
hdparm --write-sector 344505648 /dev/sda
/dev/sda: re-writing sector 344505648: succeeded