dotfiles/.local/bin/scripts/disktest

29 lines
987 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 "$1"; }
highlight "Checking SMART with hdparm"
# Needs sudo for read test
sudo hdparm -MWAgt "$disk"
if test $# -eq 0
then highlight "Write Test"
sync
# This prevents predictions by using random, but since that is too slow we have to copy a previously created file
highlight "Preparing:" &&
sudo dd status=progress if=/dev/random of=/var/tmp/tempfile bs=1M count=1K &&
highlight "Copying random bits:" &&
sudo dd status=progress if=/var/tmp/tempfile of=tempfile bs=1M count=1K
# TODO adjust size to disk
highlight "Copying zero bits:" &&
sudo dd status=progress if=/dev/zero of=tempfile bs=1M count=1K
sudo rm tempfile
fi