Define sda as the smallest disk

Diego Zuccato diego.zuccato at unibo.it
Fri Feb 23 14:34:51 CET 2024


Just a followup.
My script had a serious bug (plus a typo), too: since it gets sourced, 
$0 is not what I expected :( After many failed atttempts finally I 
noticed it and patched.

What I just tested:
-8<--
root at fai:/srv/fai/config/class# cat 99-disklist.sh
#! /bin/bash

mydisks() {

     find $* -type l -printf "%f %l\n" | grep -Pv 
'^md|-part\d|^wwn-|^nvme-eui|^nvme-nvme' | egrep '^scsi|^ata|^nvme' | 
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

filter='nvme*'

# can not use $0: script is sourced, not run explicitly !
datadir=$FAI/class/99-disklist.d
echo "**** Testing $datadir/$HOSTNAME"
if [ -f $datadir/$HOSTNAME ] ; then
     # Source host-specific list. Can define a new list or override filter
     . $datadir/$HOSTNAME
fi

if [ -z $newlist ]; then
     echo "newlist is empty, filter=$filter"
     newlist=$(mydisks $filter )
fi

if [ -n "$newlist" ]; then
     echo New disklist in 99-disklist.sh: $newlist
     echo "disklist=\"$newlist\" # $0" >> $LOGDIR/additional.var
fi
-8<--

And 99-disklist.d/fast00 (the host I'm installing) contains:
-8<--
#!/bin/bash
#filter='scsi-*'
#newlist='sdt '
. /usr/lib/fai/subroutines

newlist=$(smallestdisk)
-8<--

Hope it can be useful for others.

Diego

Il 22/02/2024 09:02, Diego Zuccato ha scritto:
> I think there's a bug (well, a missing piece) in 99-disklist.sh: egrep 
> ignores SCSI disk, considering just ATA and NVME.
> 
> If it can be useful, I also modified the script to look into 
> 99-disklist.d for hostname-specific configs (I prefer having separate 
> files instead of embedding in a bigger one):
> 
> -8<-- 99-disklist -8<--
> #! /bin/bash
> 
> mydisks() {
> 
>      find $* -type l -printf "%f %l\n" | grep -Pv 
> '^md|-part\d|^wwn-|^nvme-eui|^nvme-nvme' | egrep '^scsi|^ata|^nvme' | 
> 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
> 
> filter='nvme*'
> 
> if [ -f $0.d/$HOSTNAME ] ; then
>      # Source host-specific list.
>      # Can define a new list or just override filter
>      . $0.d/$HOSTNAME
> fi
> 
> if [ -z $newlist ]; then
>      newlist=$(mydisks $filter* )
> fi
> 
> if [ -n "$newlist" ]; then
>      echo New disklist: $newlist
>      echo disklist=\"$newlist\" >> $LOGDIR/additional.var
> fi
> -8<--
> Note the missing .sh extension.
> 
> The 99-disklist.d/$HOSTNAME file is just:
> -8<--
> #!/bin/bash
> filter='scsi-*'
> # or
> #newlist='sda'
> -8<--
> 
> HiH.
> 
> Diego
> 
> Il 31/01/2024 13:49, Thomas Lange ha scritto:
>> Hi all,
>>
>> that is the example how to change the shell variable $disklist:
>> https://fai-project.org/download/misc/99-disklist.sh
>>
>> Create the script class/99-disklist.sh in your config space 
>> (/s/rv/fai/config)
>>
>> These are the imprtant lines:
>>
>> if [ -n "$newlist" ]; then
>>      echo New disklist: $newlist
>>      echo disklist=\"$newlist\" >> $LOGDIR/additional.var
>> fi
>>
>>
>> This script writes the new valuespf disklist to
>> $LOGDIR/additional.var. Then FAI will parse it and sets the new value
>> for disklist before calling setup-storage.
>>
>> regards Thomas
> 

-- 
Diego Zuccato
DIFA - Dip. di Fisica e Astronomia
Servizi Informatici
Alma Mater Studiorum - Università di Bologna
V.le Berti-Pichat 6/2 - 40127 Bologna - Italy
tel.: +39 051 20 95786


More information about the linux-fai mailing list