Penguin Crumbs

Notes and tips from a Linux user

home about this blog
search:  

How I test a brand new data storage device

This is the way I test new data storage devices, like portable USB sticks, external hard drives, or internal hard disks.

Step 1 - prepare the drive

First, use gparted/fdisk to create a new partition table and one new unique partition having the maximum available size. In this post, I assume you are working with about 120 GiB of real free space, mounted on /media/user/newdrive. Of course please change the following instructions properly, according to your own case.

Free reserved blocks - for example if you chose ext4 and the partition is mapped in /dev/sdc1, use "sudo tune2fs -m 0 /dev/sdc1".

Step 2 - fill the drive with random files

The test consists of creating several 1 GB files. A hash is calculated for each of them and then the file is moved to the data storage to be tested. To accomplish this, I created the following bash script.

#!/bin/bash

readonly CAPACITY_IN_GB=120  # capacity in GB approximated down, adjust this
readonly HDD_MOUNTPOINT="/media/user/newdrive"  # adjust this

readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly MD5SUM_FILE="$HDD_MOUNTPOINT/md5sum.txt"

rm -f "$MD5SUM_FILE"
for in $(seq -w 1 $CAPACITY_IN_GB)do
    partial_filename="${i}_${RANDOM}.dat" # hopefully unique file name
    filename="$SCRIPT_DIR/$partial_filename"
    echo "$(date +"%Y-%m-%d %H:%M:%S") file \"$partial_filename\"..."
    dd if=/dev/urandom of="$filename" bs=64M count=16 iflag=fullblock 2> /dev/null
    md5sum "$filename" >> "$MD5SUM_FILE"
    mv -"$filename" "$HDD_MOUNTPOINT"
done
echo "...done!"
echo "MD5SUMs saved in \"$MD5SUM_FILE\"."
echo "Umount the volume and check MD5SUMs."

If you get errors, maybe you just overestimated the real capacity of the device or the device has serious write problems (and this is not common).

Then, if it’s possible, unmount the partition and reboot your system to clean cache memory and then mount it again in the same position (e.g. /media/user/newdrive).

Step 3 - read the files from the drive

Now you can check the written data using the following commands:

  md5sum /media/user/newdrive/*.dat > md5sum_2.txt

Here, read errors means that your drive may have problems.

Step 4 - check if there are errors

Before comparing md5sum.txt md5sum_2.txt you have to remove paths:

 cat /media/user/newdrive/md5sum.txt | cut -d' ' -f1 > 1.txt
 cat md5sum_2.txt | cut -d' ' -f1 > 2.txt

Now we can compare the contents:

 diff 1.txt 2.txt

no output means you drive is OK, otherwise if the files have different content, it means that your drive may have problems.

That's all.

 
 
Posted on 2022-01-09  
 
⇦  back
 
__________________
 
Copyright © 2019-2024 Marcello Zaniboni