硬盘坏道介绍

1.坏道介绍

1.1. 坏道的定义

坏道指的是硬盘中的部分数据无法使用,或者使用出现了异常。更标准的说法应该是坏扇区而不是坏道,因为磁盘的最小寻址单位是扇区而不是磁道。

坏道的表现可能有:
1.无法响应读写指令(可能时好时坏,也可能完全不响应)
2.读取出来的数据与写入的数据不一致
目前碰到的问题主要是问题一,问题二较难发现,不确定实际使用中是否遇到过。

物理坏道是指因为物理原因导致的扇区损坏,不管是操作系统还是磁盘上的磁盘控制器固件都无法对这样的扇区进行读写操作。这几年的硬盘,单个盘片容量通常超过1TB,按照新硬盘采用4K扇区划分来算,就有超过256M的扇区,目前的工艺无法保证这么多扇区全部都是正常好用的,所以硬盘出厂前会把这些坏的扇区标注出来,操作系统和磁盘控制器固件都不会去访问这些扇区。而硬盘出厂后,正常情况下物理坏道增长的概率非常低,常见的物理坏道增长的原因包括硬盘本身质量问题、超出硬盘设计范围的震动、电压不稳定等,如果读写期间突然断电,老式硬盘也会有一定几率导致坏道,新式硬盘就非常罕见了。理论上没有任何磁盘工具可以修复物理坏道。

逻辑坏道一般是指扇区本身并没有物理损坏,但因为其他原因无法完成读写操作而被操作系统标注为坏扇区的扇区。产生逻辑坏道的原因很多,操作系统本身、磁盘控制器固件、内存等等发生错误都可能导致操作系统认为某个扇区损坏而把这个扇区记录在坏扇区列表中,甚至磁盘对拷也可能会把旧硬盘的坏扇区列表拷贝到新硬盘上,使得操作系统认为新硬盘上对应的扇区也是坏的。逻辑坏道通常可以通过再次写入数据恢复成正常扇区,绝大部分的磁盘工具修复都是这个原理。

另外一种特例是硬盘厂家提供的硬盘工具,有可能可以“修复”物理坏道。但本质上只是重新标记物理坏扇区,启用出厂时标注为冗余扇区的备用扇区,重新生产物理扇区和逻辑扇区映射关系。如果损坏的物理扇区数量超出了备用扇区,它也是无能为力的。

1.2. 出现坏道后硬盘还能用吗?

一般情况下,坏道的增长是很罕见的。少量的坏道并不一定意味着硬盘不能使用了,硬盘出厂时就会存在一些坏道,但是被硬盘给屏蔽掉了。如果只出现少量坏道,可以在软件中对其进行屏蔽后,继续使用。

如果硬盘的坏道增长比较频繁,例如每周都有新增的坏道,那么这可能意味着硬盘即将出现严重损坏,此时最好更换硬盘。

2. ext4文件系统对坏道的处理

2.1. ext4布局

https://blog.csdn.net/xuhaitao23/article/details/112404331

2.2. 出现坏道时的表现

1.superblock
2.group descriptors
3.data block bitmap
4.inode bitmap
5.inode table
6.data blocks
坏道可能出现在以上任意区域内,造成的影响不同。

ext4做的保护
ext4对数据做了两个保护:1.冗余 2.校验

冗余:1.superblock和2.group descriptors是ext4的关键信息,损坏后会导致整个文件系统无法使用。ext4对这两个内容做了冗余,在1、3、5、7的幂的序号的group中都保存了一份。

校验:很多数据中都存在校验,但校验并不能解决坏道问题。

