Electromagnet Hard Drive Erasure
This is an experiment to torture test 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
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 magnets
- Small magnet: Apply for 3 seconds
- Small magnet: Wipe across hard drive aggressively
- Small magnet: Wipe across hard drive aggressively while disk is reading
- Medium magnet: Apply for 3 seconds
- Medium magnet: Wipe across hard drive aggressively
- Medium magnet: Wipe across hard drive aggressively while disk is reading
- Large magnet: Apply for 3 seconds
- Large magnet: Wipe across hard drive aggressively
- Large magnet: Wipe across hard drive aggressively while disk is 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.
- When 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 I placed it on the table and held the phone to the side of a 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 distance of |
|---|---|
| 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 on my local file system:
dd if=/dev/urandom of=$HOME/writefile.bin conv=notrunc,noerror,fdatasync bs=1M count=1000
Scripts
magtest.sh
This script was used for each hard drive test. It was modified after having issues with the badblocks test hanging.
#!/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' | head -1 | sed -E 's/\ +/ /g;s/\ -//g')"
# Previous lie was corrected. Original:
# 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"
Mistake in magtest.sh
Note: I've already applied a correction to the code above.
I discovered after running all these tests that the SMART test data is invalid. When you return SMART test results, it lists the results of the test along with several past test results. I assumed that each new test was appended to the end of the list, especially because they're numbered, but it is actually prepended to the beginning.
How I thought it was displayed:
# 1 Short offline Completed without error 00% 34291 - # 2 Short offline Completed without error 00% 34290 - # 3 Short offline Completed without error 00% 34290 - # 4 Short offline Completed without error 00% 34290 - # 5 Short offline Completed without error 00% 19201 - <--- NEW TEST RESULT (WRONG)
How it is actually displayed:
# 1 Short offline Completed without error 00% 34291 - <--- NEW TEST RESULT (CORRECT) # 2 Short offline Completed without error 00% 34290 - # 3 Short offline Completed without error 00% 34290 - # 4 Short offline Completed without error 00% 34290 - # 5 Short offline Completed without error 00% 19201 -
So the code in magtest.sh needs to be corrected so that it takes head -1 instead of tail -1:
# INCORRECT CODE
smarttest="$(smartctl -s on -a $device | grep 'Short offline' | tail -1 | sed -E 's/\ +/ /g;s/\ -//g')"
# CORRECT CODE
smarttest="$(smartctl -s on -a $device | grep 'Short offline' | head -1 | sed -E 's/\ +/ /g;s/\ -//g')"
hdd-readtest.sh
This was used to read the disk while applying the magnet to the hard drive. I could have sent the output to /dev/null, but for some reason I didn't.
#!/bin/bash
device=/dev/sdb
dd if=$device of=rtest.img conv=notrunc,noerror,fdatasync bs=1M count=2000
rm -f rtest.img
Results
Data Files
| Name | Description | Size | Link |
|---|---|---|---|
| results-magtest.csv | Test results (original). Some cells have newline characters. Works best in Libre Office.
(has header, delimiter = pipe, text qualifier = double quote). |
8K | Download |
| results-magtest.xlsx | Test results in Excel format. | 12K | Download |
Observations
After applying the large magnet while the disk was spinning, the hard drive exhibited the classic "click of death". After disassembling the drive, I noticed that one of the IC packages had a hole blown in it. The chip is a TI P15A3FHTZA SH6950D spindle motor and voice coil motor controller. This is likely the reason for the drive failure.
Conclusion
No significant difference in read/write speed and no data corruption.
Based on my test results, I conclude that using magnets on the exterior of a hard drive is not an effective method of data erasure. The other mechanisms of the drive are likely to fail first, and data may still be recoverable via platter transplant.
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)
- http://www.users.on.net/~fzabkar/HDD/HDD_Motor_Control.html