Find the answer to your Linux question:
Results 1 to 8 of 8
Hi , I am writing an application which needs to know if the disk is SSD or not. Is there a standard way (IOCTL) which can be used ?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2013
    Posts
    5

    How to detect SSD programmatically in linux?


    Hi ,

    I am writing an application which needs to know if the disk is SSD or not. Is there a standard way (IOCTL) which can be used ?

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,377
    Hi and welcome

    On fairly new kernels/distros: yes

    1) In a terminal, you can
    Code:
    cat /sys/block/sdX/queue/rotational
    2) But you are more interested in an IOCTL: BLKROTATIONAL
    It was introduced here: https://git.kernel.org/?p=linux/kern...cdea65e253f4cc
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Feb 2013
    Posts
    5
    I have a flash drive inserted into USB port and I tried

    cat /sys/block/sdb/queue/rotational

    I got "1" but I was expecting "0"

    Tried it on Ubuntu 12.04

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,377
    I just tested it (also on a ubuntu 12.04) with a 128GB SSD and a traditional harddisk connected via sata and in AHCI mode.
    Here, the result is as expected (sda is the ssd, sdb is the datadisk)
    Code:
    # cat /sys/block/sda/queue/rotational
    0
    # cat /sys/block/sdb/queue/rotational
    1
    My *guess* is, that usb disks are reporting as traditional disks.
    But whether this is true and if yes: How it can be influenced: No idea yet, sorry.
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Feb 2013
    Posts
    5
    Thanks a lot for your responses Irithori. I really appriciate your help.

  6. #6
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,377
    Usb flash drives also show as rotational=1 on my system.

    Maybe a way to identify those is via udev.
    In console:
    Code:
    udevadm info --query=all --name=/dev/sdX
    You must always face the curtain with a bow.

  7. #7
    Just Joined!
    Join Date
    Feb 2013
    Posts
    5
    But udev just tell you its a USB storage... doesn't say whether its a ssd or non ssd. I will play with BLKROTATIONAL and check how it behaves with non usb SSDs

  8. #8
    Just Joined!
    Join Date
    Feb 2013
    Posts
    5
    BLKROTATIONAL doesn't seem to work.

    I ended up using IOCTL command IDENTIFY (0xec on ATA ) . For SCSI I used INQUIRY command (0x12) for VPD page 0xb1. This VPD page has the information about SSD. These work perfectly for me.


    I tested this on non usb SSD device

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •