minor improvements
[feisty_meow.git] / scripts / system / report_disk_type.sh
1 #!/bin/bash
2
3 # reports whether a disk is spinning physical media or solid state.
4 # if no drive 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 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'"
19 fi
20
21 #hmmm: could do the check on multiple drives if weren't so lazy.
22
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'"
26 fi
27
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."
33 else
34   echo "drive $drive is a spinning physical disk."
35 fi
36
37