我需要工具来验证本地硬盘、USB 驱动器等的数据完整性。
我正在寻找像著名的解决方案www.heise.de/download/h2testw或者至少在存储库中常见的东西。 (h2testw 将特定的数据字符串一遍又一遍地写入介质上,然后再次读取它以验证其写入是否正确并显示写入/读取时间/速度。)
我不是在寻找
dd if=/dev/random of=/dev/sdx bs=1k && dd if=/dev/sdx of=/dev/null bs=1k
因为它不会验证所有内容是否都正确写入。这只是测试设备读写是否成功。
到目前为止,我还不太满意
badblocks -w -v /dev/sdx1
要么,因为它看起来很慢,而且我不知道它到底写了什么,也不知道它是否考虑闪存介质上的磨损均衡。
有一个程序叫F3http://oss.digirati.com.br/f3/需要编译。在 h2testw 之后设计的,这个概念听起来很有趣,我只是宁愿它是一个预先打包的二进制文件。
答案1
下面的脚本在共享内存中创建一个随机文件(约100M),计算其校验和,然后多次将其复制到给定的块设备,使整个设备充满随机数据的副本,同时再次读取并计算其校验和校验和以检查它是否与原始值匹配。
它产生如下输出:
We will create a test data file /dev/shm/testsource with size 100000000.
We will fill the device /dev/sdb (of size 16001036288) with this data (in 160 blocks) and then will check if the data is not corrupted.
This will erase all data in /dev/sdb.
Do you want to continue?
1) yes
2) no
#? 1
Creating test source file... (100000000)
Calculating source checksum...
9f4c31858b3bb1122974a5c9d8ec28c6f71b3367
Writing block 0 ...
Checking block 0 ... ok
Writing block 1 ...
Checking block 1 ... ok
Writing block 2 ...
Checking block 2 ... ok
它需要 dd、blockdev、cut、sha1sum、/dev/urandom 和 /dev/shm。它需要访问设备(通常是root)。这已经在 Linux 2.6.3x 上进行了测试。它很慢。您可以修改它以执行多次传递或执行所有写入然后所有检查或在检查之前等待一段时间(“淡入淡出”测试)。
#!/bin/bash
TARGETDEVICE=$1
TESTFILE="/dev/shm/testsource"
BLOCKSIZE="100000000"
if [ -b "$1" ]; then
TARGETSIZE=$(blockdev --getsize64 $TARGETDEVICE)
if [ "$TARGETSIZE" -gt 0 ] ; then
let "BLOCKS=$TARGETSIZE / $BLOCKSIZE"
if [ "$BLOCKS" -lt 2 ] ; then
BLOCKSIZE=$TARGETSIZE
BLOCKS=1
fi
fi
echo "We will create a test data file $TESTFILE with size $BLOCKSIZE."
echo "We will fill the device $TARGETDEVICE (of size $TARGETSIZE) with this data (in $BLOCKS blocks) and then will check if the data is not corrupted."
echo "This will erase all data in $TARGETDEVICE."
echo "Do you want to continue?"
select choice in yes no ; do
if [ "$choice" == "yes" ] ; then
echo "Creating test source file... ($BLOCKSIZE)"
dd if=/dev/urandom of=$TESTFILE bs=$BLOCKSIZE count=1 status=noxfer 2> /dev/null
echo "Calculating source checksum..."
CHECKSUM=$(sha1sum $TESTFILE | cut -d " " -f 1)
echo $CHECKSUM
for ((y=0 ; y<$BLOCKS ; y++)) ; do
echo "Writing block $y ..."
dd if=$TESTFILE of=$TARGETDEVICE bs=$BLOCKSIZE count=1 seek=$y status=noxfer 2> /dev/null
echo -n "Checking block $y ... "
TESTCHECKSUM=$(dd if=$TARGETDEVICE bs=$BLOCKSIZE count=1 skip=$y status=noxfer 2> /dev/null | sha1sum | cut -d " " -f 1)
if [ "$CHECKSUM" == "$TESTCHECKSUM" ] ; then
echo "ok"
else
echo "MISMATCH"
echo "(found $TESTCHECKSUM)"
fi
done
rm -f $TESTFILE
break
fi
if [ "$choice" == "no" ] ; then
echo
echo "Operation cancelled"
echo
break
fi
done
else
echo
echo "Missing or wrong target device"
echo "Usage: $0 /dev/device"
echo
fi