Distinguish between rotational and non-rotational block devices.
List block devices to determine if it is rotational type.
$ lsblk --nodeps --exclude 1,7 --output NAME,PATH,ROTA
NAME PATH ROTA sda /dev/sda 1 sr0 /dev/sr0 1 nvme0n1 /dev/nvme0n1 0
Use JSON format for machine friendly output.
$ lsblk --nodeps --exclude 1,7 --output NAME,PATH,ROTA --json
{ "blockdevices": [ {"name":"sda", "path":"/dev/sda", "rota":true}, {"name":"sr0", "path":"/dev/sr0", "rota":true}, {"name":"nvme0n1", "path":"/dev/nvme0n1", "rota":false} ] }
Now, use awk
to display rotational devices.
$ lsblk --nodeps --exclude 1,7 --output PATH,ROTA | awk '$2~/1/ {print $1}'
/dev/sda /dev/sr0
Alternatively, use jq
to parse JSON and display non-rotational devices.
$ lsblk --nodeps --exclude 1,7 --output PATH,ROTA --json | jq --raw-output '.blockdevices[] | select(.rota==false) | .path'
/dev/nvme0n1
Also, find
utility is enough to identify rotational devices.
$ find /sys/block/*/device/block/*/queue/rotational
/sys/block/sda/device/block/sda/queue/rotational /sys/block/sr0/device/block/sr0/queue/rotational
Additional notes
Please read Queue sysfs files for more information.