query the disk type in Linux

时间:2024-11-28 07:02:18

To query the disk type in Linux (e.g., SSD or HDD), you can use several methods. Here are some common approaches:


1. Using lsblk

The lsblk command lists information about block devices.

Command:

lsblk -d -o NAME,ROTA,TYPE

Output:

  • ROTA: Indicates if the disk is rotational.
    • 1: HDD (rotational)
    • 0: SSD (non-rotational)
Example:

NAME ROTA TYPE sda 1 disk # HDD nvme0n1 0 disk # SSD


2. Using cat to Read Disk Attributes

Linux provides disk attributes in the /sys/block directory.

Command:

cat /sys/block/sdX/queue/rotational

Output:

  • 0: SSD
  • 1: HDD

Replace sdX with the disk identifier (e.g., sda).

Example:

cat /sys/block/sda/queue/rotational 1 # HDD