2022-08-04 21:55:07 +00:00
|
|
|
|
#!/bin/bash -e
|
2021-12-16 22:28:41 +00:00
|
|
|
|
# Test disk performance
|
|
|
|
|
# Adapted from https://www.shellhacks.com/disk-speed-test-read-write-hdd-ssd-perfomance-linux/
|
2022-08-04 21:55:07 +00:00
|
|
|
|
# Using bash because of redirects
|
2022-07-05 09:40:11 +00:00
|
|
|
|
test "$1" = "-w" && write=true && shift
|
2021-12-16 22:28:41 +00:00
|
|
|
|
disk="${1:-$(df --output=source . | tail -1)}"
|
2022-07-05 09:40:11 +00:00
|
|
|
|
if test "$write"
|
2022-09-16 12:48:43 +00:00
|
|
|
|
then exec &> >(tee ".disktest-$(date +%F)")
|
2022-07-05 09:40:11 +00:00
|
|
|
|
fi
|
2022-08-04 21:55:07 +00:00
|
|
|
|
highlight() { echo "[4m$1[0m"; }
|
|
|
|
|
|
|
|
|
|
highlight "Checking SMART with hdparm"
|
2022-07-05 09:40:11 +00:00
|
|
|
|
# Needs sudo for read test
|
2024-09-15 14:42:56 +00:00
|
|
|
|
sudo hdparm -MWAgt "$disk" || true
|
2022-08-04 21:55:07 +00:00
|
|
|
|
|
2021-12-16 22:28:41 +00:00
|
|
|
|
if test $# -eq 0
|
2022-08-04 21:55:07 +00:00
|
|
|
|
then highlight "[1mWrite Test"
|
2021-12-16 22:28:41 +00:00
|
|
|
|
sync
|
2024-09-15 14:42:56 +00:00
|
|
|
|
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 ) &&
|
2022-08-04 21:55:07 +00:00
|
|
|
|
highlight "Copying random bits:" &&
|
2024-09-15 14:42:56 +00:00
|
|
|
|
sudo dd status=progress if=$tempfile of=.$count bs=1M count=$count
|
2022-08-04 21:55:07 +00:00
|
|
|
|
highlight "Copying zero bits:" &&
|
2024-09-15 14:42:56 +00:00
|
|
|
|
sudo dd status=progress if=/dev/zero of=.$count bs=1M count=$count
|
|
|
|
|
sudo rm .$count
|
2021-12-16 22:28:41 +00:00
|
|
|
|
fi
|