Results 1 to 4 of 4

Thread: get device IDs from drive devices for fstab scripting

  1. #1

    Question 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?

  2. #2
    Join Date
    Jun 2008
    Location
    Norman, OK
    Posts
    209

    Default Re: get device IDs from drive devices for fstab scripting

    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
    Main Machine: Dell G7 running Ubuntu 18.04
    Server: Dell PowerEdge SC1430 running CentOS 7.x

  3. #3

    Default Re: get device IDs from drive devices for fstab scripting

    Quote Originally Posted by Pocadotty View Post
    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?
    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.
    Box 1: OpenSuse 11.1/Win7 | Linux 2.6.27 Gnome | AMD 64 X2 6000+ | nVidia 8600GT | 2GB RAM
    Box 2: OpenSuse 11.2 | Linux 2.6.31 Gnome | AMD 64 3000+ | ATI X800 Pro | 1GB RAM
    Box 3: Win7 Premium Home | Intel P4 3.0Gz | ATI AIW 2006 | 2GB RAM

  4. #4
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    32,324
    Blog Entries
    15

    Default Re: get device IDs from drive devices for fstab scripting

    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


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •