3 # reports whether a disk is spinning physical media or solid state.
4 # if no drive is specified, then /dev/sda is the default.
6 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
10 # plug in a default drive if none is provided.
11 if [ -z "$drive" ]; then drive="sda"; fi
13 # chop off the /dev/ portion of the disk name, if it exists. also chop off
14 # any partition numbers, since the script can only check whole drives (where,
15 # so far at least, all partitions on a drive are the same type).
16 if [[ "$drive" =~ ^/dev/.*$ ]]; then
17 drive="$(echo "$drive" | sed -e 's/^\/dev\///')"
18 # echo "after mangle, drive is: '$drive'"
21 #hmmm: could do the check on multiple drives if weren't so lazy.
23 # let's make sure that the drive exists...
24 if [ ! -e "/sys/block/${drive}/queue/rotational" ]; then
25 false || exit_on_error "failed to find a record for drive '$drive'"
28 # the value for the block device's rotational parameter should be 1 for hard
29 # disks and 0 for SSDs. apparently the linux kernel has supported this check
30 # since version 2.6.29.
31 if [ $(cat /sys/block/${drive}/queue/rotational) -eq 0 ]; then
32 echo "drive $drive is a solid state disk."
34 echo "drive $drive is a spinning physical disk."