Is there anyway to find the serial number, model number and hardware vendor information for either an IDE drive or a SCSI drive from within Red Hat Enterprise Linux? What is the command to determine the HDD serial number in Red Hat Enterprise Linux? How do I determine a LUN serial number? How do I find a disk's serial number? May 04, 2010 How to get Hard Disk serial number using C program in linux i need to get the hard disk serial number of my machine using a C program,can anybody help with a sample program or similar solutions Thanks in advance. How do I find out the make, model and serial number for my SCSI or IDE hard disks under CentOS Linux server? How do I get vendor information about my disk storage w/o opening my Intel / AMD server chassis? You need to use the hdparm command. It provides a command line interface to various hard disk. I'm looking for a serial number of the system and motherboard (eg. Dell or HP), is there any way to find that remotely? Yes, there is. In many cases a little tool called dmidecode can be used. Here's the synopsis from the man pages: dmidecode is a tool for dumping a computer's DMI (some say SMBIOS) table contents in a human-readable format. 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.
Active3 years, 3 months ago
How can I get the
serial number
of a hard disk
drive using Python
on Linux
?I would like to use a Python module to do that instead of running an external program such as
hdparm
. Perhaps using the fcntl
module?Forge
ForgeForge4,47266 gold badges3333 silver badges5151 bronze badges
2 Answers
As you suggested, fcntl is the way to do this on Linux. The C code you want to translate looks like this:
Translated into Python on Ubuntu 9.10, it goes a little something like this: Microsoft toolkit 2 5 2.
Apologies for the length, I thought it useful to include the original C struct as a comment. Also, I'm pretty new to both the
fcntl
and struct
modules, so I may be doing something unidomatic. In anycase, run from the command-line (with root privelidges) it looks like this (I've redacted my exact serial for privacy):What's going on here?
In order to be able to understand what is going on here, you need to look at the
#include <linux/hdreg.h>
in the original C program. This include imports the HDIO_GET_IDENTITY
constant and the struct hd_driveid
. I've copied the struct as a comment into the python sourcecode above, so I won't repeat it here. To find out what is going on with HDIO_GET_IDENTITY
, grep the source-code for it (on Ubuntu this is at /usr/include/linux/hdreg.h
. You should find something like this:Thus, you find that
HDIO_GET_IDENTITY
is just a constant that tells fcntl that you are interested in getting HD info. As you will notice, that same value (0x030d
is an integer in hexadecimal notation) is assigned to a variable in the python code.I realise now you are interested in Linux, but I'll keep this here for posterity. The following will get the HDD serial number on Windows (you will need to install the wmi package):
fmarkfmark36.5k2323 gold badges8383 silver badges106106 bronze badges
Get a screwdriver and open the case ;-)
If you are on windows, this might do the trick
For this you need the Mark Hammond modules for windowshttp://python.net/crew/mhammond/
Forge4,47266 gold badges3333 silver badges5151 bronze badges
Fredrik PihlFredrik Pihl36.4k44 gold badges6363 silver badges116116 bronze badges
Not the answer you're looking for? Browse other questions tagged pythonlinuxhard-driveserial-numberfcntl or ask your own question.
Active2 years, 3 months ago
I have a Linux box with five disk drives, one of which I want to replace. The offending drive is
/dev/sdc
, but that doesn't tell me how to distinguish the hardware. The drive is SATA and the assignment of drives to devices sometimes changes after a boot.I'd like to be able to use the model names printed on the disk. Windows 8.1 enterprise product key. I know these names are machine-readable because they are the names the BIOS uses.
Is there a way, using Linux, to find out the model number of
Norman RamseyNorman Ramsey/dev/sdc
, or even the model numbers of all the drives in the system? 2,00866 gold badges2626 silver badges3535 bronze badges
4 Answers
Try the
hdparm
program:The
LekensteynLekensteyn-i
option of hdparm
can be used to retrieve identification information.4,80122 gold badges2222 silver badges4444 bronze badges
I'm not sure if it's on all distros, but try looking into /dev/disk/by-id:
You can also try grepping dmesg for the device name:
In this case it's ST31000528AS.
![Get Get](/uploads/1/2/5/0/125038735/281200020.jpg)
user697683user697683
try running:
It will give you a long output regarding your hardware, the one that concerns you will look similar to this:
Linux Get Scsi Disk Serial Number
Notice that it mentions your block device id as
logical name
and also the serial number as product
. You can use this to physically distinguish your drivesdarnirdarnir
If you have
lsblk
installed on your system, you can use this command:This will return a columnar display like the one shown below with model number, manufacturer's serial number, disk size, and state. It can be scripted to allow you to access remote machines, too. You must be root to use it, though.
moonpoint4,31222 gold badges1111 silver badges1616 bronze badges
Gray ManGray Man