Electromagnet Hard Drive Erasure
Torture test of a Seagate hard drive using magnets, including my grossly overpowered electromagnet made from a microwave oven transformer (MOT). I try to quantify the difference in magnetic strength between the different magnets. I then inflict a series of escalating traumas upon the hard drive, following each assault by a scripted routine of tests that generates a wealth of data about the drive's status. When will this hard drive fail? And how? Can you really erase data from a hard drive using a magnet?
Warning: Powerful magnets pose a risk of pinching, broken bones, and damaged electronic devices including medical devices.
Contents
Video
[placeholder video]
Gallery
Project Details
The Plan
I had three magnets:
- Small: a set of small cubic neodymium magnets
- Medium: a much stronger neodymium magnet from another hard drive
- Large: electromagnet made from a MOT powered by 24V DC
I would perform a preliminary magnetic strength test to quantify the difference in strength between the magnets.
For each test of the hard drive, I would apply magnetic torture and run a script that performs many tests. I planned to perform 10 tests on the hard drive:
- Baseline: test before any application of magnetic torture
- Small magnet: Applied for 3 seconds
- Small magnet: Wiped across hard drive aggressively
- Small magnet: Wiped across hard drive aggressively while disk was reading
- Medium magnet: Applied for 3 seconds
- Medium magnet: Wiped across hard drive aggressively
- Medium magnet: Wiped across hard drive aggressively while disk was reading
- Large magnet: Applied for 3 seconds
- Large magnet: Wiped across hard drive aggressively
- Large magnet: Wiped across hard drive aggressively while disk was reading
Deviations from The Plan
- Due to issues after applying the medium magnet while reading I ended up running that test multiple times. The data file has multiple records reflecting this.
- While applying the large magnet while reading, I decided to only spin the drive but not read. In a previous test, I ruined my hard drive adapter, so I didn't want to ruin another one.
- After the final test, the disk would not be recognized as a device in Linux, so I could not perform a final test. The data file, therefore, does not have a record for large magnet while reading.
Magnetic Strength Test
To get a relative comparison between the different magnets, I used my phone's magnetometer. For each magnet place it on the table and held the phone to the side of the ruler to determine at what distance the needle on the magnetometer was centered, which represents 480μT. These were my results:
| Magnet | 480 μT at |
|---|---|
| Small | 2.5cm |
| Medium | 7.5cm |
| Large | 20.5cm |
Preparation
First, I cleared the whole disk with zeros:
dd if=/dev/zero of=$device conv=notrunc,noerror,fdatasync bs=1M
Then I wrote random bits to the first 1 gigabyte of the disk:
dd if=/dev/urandom of=$device conv=notrunc,noerror,fdatasync bs=1M count=1000
I then generated a 1 gig file full of random bits:
dd if=/dev/urandom of=$HOME/writefile.bin conv=notrunc,noerror,fdatasync bs=1M count=1000
Scripts
magtest.sh
#!/bin/bash
#
# Script for testing a hard drive after attempting to destroy it with magnets.
#
# Parameters:
# - $1 test_no
# - $2 "description"
#
# Example: sudo ./magtext.sh 1 baseline
#
# Test results will be written to this log file
outfile="$HOME/results-magtest.csv"
# Device of test drive
device="/dev/sdb"
# File containing random bits for doing a write test (1G size)
writefile="$HOME/writefile.bin"
# Sound to play when done
sound="fanfare3.wav"
# Parameter check
if [ $# != 2 ];then
echo "Usage: $0 test_no \"description\""
exit 1
fi
# Root check
if [ "$(whoami)" != "root" ];then
echo "Must be root."
exit 1
fi
begun=false
exit_f(){
badblocks_interrupted=true
}
#if [ $begun ];then
# echo "INTERRUPT"
# if [ -f "$outfile" ];then
# dtend="$(date +%Y-%m-%d_%H:%M:%S)"
# echo "$1|$dt|$dtend|\"$2\"|\"$badblocks\"|\"$smarttest\"|\"$readperf\"|\"$writeperf\"|$checksum|\"$imagefile\"" >>$outfile
# echo "OUTFILE WRITTEN"
# exit 1
# else
# echo "OUTFILE NOT WRITTEN"
# fi
#fi
trap "exit_f $1 $2" INT
# Get confirmation from user
echo "You are about to perform hard drive test #$1 on $device: \"$2\""
echo -n "Is this correct? [y,N] ";read ans
if ! [[ $ans =~ [yY].* ]];then
echo "Cancelled by user."
exit 0
fi
# Define imagefile
imagefile="$HOME/hddread$1.img"
# If imagefile exists, make sure it's okay to overwrite it
if [ -f $imagefile ];then
echo -n "Overwrite existing imagefile: $imagefile ? [y,N] ";read ans2
if ! [[ $ans2 =~ [yY].* ]];then
echo "Cancelled by user."
exit 0
fi
rm -f $imagefile
fi
## Start test
begun=true
dt="$(date +%Y-%m-%d_%H:%M:%S)"
echo "STARTING TEST: $dt"
if ! [ -f "$outfile" ];then
outhead="test_no|start_time|end_time|description|badblocks|health|read_perf|write_pref|checksum|imagefile"
echo $outhead >$outfile
fi
# Badblocks test
echo "TEST: Badblocks"
badblocks="BAD BLOCKS"
badblocks_interrupted=false
badblocks $device -o badblocks$1.out
sleep 1
if [ -z $(cat badblocks$1.out) ] && ! [ $badblocks_interrupted ];then
badblocks="good blocks"
elif [ $badblocks_interrupted ];then
badblocks="INTERRUPT"
fi
# SMART test
echo "TEST: SMART Test"
smartctl -s on -t short $device >/dev/null 2>&1
sleep 120
smarttest="$(smartctl -s on -a $device | grep 'Short offline' | tail -1 | sed -E 's/\ +/ /g;s/\ -//g')"
# Read performance
echo "TEST: Read performance"
readperf="$(hdparm -Tt $device | tail -2)"
# Write performance
echo "TEST: Write performance"
writeperf="$(dd if=$writefile of=$device conv=notrunc,noerror,fdatasync bs=1M seek=1000 2>&1 | tail -1)"
# Get image file of both read and write sections (2G total)
echo "TEST: Get image file"
dd if=$device of=$imagefile conv=notrunc,noerror,fdatasync bs=1M count=2000 >/dev/null 2>&1
# Clear the write section with zeros
echo "CLEANUP: Clear write section"
dd if=/dev/zero of=$device conv=notrunc,noerror,fdatasync bs=1M count=1000 seek=1000 >/dev/null 2>&1
# Get checksum of image file
echo "CLEANUP: Get checksum"
checksum="$(md5sum $imagefile | awk '{print $1}')"
# Write results to CSV file
echo "RECORD: Log results"
dtend="$(date +%Y-%m-%d_%H:%M:%S)"
echo "$1|$dt|$dtend|\"$2\"|\"$badblocks\"|\"$smarttest\"|\"$readperf\"|\"$writeperf\"|$checksum|\"$imagefile\"" >>$outfile
# Play a sound
paplay $sound
echo "COMPLETE: Test $1 finished $dtend"
hdd-readtest.sh
#!/bin/bash
device=/dev/sdb
dd if=$device of=rtest.img conv=notrunc,noerror,fdatasync bs=1M count=2000
rm -f rtest.img
Links
- http://www.emfs.info/limits/limits-organisations/acgih/: The American Conference of Governmental Industrial Hygienists (ACGIH), TLVs (Threshold Limit Values) and BEIs (Biological Exposure Indices)