SoFunction
Updated on 2025-05-08

Summary of the methods of distinguishing SSD from mechanical hard disk in Linux

1. Introduction to lsblk command

lsblk(list block devices) is a powerful command line tool in Linux systems that lists all available block device information. Block devices refer to storage devices that read and write data in fixed blocks, such as hard disks, SSDs, USB drives, and optical disks.

Basic usage

The easiestlsblkThe command takes no parameters, it will display all block devices and their partitions in a tree structure:

lsblk

Typical outputs are as follows:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238.5G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 237.5G  0 part /
└─sda3   8:3    0   488M  0 part [SWAP]
nvme0n1 259:0    0 465.8G  0 disk
├─nvme0n1p1 259:1    0   100M  0 part
└─nvme0n1p2 259:2    0 465.7G  0 part /data

This output displays information such as device name, primary and secondary device number, whether it is removable, size, read-only flag, type, and mount point.

2. Key parameters for identifying disk type: ROTA

To distinguish between SSD and mechanical hard drive, we need to pay attention toROTAThis key parameter.ROTAIt is the abbreviation of "rotational", indicating whether the device has rotating parts.

Query ROTA parameters

Use the following command to specifically display the rotation characteristics of the device:

lsblk -d --output NAME,ROTA

Parameter description:

  • -d: Only display disk devices, no partitions
  • --output NAME,ROTA: Specifies that the output contains NAME (device name) and ROTA (rotate flag) columns

Sample output:

NAME   ROTA
sda    0
sdb    1
nvme0n1 0

What is the meaning of ROTA value

  • ROTA=1: means the device isRotating equipment, that is, traditional mechanical hard disk (HDD). Such devices read and write data through rotating discs and moving magnetic heads.
  • ROTA=0: means the device isNon-rotating equipment, usually solid state drive (SSD). This type of device uses flash chips to store data without mechanical moving parts.
  • For NVMe devices,ROTAThe values ​​are always 0 because they are essentially solid state storage.

3. Why can ROTA parameters distinguish disk types

understandROTAThe principles behind the parameters help us gain a deeper understanding of storage devices.

How does mechanical hard drive (HDD) work

A traditional mechanical hard disk consists of the following key components:

  1. Rotating disc (usually 5400 or 7200 revolutions per minute)
  2. Removable read and write heads
  3. Stepper motor that controls the positioning of the magnetic head

When the system needs to access data, the head must move to the correct track position and then wait for the disc to rotate to the target sector. This mechanical movement results in high access delays (usually in milliseconds).

How solid state drives (SSDs) work

SSD uses NAND flash chips to store data without mechanical moving parts:

  1. Data is stored in a memory cell composed of floating gate transistors
  2. Direct access to data through electronic signals
  3. Access times are usually in microseconds, several orders of magnitude faster than HDD

Since the SSD has no rotating parts at all,ROTAThe flag is set to 0.

4. Other methods to identify disk types

AlthoughlsblkofROTAParameters are the most direct way to judge, but the Linux system also provides several other ways to identify disk types.

1. View /sys/block information

Each block device is/sys/blockThere are corresponding subdirectories in the directory, which contain the detailed information of the device:

cat /sys/block/sda/queue/rotational

The content of this file isROTAValue (0 or 1).

2. Use the smartctl tool

smartctlis part of the SMART (Self-Monitoring, Analysis and Reporting Technology) tool that can provide more detailed disk information:

sudo smartctl -i /dev/sda | grep "Rotation Rate"

For SSDs, the output is usually "Solid State Device" or "Rotation Rate: Solid State Device"; for HDDs, the specific speed is displayed (such as "Rotation Rate: 7200 rpm").

3. Observe the device naming agreement

Although not completely reliable, device names can sometimes provide clues:

  • dev/sdX: It may be an HDD or SSD of the SATA interface
  • /dev/nvmeXnY: It must be NVMe SSD
  • /dev/mmcblkX: Usually an SD card or eMMC storage

5. The importance of disk type identification

Understanding the type of storage device is critical to system management and performance optimization:

1. Performance Tuning

SSD and HDD require different optimization strategies:

  • SSD: Benefiting from TRIM support, appropriate scheduling algorithms (such asnoneorkyber) and aligned partitions
  • HDD: It is necessary to optimize for sequential I/O, which may benefit from more complex scheduling algorithms (e.g.bfq

2. Storage tiering

In a hybrid storage environment, identifying device types can help achieve efficient storage hierarchy:

  • Place frequently accessed data on SSD
  • Store large-capacity, infrequently accessed data on HDD

3. Fault prediction

HDD and SSD have different failure modes and monitoring metrics:

  • HDD: Focus on redistribution sectors, seek error rates and temperatures
  • SSD: Focus on wear, remaining life and write amplification

6. Practical application cases

Case 1: Automated scripts identify disk types

Here is an example of a Bash script to automatically identify SSDs and HDDs in your system:

#!/bin/bash

echo "Detection of storage device types in the system:"
echo "--------------------------------"

lsblk -d -o NAME,ROTA,SIZE,MODEL | awk '
BEGIN {
    print "Device\t\tType\tSize\t\tModel"
    print "----------------------------------------"
}
NR>1 {
    type = ($2 == "0") ? "SSD" : "HDD"
    printf "%s\t\t%s\t%s\t%s\n", $1, type, $3, $4
}'

echo "--------------------------------"
echo "Detection completed"

Case 2: Select the best storage for the database

Suppose we want to select a storage location for the MySQL database:

# Find all SSD devicesssd_devices=$(lsblk -d -o NAME,ROTA | awk '$2=="0" {print $1}')

# If there is an SSD, place the database on the first SSDif [ -n "$ssd_devices" ]; then
    first_ssd=$(echo "$ssd_devices" | head -n1)
    echo "It is recommended to install the database on /dev/$first_ssd (SSD)"
else
    echo "No SSD found, it is recommended to use the fastest HDD to install the database"
fi

7. Advanced Topic: Disk Types in Virtual Environments

In a virtualized environment,ROTAThe behavior of parameters may vary:

1. Disks in virtual machines

Virtual machine's virtual diskROTAThe value depends on the configuration of the manager:

  • May reflect the characteristics of the underlying physical device
  • It may also be set to any value

2. Disks in cloud environments

Virtual disks for mainstream cloud service providers:

  • AWS EBS: gp3/io2 volumes are displayed asROTA=0(Although it is network storage)
  • Azure Managed Disk: Premium SSD displays asROTA=0
  • Google Persistent Disk: The SSD type is displayed asROTA=0

In these cases,ROTAValues ​​represent performance characteristics rather than actual physical characteristics.

The above is the detailed summary of the method of Linux distinguishing SSD from mechanical hard disk. For more information about Linux distinguishing SSD from mechanical hard disk, please pay attention to my other related articles!