Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running Ubuntu Server 9.10. I have two external USB HDDs. I use them each for different backup reasons. So certain data gets stored on one HDD, and different information gets stored on the other HDD.

I want to make a script that can look at the external HDD can determine which HDD it is, so that it can copy the proper information to it. Is there a way for Linux to determine this? Like if I see one HDD as /dev/sdc1, then unplug it and plug in the other HDD, should Linux see it as /dev/sdd1 or will it be /dev/sdc1?

I'm a bit of a Linux newb and I don't quite understand how it determines the /dev/sdxx values that it assigns to drives.

share|improve this question
up vote 6 down vote accepted

Storage device identification can be performed using the UUID of the device. Identification based on /dev/sd* is not reliable.

In ubuntu 9.10 you can use blkid to list the devices' UUID and you can use this command in a script to properly identify a specific HDD since UUID are uniquely assigned to a specific HDD.

You can find more information here, but note that the command vol_id is not available since ubuntu 9.10.

share|improve this answer
    
personally i'd use volume labels instead of UUIDs (i prefer human-readable to guaranteed-unique), but if vol_id is unavailable i'm not sure what else to use. surely udev/DeviceKit provides some tool to do this, but i'm not finding it ATM. if all else fails, tune2fs -l /dev/sdXN | grep volume would get it. – quack quixote Mar 15 '10 at 7:55
    
blkid -s label /dev/sdXN should do the job. The only problem I see with using labels is that there is no command-line program for setting labels for the different file-system types. See help.ubuntu.com/community/RenameUSBDrive#Command%20line – mrucci Mar 15 '10 at 8:49
    
almost: blkid -s LABEL /dev/sdXN (the tags are case sensitive). your point about setting them is wrong tho -- there are commandline programs for setting labels, it's just that each filesystem needs a different program, which can be a pain. but i generally set labels when formatting; i rarely need to adjust them later. – quack quixote Mar 16 '10 at 13:07

This may be considered a workaround, and not a direct answer to your question, but my approach to this problem is to create a different file on each HDD.

I have several external HDDs, so I use touch to create a zero-byte file like 'Music' on one, or 'Videos' on another, and then my backup script can detect what to write to it.

I do hope you get a definite answer to your question. I'll be interested to see it.

share|improve this answer

Just responding to my own question for anyone else's future reference...

I've found that a good method for distinguishing between devices is to just give them labels using e2label.

Also, I can distinguish between devices here

/dev/disk/by-label/

and

/dev/disk/by-uuid
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .