Linux命令之badblocks命令
一、命令简介 badblocks命令用于检查磁盘装置中损坏的区块,执行指令时须指定所要检查的磁盘装置,及此装置的磁盘区块数。如果没有指定区块数这个参数,默认值就是设备的容量大小。二、使用示例0、查看磁盘号及块信息[root@s209 ~]# fdisk -lDisk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectorsUnits =
一、命令简介
badblocks命令用于检查磁盘装置中损坏的区块,执行指令时须指定所要检查的磁盘装置,及此装置的磁盘区块数。如果没有指定区块数这个参数,默认值就是设备的容量大小。
二、使用示例
0、查看磁盘号及块信息
[root@s209 ~]# fdisk -l
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000f2931
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 8744959 4064256 82 Linux swap / Solaris
/dev/sda3 8744960 251658239 121456640 83 Linux
1、检测坏块时显示进度
[root@s209 ~]# badblocks -s -v /dev/sda2 > badsectors.txt
Checking blocks 0 to 4064255
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found. (0/0/0 errors)
#执行中会显示进度,如下图
2、执行检测时指定区块大小
[root@s209 ~]# badblocks -s -v -b 8192 /dev/sda3 > badsectors.txt
Checking blocks 0 to 15182079
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found. (0/0/0 errors)
3、指定一次检测块数量
[root@s209 ~]# badblocks -s -v -c 32 /dev/sda2 > badsectors.txt
Checking blocks 0 to 4064255
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found. (0/0/0 errors)
4、使用非破坏的读写模式检测
[root@s100 ~]# badblocks -s -n /dev/sdd
Checking for bad blocks (non-destructive read-write test)
Testing with random pattern: 3.43% done, 3:29 elapsed. (0/0/0 errors)
#非破坏的读写模式检测要求磁盘是未挂载状态
5、重复执行2次检测
[root@s209 ~]# badblocks -s -v -p 2 /dev/sda2
Checking blocks 0 to 4064255
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found. (0/0/0 errors)
Checking blocks 0 to 4064255
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found. (0/0/0 errors)
三、使用语法及参数说明
1、使用语法
badblocks [-svw][-b <区块大小>][-o <输出文件>][磁盘装置][磁盘区块数][启始区块]
2、参数说明
参数 | 参数说明 |
---|---|
-b<区块大小> | 指定磁盘的区块大小,单位为字节,默认4K。 |
-c <块数量> | 每一次检测区块的数目,默认是16,加这个数目可以增加检测坏块的效率可同时也会增加内存的耗费 |
-o file | 将检查的结果写入指定的输出文件。 |
-i file | 跳过已经显示在file文件中的坏道,而不进行检测(可以避免重复检测) |
-s | 在检查时显示进度。 |
-p <重复次数> | 重复扫描次数,默认值是0,命令成功执行一遍扫描后就会结束。 |
-n | 使用非破坏性的读写模式。默认值是非破坏性的只读模式测试。 |
-v | 混杂模式检测。 |
-w | 在检查时,执行写入测试,这个选项会删除掉原有的数据!万不要将此选项用在一个已经包含了文件系统的设备上!!! |
[磁盘装置] | 指定要检查的磁盘装置。 |
[磁盘区块数] | 指定磁盘装置的区块总数。 |
[启始区块] | 指定要从哪个区块开始检查。 |
四、坏道修复步骤
1、查看坏道记录文件
#cat badsectors.txt。
你需要执行e2fsck(针对 ext2/ext3/ext4 文件系统)或fsck命令,命令中还需要用到badsectors.txt文件和设备文件。
2、卸载存在坏道的磁盘
如果你在你的磁盘上发现任何坏道,卸载磁盘并像下面这样让系统不要将数据写入回报的扇区中。
3、使用-l参数锁定坏块
-l 选项告诉命令将在指定的文件 badsectors.txt 中列出的扇区号码加入坏块列表。
------------ 针对 for ext2/ext3/ext4 文件系统 ------------
#e2fsck -l badsectors.txt /dev/sda1
或
------------ 针对其它文件系统 ------------
#fsck -l badsectors.txt /dev/sda1
更多推荐
所有评论(0)