Skip to content

Instantly share code, notes, and snippets.

@cassc
Created September 24, 2024 09:13
Show Gist options
  • Save cassc/373759e8d753c2e14933ed9fe71a4dd6 to your computer and use it in GitHub Desktop.
Save cassc/373759e8d753c2e14933ed9fe71a4dd6 to your computer and use it in GitHub Desktop.
Check if disk is SSD or HDD

To determine whether a drive is an SSD or an HDD on Ubuntu from the command line, you can use one of the following methods:

1. Using lsblk

The lsblk command can display whether a disk is an SSD.

lsblk -d -o name,rota
  • name: The name of the disk.
  • rota: Displays 0 for SSDs (non-rotational) and 1 for HDDs (rotational).

Example output:

NAME   ROTA
sda       1  # HDD
sdb       0  # SSD

2. Using cat /sys/block/<device>/queue/rotational

Replace <device> with your actual device name (e.g., sda, sdb, sdc):

cat /sys/block/sdc/queue/rotational
  • 0 indicates an SSD (non-rotational).
  • 1 indicates an HDD (rotational).

3. Using smartctl

If the smartmontools package is installed, you can get detailed information about your drives:

sudo apt-get install smartmontools
sudo smartctl -a /dev/sdc | grep 'Rotation Rate'
  • If the output shows Rotation Rate: Solid State Device, it’s an SSD.
  • If it shows a number (e.g., 5400 RPM or 7200 RPM), it’s an HDD.

4. Using udevadm

Another way to check the device's type is by using udevadm:

udevadm info --query=property /dev/sdc | grep ID_ATA_ROTATION_RATE_RPM
  • If you see ID_ATA_ROTATION_RATE_RPM=0, it's an SSD.
  • If it shows a number (e.g., 5400 or 7200), it's an HDD.

Summary

The simplest and most direct method is to use lsblk -d -o name,rota or cat /sys/block/<device>/queue/rotational. These commands work quickly without needing additional packages and provide the information you're looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment