我注意到在我的家用 Ubuntu 服务器上,出于某种原因,一个驱动器是只读的。挖掘我发现当硬盘驱动器出现错误时会发生这种情况。我使用坏块来检查错误,确实我有一些损坏的扇区。
在大多数情况下,唯一合理的做法是尝试备份数据、移除硬盘并购买新硬盘。但是,这个服务器没有任何我已经没有在多个地方备份过的东西,我想用它直到它死了。我用它来播放音乐和运行一些简单的脚本。无论如何,重新安装所有东西都会大惊小怪。
有没有办法在不格式化硬盘的情况下标记这些坏块?
use*_*505 34
我假设您在谈论磁盘上的物理坏块,而不是损坏的文件系统。
要检查磁盘的物理状况,最好安装 smartmontools
sudo apt-get install smartmontools
Run Code Online (Sandbox Code Playgroud)
这是有效的,因为所有现代磁盘都使用名为SMART的系统记录其健康状态
使用该smartctrl命令读出此状态。例如从第一个磁盘调用中读取所有属性
sudo smartctl --all /dev/sda
Run Code Online (Sandbox Code Playgroud)
注意一条谈论整体健康状况的行。一旦这表明有错误,磁盘很可能很快就会出现故障。
SMART overall-health self-assessment test result: PASSED
Run Code Online (Sandbox Code Playgroud)
您要检查的其他行是待定扇区计数和重新分配的扇区。
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 48
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 2
Run Code Online (Sandbox Code Playgroud)
重新分配通常在原始字段中列出磁盘为工作备用扇区交换的坏扇区数。待处理的是在下一次写入失败的情况下可能会重新分配的扇区。
当您的型号支持时,您甚至可以触发磁盘的自检
sudo smartctl -t long /dev/sda
Run Code Online (Sandbox Code Playgroud)
要强制检查所有扇区,请badblocks在写入数据的模式下使用。请注意,即使通常运行是安全的,它也会给您的磁盘带来额外的负载,这可能会导致它们出现故障。始终备份您的数据。
sudo badblocks -svvn -c 262144 /dev/sda
Run Code Online (Sandbox Code Playgroud)
badblocks命令的输出将显示多行
hh:mm:ss elapased. (x/y/z errors)
Run Code Online (Sandbox Code Playgroud)
在哪里
x = num_read_errors
y = num_write_errors
z = num_corruption_errors
Run Code Online (Sandbox Code Playgroud)
如果您以这种方式完全处理了磁盘,则磁盘控制器应该已将所有坏块替换为工作块,并且重新分配的计数将在 SMART 日志中增加。
虽然这是一个老问题,但我发布这个问题是因为badblocks不应该用于坏块磁盘。看man badblocks获取更多信息。
\n\n“强烈建议用户不要直接运行 badblocks,而是使用 e2fsck 和 mke2fs 程序的 -c 选项”。
\n
以 \xe2\x80\x9c 引导至 Ubuntu Live DVD/USB 尝试 Ubuntu\xe2\x80\x9d 模式。
\n在终端中:
\nsudo fdisk -l # identify all "Linux Filesystem" partitions\n\nsudo e2fsck -fccky /dev/sdXX # non-destructive read/write test **(recommended)**\nRun Code Online (Sandbox Code Playgroud)\n或者sudo e2fsck -fcky /dev/sdXX# 只读测试
这-k很重要,因为它保存以前的坏块表,并将任何新的坏块添加到该表中。没有-k,您将丢失所有先前的坏块信息。
这-fccky:
-f Force checking even if the file system seems clean.\n\n -c This option causes e2fsck to use badblocks(8) program to do\n a read-only scan of the device in order to find any bad blocks.\n If any bad blocks are found, they are added to the bad block\n inode to prevent them from being allocated to a file or direc\xe2\x80\x90\n tory. If this option is specified twice, then the bad block scan\n will be done using a non-destructive read-write test.\n\n -k When combined with the -c option, any existing bad blocks in the\n bad blocks list are preserved, and any new bad blocks found by\n running badblocks(8) will be added to the existing bad blocks\n list.\n\n -y Assume an answer of `yes\' to all questions; allows e2fsck to be\n used non-interactively. This option may not be specified at the\n same time as the -n or -p options.\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
61401 次 |
| 最近记录: |