homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Getting Hard Disk Serial number
From Linux command prompt
trillianjedi




msg:912211
 4:19 pm on Feb 9, 2004 (gmt 0)

Someone told me this is available in DF somewhere but I couldn't find it.

I just need something that will let me grab the hard disk serial number from the command line. I know the information is available in IOCTL but I don't really want to have to code a routine for it.

Thanks,

TJ

 

bcolflesh




msg:912212
 4:28 pm on Feb 9, 2004 (gmt 0)

/sbin/ifconfig

?

<edit> ignore - that is the ethernet address </edit>

[edited by: bcolflesh at 4:31 pm (utc) on Feb. 9, 2004]

bakedjake




msg:912213
 4:29 pm on Feb 9, 2004 (gmt 0)

TJ, I can't find it in either my BSD or Linux df command. I don't think it's there, because hardware readable serial numbers are something that only exists in IDE land.

Or did you mean the model number? Because dmesg will give you model numbers.

trillianjedi




msg:912214
 4:35 pm on Feb 9, 2004 (gmt 0)

bcolflesh - thanks, but that seems to be ethernet card info?

Mind you maybe I could use the MAC address instead.

Jake - no, it's the serial number. I'm looking for something reasonably unique that I can ID a machine by. I say reasonably, as it's for a (relatively) small group of PC's so liklihood of a doubled-ID would be remote. Needs to be no more than 4 bytes.

I'm wondering if I could take the first 4 bytes of a MAC address now.....

<Edit : bcolflesh - just seen your edit but actually I think you may have inadvertently given me a better idea anyway ;-)>

Thanks,

TJ

[edited by: trillianjedi at 4:37 pm (utc) on Feb. 9, 2004]

bcolflesh




msg:912215
 4:37 pm on Feb 9, 2004 (gmt 0)

You could concatenate the hostid and MAC addy.

bakedjake




msg:912216
 4:39 pm on Feb 9, 2004 (gmt 0)

something reasonably unique

What about 15 bytes from /dev/random?

Problem with MAC addresses is that some network card vendors set the MAC addresses to be the same. That may be a non issue for you, but just thought I'd bring it up.

As far as serials - yeah, only IDE drives have hardware serial numbers. So throw that out if you have machines with SCSI drives.

trillianjedi




msg:912217
 4:40 pm on Feb 9, 2004 (gmt 0)

You could concatenate the hostid and MAC addy.

Needs to be 4 bytes long as I need cross-compatability with Windows unfortunately (Win stores Hard Disk ID as a DWord).

First (or maybe last) 4 bytes of a MAC address are likely to be pretty unique though?

TJ

bird




msg:912218
 4:45 pm on Feb 9, 2004 (gmt 0)

On linux, the standard way to get the serial no. of a HD is hdparm, but you need to have root priveledges to use that:

#> hdparm -i /dev/hda

/dev/hda:

Model=Maxtor 52049H3, FwRev=JAC61HU0, SerialNo=F3H238ZC
Config={ Fixed }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=57
BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=8
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=39102336
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
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5
AdvancedPM=yes: disabled (255) WriteCache=enabled
Drive conforms to: ATA/ATAPI-6 T13 1410D revision 0: 1 2 3 4 5 6

#>

Getting the MAC address is probably easier.

Problem with MAC addresses is that some network card vendors set the MAC addresses to be the same.

That sounds very unlikely to me, because it would keep those cards from connecting to each other.

[edited by: bird at 4:48 pm (utc) on Feb. 9, 2004]

bakedjake




msg:912219
 4:46 pm on Feb 9, 2004 (gmt 0)

because it would keep those cards from connecting to each other.

Heh - That's exactly how I found out about it. ;-) D-Link was notorious for it several years ago.

trillianjedi




msg:912220
 4:46 pm on Feb 9, 2004 (gmt 0)

Definitely want to cover possibility of SCSI drives so thanks for the tip Jake - will scrub the serial number idea.

So it seems MAC addy might not be unique either. I need to be able to grab this occasionally, so needs to be something static in the sense that a user couldn't change whatever it is I'm looking at.