出现后的影响
1.superblock和2.group descriptors的损坏可以使用冗余数据保证不出现异常,其他区域的损坏应该是会导致异常的。
3.data block bitmap: 记录了一个group的block使用情况,可能导致group中一些block无法被新数据获取使用。应该不会影响旧数据的读取。
4.inode bitmap: 记录的一个group的inode的使用情况,可能导致group中一些inode无法被新获取获取使用。应该不会影响旧数据的读取。
5.inode table: 可能导致部分inode损坏,对应的文件无法再读取。如果inode表示的是目录,可能目录下所有文件都访问不到了,需要使用ext4的相关工具才能读取。
6.data block: 导致部分数据无法读取,新数据无法写入

总结:ext4只对ext4的关键数据做了保护,出现坏道是有可能导致少量/大量数据损坏的。

另外,ext4应该是会记录坏道信息的,对于后续的写入会避开这些坏道。但是记录坏道不确定是否必须要通过工具进行,还没有找到明确的资料。

三、RAID对坏道的处理

写入:写入时遇到坏道,如果部分盘写入成功,且数据可以任务是完整的,应也会返回写入成功。但会将坏道记录下来。

读取:RAID在正常状态(非降级/失效)下,读取数据是会直接去数据保存的那个盘读取的,读取时遇到坏道,应该会去尝试用校验/备份来计算出因坏道而无法读取的数据。如果通过校验/备份也无法得到这个数据,那么就会返回识别。读取时遇到坏道,也会记录下来。

BBL:bad block list,用于记录坏道信息。这是一个特性,可以关闭,关闭后遇到坏道应该是会直接踢除该硬盘。如果开启,遇到坏道时则会进行记录,坏道总数达到512个之后,也会进行踢盘。

附:参考资料

https://smallbusiness.chrom.com/bad-blocks-mean-hard-drive-failing-75578.html

Do Bad Blocks Mean a Hard Drive Is Failing
/
In computer lingo, a block or sector is a section of your hard drive that records data. Bad blocks are spots that can no longer be written to or read from – essentially, they’re corrupted areas on your hard drive. Although a few bad sectors don’t necessarily mean your hard drive’s about to go belly up, too many can negatively impact your drive’s memory capacity.
/
Tip
A few bad sectors don’t necessarily mean your hard drive’s about to go belly up, too many can negatively impact your drive’s memory capacity.
/
Two Types of Damage
Not all bad sectors are created equal, and there are two different types of sector errors: hard and soft. A hard bad sector has suffered physical damage to a certain block of space, such as from an impact, manufacturing defect or even a small speck of dust on the drive’s internal disk. A soft bad sector is essentially a spot that the operating system (OS) finds a problem with. One way an OS finds a soft bad sector is if the sector’s error-correcting code, or ECC, doesn’t match the information written to that spot.
/
Likelihood of Failure
In most cases, a bad sector or three isn’t the end of the world. If the sector was empty when it went bad, your computer’s operating system simply ignores the area. However, if the block had data on it, that information could be corrupted or destroyed. This could be especially problematic if your operating system files are saved in those bad sectors.
/
Fixing Bad Sectors
Most operating systems offer built-in utilities to scan your hard drive for errors, and identify or repair bad sectors. Although a hard bad sector can’t be repaired, the OS identifies it as bad and reallocates it, which basically means it ignores it from that moment on. Soft bad sectors can sometimes be repaired through your operating system’s disk repair utilities or by formatting the drive.
/
Impending Hard Drive Death
The occasional bad sector every now and then shouldn’t cause alarm, but if your drive seems to sport a new bad spot every week, that could be a sign of imminent failure. Other signs of a hard drive on its last legs are operational problems, missing files or unusually long load times.
/
Odd sounds emanating from the drive can indicate an impending failure, especially scratching, grinding or clicking sounds. These
typically occur when your hard drive is physically damaged, causing
the read/write head to bounce or scrape across the disk.

https://unix.stackexchange.com/questions/499628/can-ext4-filesystem-withstand-a-bad-sector-unreadable

https://raid.wiki.kernel.org/index.php/The_Badblocks_controversy

https://blog.csdn.net/weixin_39941859/article/details/116983267

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值