How to handle large number of disk devices in "arbitrary" order

Thomas Lange lange at informatik.uni-koeln.de
Wed Nov 20 16:15:47 CET 2013


Hi all,

in late 2011 there was a discussion on linux-fai about:

  > How to handle large number of disk devices in "arbitrary" order?
  > Carsten Aulbert carsten at welcomes-you.com
  > Mon Nov 14 16:54:24 CET 2011

  > We have a couple of machines with a largish number of disk drives (currently 
  > up to 48) plus one or more "flash drives" - could be USB thumb drive, SATA 
  > disk on module, SSD, whatever. Of course the order in which these are detected 
  > is not always guaranteed to be the same which makes using setup-storage 
  > cumbersome and/or impossible to partition/install.

Here's my solution for that.

setup-storage uses the variable disklist for mapping physical disks
sda, sdb, sdc... in disk_config/* to diskN. The first disk listed in 
the variable $disklist becomes disk1 and so on.

You can redefine this variable in a class/*,source script, so that a
different order is used. Making this disklist more dynamic can help
you that a certain disk always becomes disk1 for e.g., independent on
if it's sda, sdd or whatever.


Here's an example. I have two SSD and four hard disks in my
testserver. Once I booted the machine I got this assignment in
/dev/disks/by-id (made by udev)

scsi-SATA_WDC_WD3000FYYZ-_WD-WMC1F0680952    sde
scsi-SATA_WDC_WD3000FYYZ-_WD-WCC131067518    sda
scsi-SATA_WDC_WD3000FYYZ-_WD-WMC1F0499068    sdd
scsi-SATA_WDC_WD3000FYYZ-_WD-WMC1F0399095    sdf
scsi-SATA_INTEL_SSDSC2BA4BTTV3276020F400HGN  sdb
scsi-SATA_INTEL_SSDSC2BB2BTWL332303LR240NGN  sdc

I like to have following order. First, both SSDs (alphabetical order is
fine, since the 400G will be first) then the hard disks ending in
following pattern: *068 *952 *095 *518

I like to call

  mydisks *SSD* *068 *952 *095 *518

somewhere and I my 400GB SSD will become disk1, the 240GB SSd
disk2,... and the disk with serial number *518 will become disk6.
Even if the OS assignment of the disks is changing the regex
determines which disk becomes disk1, disk2,...


Here's what my new FAI script does:

Executing /var/lib/fai/config/class/99-disklist.source.
New disklist: sdb sdc sdd sde sdf sda
99-disklist.source   OK.

Using shell globbing, you can define whatever order you like for your
disks. You can even exclude some disks from the list, or if your regex
is wrong have a disk multiple times in it (you should not do this).

Here's the 99-disklist.source script:

#! /bin/bash

mydisks() {

    find $* -type l -printf "%f %l\n" | egrep -v '^md|-part|wwn-' | egrep ^scsi | sed -e 's#.*/##g'| tr '\n' ' '
}

# This is really important, because we use shell globbing for creating the list of disks
cd /dev/disk/by-id || echo Cannot get disk information


case $HOSTNAME in
    testserver) disklist=$(mydisks *SSD* *068 *952 *095 *518) ;;
esac

echo New disklist: $disklist
echo disklist=\"$disklist\" >> $LOGDIR/additional.var

# end of script


Got it? It's pretty simple IMO. If you have any questions, don't hesitabe to ask.

-- 
regards Thomas


More information about the linux-fai mailing list