new script checks disk for ssd or hd
[feisty_meow.git] / scripts / system / report_disk_type.sh
1 #!/bin/bash
2
3 # reports whether the disk partition provided is spinning physical media or solid state.
4 # if no partition is specified, then /dev/sda is the default.
5
6 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
7
8 drive="$1"; shift
9
10 # plug in a default drive if none is provided.
11 if [ -z "$drive" ]; then drive="sda"; fi
12
13 # chop off the /dev/ portion of the disk partition name, if it exists.
14 if [[ "$drive" =~ ^/dev/.*$ ]]; then
15   drive="$(echo "$drive" | sed -e 's/^\/dev\///')"
16 #  echo "after mangle, drive is: '$drive'"
17 fi
18
19 #hmmm: could do the check on multiple drives if weren't so lazy.
20
21 # let's make sure that the drive exists...
22 if [ ! -e "/sys/block/${drive}/queue/rotational" ]; then
23   false || exit_on_error "failed to find a record for drive '$drive'"
24 fi
25
26 # the value for the block device's rotational parameter should be 1 for hard
27 # disks and 0 for SSDs.  apparently the linux kernel has supported this check
28 # since version 2.6.29.
29 if [ $(cat /sys/block/${drive}/queue/rotational) -eq 0 ]; then
30   echo "drive $drive is a solid state disk."
31 else
32   echo "drive $drive is a spinning physical disk."
33 fi
34