-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk_overwrite.sh
More file actions
42 lines (35 loc) · 950 Bytes
/
disk_overwrite.sh
File metadata and controls
42 lines (35 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Usage: disk_overwrite.sh device
# By: Gene Chao - Last updated: 3/7/2022
REPEAT=2
PAUSE=300
if [ -z "$1" ]; then
echo "Usage: $0 device"
return 1 2>/dev/null
exit 1
fi
DEV=$1
if [ ! -b "$DEV" ]; then
echo "Error: $DEV is not a block device"
return 1 2>/dev/null
exit 1
fi
SIZE=$(blockdev --getsize64 $DEV 2>/dev/null)
if [ -z $SIZE ]; then
echo "Error: Unable to get size of $DEV"
return 1 2>/dev/null
exit 1
fi
LOG=disk_overwrite_$(basename $DEV).log
for n in $(seq 1 $REPEAT); do
echo "***" n=$n
perl -e 'while(1){print"disk_overwrite!"x1000}' | dd of=$DEV bs=4K conv=sync,noerror status=progress
pv $DEV -petar --size $SIZE --stop-at-size | md5sum -b - | tee -a "$LOG"
cat /dev/zero | dd of=$DEV bs=4K conv=sync,noerror status=progress
pv $DEV -petar --size $SIZE --stop-at-size | md5sum -b - | tee -a "$LOG"
if [ $n -lt $REPEAT ]; then
echo "***" Pausing for $PAUSE seconds...
sleep $PAUSE
echo
fi
done