Created
July 11, 2021 19:15
-
-
Save mrjk/b6731abb182dac430e9f4438ecdcd45d to your computer and use it in GitHub Desktop.
A little script to get disks informations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Tooling: Debian | |
# apt install smartmontools sysstat hdparm | |
# Sata infos | |
# SATA revision 1.0 => 1.5 Gbit/s, 150 MB/s | |
# SATA revision 2.0 => 3 Gbit/s, 300 MB/s | |
# SATA revision 3.0 => 6 Gbit/s, 600 MB/s | |
# SATA revision 3.2 => 16 Gbit/s, 1969 MB/s | |
# Determine your sata disk speed: | |
# dmesg | grep -i --color ahci | |
# dmesg | grep -i sata | grep 'link up' | |
# dmesg | grep -i ahci | grep -i --color Gbps | |
# Determine disk stat support | |
# for i in /dev/[vs]d? ; do echo $i ; smartctl -i $i | grep "^SATA" ; done | |
# Determine disk rpm | |
# for i in /dev/[vs]d? ; do echo $i ; hdparm -I $i | grep -i Rotation ; done | |
# Check read speed: | |
# hdparm -Tt /dev/sda | |
# To track IO in live: | |
# iostat -xm 2 | grep -E "^sd|Device" | |
# iotop | |
set -eu | |
show_disks () | |
{ | |
for i in /dev/[vs]d? ; do | |
echo "Disk info for: $i" | |
local hdparm_out=$( hdparm -I $i ) | |
echo "$hdparm_out" | grep -i Rotation | |
echo "$hdparm_out" | grep -i "Model Number:" | |
echo "$hdparm_out" | grep -i "Serial Number:" | |
echo "$hdparm_out" | grep -i "Firmware Revision:" | |
echo "$hdparm_out" | grep -i "Transport:" | |
echo "$hdparm_out" | grep -i "device size with" | |
local smartctl_out=$( smartctl -a $i ) | |
#smartctl -i $i | sed 's/^/ /' | grep " SATA" | |
#smartctl -H $i | |
echo "$smartctl_out" | grep "SATA" | |
echo "$smartctl_out" | grep "Model Family:" | |
echo "$smartctl_out" | grep "User Capacity:" | |
echo "$smartctl_out" | grep "Rotation Rate:" | |
echo "$smartctl_out" | grep "SMART supprt" | |
echo "$smartctl_out" | grep "SMART overall-health" | |
done | |
} | |
main () | |
{ | |
local dest=$1 | |
local scheme=${2:-medium} | |
local bs count | |
case "$scheme" in | |
large) | |
bs=10M | |
count=100 | |
;; | |
medium) | |
bs=1M | |
count=1000 | |
;; | |
small) | |
bs=1K | |
count=1000000 | |
;; | |
*) | |
echo "ERROR: Unknown scheme: $scheme" | |
exit 1 | |
;; | |
esac | |
# Destination check | |
if [[ ! -d "$dest" ]]; then | |
echo "ERROR: Destination is not a directory: $dest" | |
exit 1 | |
fi | |
# Destination size check | |
local disk_av=$(df $dest | tail -n -1 | awk '{print $4 }') | |
if [[ "$disk_av" -lt 1500 ]]; then | |
echo "ERROR: Not enough disk space, only $disk_av available instaead of 1500" | |
exit 1 | |
fi | |
echo "INFO: Starting speed test on $dest/ZERO_FILE" | |
time dd if=/dev/zero of=$dest/ZERO_FILE bs=$bs count=$count status=progress oflag=direct | |
rm $dest/ZERO_FILE 2>/dev/null || true | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment