31 lines
1.1 KiB
Bash
Executable File
31 lines
1.1 KiB
Bash
Executable File
#!/bin/bash -e
|
||
# Test disk performance
|
||
# Adapted from https://www.shellhacks.com/disk-speed-test-read-write-hdd-ssd-perfomance-linux/
|
||
# Using bash because of redirects
|
||
test "$1" = "-w" && write=true && shift
|
||
disk="${1:-$(df --output=source . | tail -1)}"
|
||
if test "$write"
|
||
then exec &> >(tee ".disktest-$(date +%F)")
|
||
fi
|
||
highlight() { echo "[4m$1[0m"; }
|
||
|
||
highlight "Checking SMART with hdparm"
|
||
# Needs sudo for read test
|
||
sudo hdparm -MWAgt "$disk" || true
|
||
|
||
if test $# -eq 0
|
||
then highlight "[1mWrite Test"
|
||
sync
|
||
count=3000$(test $(df --output="avail" . | tail -1) -gt 999999 && echo 0 || true)
|
||
tempfile=/var/tmp/.$count
|
||
# Prevent deduplication/predictions by using random rather than zero, but since that is too slow we have to copy a previously created file
|
||
test -s $tempfile ||
|
||
( highlight "Preparing random bits:" &&
|
||
sudo dd status=progress if=/dev/urandom of=$tempfile bs=1M count=$count ) &&
|
||
highlight "Copying random bits:" &&
|
||
sudo dd status=progress if=$tempfile of=.$count bs=1M count=$count
|
||
highlight "Copying zero bits:" &&
|
||
sudo dd status=progress if=/dev/zero of=.$count bs=1M count=$count
|
||
sudo rm .$count
|
||
fi
|