A small shell script to write random data to a block device (or loopback device) block-by-block and verify each block by reading it back and comparing. This is intended as a simple disk write/read verification tool for Linux systems. Use with extreme caution — it will overwrite the target device.
- Verify that data written to a device can be read back correctly, block by block.
- Provide an easy, auditable script for manual disk testing.
This script will overwrite the target device. Do NOT run it on a mounted filesystem, your OS disk, or any device that contains important data unless you explicitly intend to destroy its contents. Always test with a loopback device or a spare disk.
- Linux environment (not intended for native Windows). Works in WSL/WSL2 or a Linux VM if you access real block devices there.
- Bash shell
- coreutils (dd, cmp, awk)
- Optional: blockdev or lsblk for device size detection
- Optional: xxd for hex-dump diagnostics
Basic invocation:
sudo ./hdd_check.sh DEVICE [BLOCKSIZE] [START_OFFSET]Examples:
-
Test entire device with 100M blocks (default blocksize): sudo ./hdd_check.sh /dev/sdb
-
Use custom blocksize of 1M: sudo ./hdd_check.sh /dev/sdb 1M
-
Start at an offset of 1G into the device: sudo ./hdd_check.sh /dev/sdb 100M 1G
- To avoid touching real hardware while you experiment, use a loopback file:
# create a 200 MiB image file
dd if=/dev/zero of=test.img bs=1M count=200
# create a loop device (Linux)
sudo losetup -fP test.img
losetup -a | grep test.img
# run the script against the loop device shown by losetup, e.g. /dev/loop0
sudo ./hdd_check.sh /dev/loop0 1M
# detach the loop device when done
sudo losetup -d /dev/loop0-
The script attempts to keep temporary files in RAM (via /dev/shm) when possible to avoid additional SSD writes. It also streams the read-back data directly into
cmpto avoid writing the read-back block to disk. -
If you supply incorrect arguments (e.g. pass a size string as DEVICE), the script will likely report an error. Double-check argument order: DEVICE first, then BLOCKSIZE (optional), then START_OFFSET (optional).
This project is licensed under the GNU General Public License v3 (GPL-3.0). See the included LICENSE file for the full text.
Feel free to open issues or suggest improvements. Be careful when changing behavior that writes to devices; always test against loopback devices first.