LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Hard Drive Serial Number? (https://www.linuxquestions.org/questions/linux-hardware-18/hard-drive-serial-number-23071/)

daver 06-10-2002 02:09 PM

Hard Drive Serial Number?
 
Is there a command in linux that will give the hard drive serial number? (hopefully this is a non-specific distribution command....)

Sorry for the simplicity of this question.... Linux Newbie.....

Glockage 06-10-2002 02:17 PM

If you have DOS on your machine, you can type "dir" in and it will list the serial number of the current drive and the conternets of the directory you are in, but for doing it in Linux, I could'nt tell you :D.

daver 06-10-2002 02:43 PM

Thanks, but, I knew the DOS command..... looking for Linux and Mac now....

acid_kewpie 06-10-2002 03:21 PM

well the serial number is presumably in /proc/ide/hdX/identify, as to a foraml way to get the data i don't know.

you can also get a decent more usable output from "hdparm -i /dev/hda":

Code:

[root@trevor chris]# hdparm -i /dev/hda

/dev/hda:

 Model=Maxtor 32049H2, FwRev=YAH814Y0, SerialNo=L22H2Q4C
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=57
 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=40021632
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes: pio0 pio1 pio2 pio3 pio4
 DMA modes: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 *udma5
 AdvancedPM=yes: disabled (255) WriteCache=enabled
 Drive Supports : ATA/ATAPI-6 T13 1410D revision 0 : ATA-1 ATA-2 ATA-3 ATA-4 ATA-5 ATA-6


icwiener 03-17-2004 09:57 AM

Have a look at the kernel header file "hdreg.h". There you can find a struct called "hd_driveid". It looks like this:
Code:

struct hd_driveid {
  unsigned short  config;        /* lots of obsolete bit flags */
          ...
  unsigned char  serial_no[20];  /* 0 = not_specified */
          ...
}

The output of /proc/ide/ideN/hdX look like this:
Quote:

045a 3fff c837 0010 8856 022a 003f ffff
0000 0000 5330 3147 4a31 3057 3430 3133
3436 2020 2020 2020 0003 1000 0004 5344
...
With perl you can extract this as following:
Code:

[root@k0Nkr3Tix /proc/ide/ide3/hdh]#
cat identify | perl -e '<>;($tmp = substr(<>,10,29).substr(<>,0,20) ) =~ s/\ //g;print chr(hex $_) foreach (unpack("a2" x 20,$tmp))'

# output : S01GJ10W401346



All times are GMT -5. The time now is 10:24 PM.