get device IDs from drive devices for fstab scripting

I am trying to write a script to modify /etc/fstab that will add entries for a number of partitions on different disks.

The only thing that I do not know how to do is to obtain a unique id such as the ones in /dev/disk/by-id/ to address by from a given partition (ie /dev/sdb1). In my fstab I noticed that in installation the system added fstab entries that are unique (in /dev/disk/by-id/)

I could simply do /dev/sdb1 and so on, but I would prefer a unique identifier so that each mount point is tied to a partition on a specific and unique physical drive.

i need this to be script-able if possible, if not I would still like to know.

any ideas?

the entries in /dev/disk/by-id are symbolic links to the real partitions, so you could could write your script to parse that directory to obtain which device-id maps to which partition.

For example on one of my hosts:

lrwxrwxrwx 1 root root 10 Apr 1 04:35 scsi-SATA_C300-CTFDDAC25600000000103602FD1876-part1 → …/…/sdb1

HTH

Or use the /dev/disk/uuid/

However, if you look closely at by-id these are unique by manufacturer part name and partition #.
3 partitions mounted on a Seagate 1Tb, 2 partitions mounted on a Samsung 300Gb, 4 partitions on a WD 2Tb, etc. that correspond to sda1-x, sdb1-x, sdc1-x.

On Sat, 2011-04-02 at 00:06 +0000, katanacb wrote:
> the entries in /dev/disk/by-id are symbolic links to the real
> partitions, so you could could write your script to parse that directory
> to obtain which device-id maps to which partition.
>
> For example on one of my hosts:
>
> lrwxrwxrwx 1 root root 10 Apr 1 04:35
> scsi-SATA_C300-CTFDDAC25600000000103602FD1876-part1 → …/…/sdb1
>
> HTH
>
Hi
The blkid command run as root user shows the relationship.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.4 (i586) Kernel 2.6.37.1-1.2-default
up 11 days 8:14, 3 users, load average: 0.12, 0.18, 0.14
ASUS eeePC 1000HE ATOM N280 1.66GHz | GPU Mobile 945GM/GMS/GME