LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   how to get HDD and SSD serial number in linux using command line (https://www.linuxquestions.org/questions/linux-hardware-18/how-to-get-hdd-and-ssd-serial-number-in-linux-using-command-line-4175504920/)

sundanat 05-14-2014 12:11 AM

how to get HDD and SSD serial number in linux using command line
 
Hi,

I need to calculate an algorithm using linux HDD or SSD serial number.

How can i get HDD or SSD serial number in linux?

Thanks,
Sundar.N

rhoekstra 05-14-2014 12:56 AM

Smartctl -i /dev/sda

273 05-14-2014 01:11 AM

or you could try using the output of "hdparm -i /dev/sda".

sundanat 05-14-2014 01:27 AM

Thanks rhoekstra.

One more question, how can i find whether my linux machine using SSD or HDD?

Thanks,
sundar.N

pan64 05-14-2014 02:48 AM

there is no direct way I think, but you can get the device model and look for information on the net about that device.

onebuck 05-14-2014 05:27 AM

Member Response
 
Hi,

man hdparm;
Quote:

-I Request identification info directly from the drive, which is displayed in a new expanded format with considerably more detail than with the older -i option.
By using the 'I' option you can get the desired information.
Code:

hdparm -I /dev/sda

/dev/sda:

ATA device, with non-removable media
        Model Number:      OCZ-AGILITY3                           
        Serial Number:      OCZ-C93VFN4X0532CVMP
        Firmware Revision:  2.22   
...detailed information <snipped>


gengisdave 05-14-2014 06:19 AM

The first snipped line posted by onebuck is the Transport Layer (S)ATA or SSD or whatever.

sdparm -I /dev/sda | egrep -i 'model|transport:'

onebuck 05-18-2014 08:53 AM

Member Response
 
Hi,

Quote:

Originally Posted by gengisdave (Post 5170613)
The first snipped line posted by onebuck is the Transport Layer (S)ATA or SSD or whatever.

sdparm -I /dev/sda | egrep -i 'model|transport:'

The option as stated for 'hdparm' is;
Quote:

-I Request identification info directly from the drive, which is displayed in a new expanded format with considerably more detail than with the older -i flag.
I snipped the transport data since the OP wanted just the model & serial;
Quote:

/dev/sda:

ATA device, with non-removable media
Model Number: OCZ-AGILITY3
Serial Number: OCZ-C93VFN4X0532CVMP
Firmware Revision: 2.22
Transport: Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Correct me if I am wrong but 'sdparm' supports the '-i' option for a inquiry;
Quote:

hdparm -i /dev/sda
/dev/sda:

Model=OCZ-AGILITY3, FwRev=2.22, SerialNo=OCZ-C93VFN4X0532CVMP<snip>
I do not think that 'I' is a valid option for 'sdparm'.

sgosnell 05-18-2014 05:52 PM

You can check the rotation rate to see whether it's an SSD or HDD.

brianL 05-20-2014 05:55 AM

lshw is another way:
Code:

      *-disk
            description: ATA Disk
            product: SAMSUNG HD161HJ
            physical id: 0.0.0
            bus info: scsi@0:0.0.0
            logical name: /dev/sda
            version: JF10
            serial: S0V3J90S146109
            size: 149GiB (160GB)
            capabilities: partitioned partitioned:dos
            configuration: ansiversion=5 sectorsize=512 signature=00073592


bluegroper 03-09-2018 03:39 PM

Quote:

Originally Posted by sgosnell (Post 5173283)
You can check the rotation rate to see whether it's an SSD or HDD.

Great answer. +1

BW-userx 03-09-2018 03:55 PM

Code:

udevadm info --query=all --name=/dev/sda
gets you a list of everything then pick what you're looking for then grep it.
Code:

$ udevadm info --query=all --name=/dev/sda | grep ID_SERIAL_SHORT
E: ID_SERIAL_SHORT=S22SNXAG928927N

then if you need to chop that leading part off.
Code:

$ udevadm info --query=all --name=/dev/sda | grep ID_SERIAL_SHORT | tr -d "ID_SERIAL_SHORT=:"
 22NXG928927N

that is off of an SSD drive.
this is bash, or command line so...
taking the information and seeing my HDD says sdd within it I use substring finding to see if it is in fact a ssd or not.

Code:

$ udevadm info --query=all --name=/dev/sda | grep "ID_MODEL"
E: ID_MODEL=Samsung_SSD_850_EVO_250GB
E: ID_MODEL_ENC=Samsung\x20SSD\x20850\x20EVO\x20250GB\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20


//Now I set my test for "SSD"

 
$ [[ $(udevadm info --query=all --name=/dev/sda | grep "ID_MODEL" | awk 'FNR == 1 {print $2}') =~ "SSD" ]] && echo "is ssd"
is ssd


jefro 03-09-2018 04:18 PM

Original post 2014.

BW-userx 03-09-2018 04:20 PM

Oh I c Who reviled it
bluegroper


All times are GMT -5. The time now is 08:04 PM.