CPU serial number would be ideal here, but Intel stopped doing those after the PIII......

Thanks Bird - your post perfectly answers the original question. But it seems that will only produce a serial nunber for an IDE disk and not SCSI?

TJ

[edited by: trillianjedi at 4:48 pm (utc) on Feb. 9, 2004]

bcolflesh




msg:912221
 4:47 pm on Feb 9, 2004 (gmt 0)

First (or maybe last) 4 bytes of a MAC address are likely to be pretty unique though?

It's probable in the small setting you mentioned - sounds like you could check them all and find out pretty quick.

What happens in situations w/more than 1 drive per machine?

trillianjedi




msg:912222
 4:54 pm on Feb 9, 2004 (gmt 0)

What happens in situations w/more than 1 drive per machine?

It wouldn't make any difference. Especially if I use the MAC addy ;-)

If you meant more than one NIC - I'll just be grabbing the first one, so shouldn't matter.

TJ

bakedjake




msg:912223
 4:56 pm on Feb 9, 2004 (gmt 0)

What about the creation time (17:44) of /bin (or whatever)?

That *should* be relatively unique.

But I'd stick with the MAC addy too, if you know they've all got different addresses.

bird




msg:912224
 4:58 pm on Feb 9, 2004 (gmt 0)

(duplicate MAC addresses)
Heh - That's exactly how I found out about it. ;-) D-Link was notorious for it several years ago.

Well, but in this case you have more urgent problems than determining a unique ID for some software...

First (or maybe last) 4 bytes of a MAC address are likely to be pretty unique though?

A certain number of bits at the beginning of the MAC address specify the manufacturer, and are therefore quite likely to be the same for most machines in a local network. For the remaining bits the manufacturer is supposed to come up with unique values. Therefore, only the full thing is garanteed to be unique across manufacturers (ignoring any screwups).

What happens in situations w/more than 1 drive per machine?

The same that happens with more than one ethernet card: Pick the prettiest one! ;)

trillianjedi




msg:912225
 5:02 pm on Feb 9, 2004 (gmt 0)

What about the creation time (17:44) of /bin (or whatever)?

That's a clever idea - hadn't thought of that one. If I could translate that to a t_time value (# of seconds since 1/1/1970), that would be pretty damn unique. And exactly 4 bytes long (unsigned int).

TJ

SeanW




msg:912226
 5:17 pm on Feb 9, 2004 (gmt 0)

hostid - print the numeric identifier for the current host

$ hostid
a8c00101

Works well enough for most unix licencing software...

Sean

trillianjedi




msg:912227
 5:22 pm on Feb 9, 2004 (gmt 0)

$ hostid

Interestingly, the first two bytes of mine are the same as yours:-

hostid
a8c06400

What is the hostid exactly? Is it designed to be unique? Perhaps randomly genereated on install?

TJ

bakedjake




msg:912228
 5:24 pm on Feb 9, 2004 (gmt 0)

Is it designed to be unique?

No. Documented problems with it, in fact, and most major OS vendors are dropping it.

See: [mail.gnu.org...]

trillianjedi




msg:912229
 5:30 pm on Feb 9, 2004 (gmt 0)

OK thanks Jake - read the article, hostID is definitely not the ticket here.

But I do like your time/date stamp of /bin - and I have just checked and can convert that to number of seconds since 1/1/1970 within a 4 byte time_t.

About as unique as I'll ever need. Not much liklihood of two users of this sytem having both installed linux at exactly the same moment in time on exactly the same date ;-)

TJ

PS This is not for software protection - just to ID a particular server. No major problems if two happen to have the same ID anyway as this ID is coupled with IP address as a secondary (dynamic IP related system, hence IP alone is not enough).

danny




msg:912230
 1:24 am on Feb 10, 2004 (gmt 0)

If you have more bits than you want, you can always hash them. So take the MAC address, MD5 it, then grab 32 bits of that to get your four bytes. The chances of MD5 hashes of ethernet addresses colliding is pretty small. (And I think for practical purposes you can assume ethernet addresses are unique.)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved