Re: Define sda as the smallest disk
Hi Diego, Nice catch for the scsi grep. Will try that ASAP. Thanks Le ven. 23 févr. 2024 à 14:35, Diego Zuccato a écrit : > > 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@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
Re: Define sda as the smallest disk
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@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
Re: Define sda as the smallest disk
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
Re: Define sda as the smallest disk
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
Re: Define sda as the smallest disk
I know I could change directly the subroutine code from the "set_disk_info" function, but if I can avoid doing this and doing something better / cleaner... Le mer. 31 janv. 2024 à 12:48, Rémy Dernat a écrit : > > Ok, Thanks Thomas. > > So, let's say I want to get a `$disklist` as an environment variable > for the setup-storage step (or '-D'), and this disklist is : > `$(newdisk_list=$(all_disks_by_size |sort -r | tr "\n" " ")` > > How could I change my disk_config file to use this new list ? By > modifying `class/20-hw-detect.sh` (?); in the beginning of the > scripts, it says that the outputs of `*.sh` scripts are ignored ... > > Thanks, > Rémy > > Le mer. 31 janv. 2024 à 12:42, Thomas Lange a écrit : > > > > > On Wed, 31 Jan 2024 11:15:46 +0100, Rémy Dernat > > > said: > > > > > Hi Thomas, > > > That looks fantastic. Is there any examples to use these functions ? > > No, the documentation is really bad. In FAI the disk list is created > > by these two steps: > > > > set_bootstick > > all_disks_and_size | checkdisk $FAI_BOOTSTICK | once_only > > > > > > > > From the sources (lib/subroutines) > > > > matchdisks() { > > # matchdisks PATTERN PATTERN > > > > checkdisk() { > > # read lines with device name and size and check if device is a disk > > # $1 can be a device name that will be ignored. Used for the device > > # name of the USB stick if we boot from it > > > > disks_by_id() { > > # list all disks by ID and their link to the device name > > > > all_disks_and_size() { > > # print a list of devices and their block size > > > > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > all_disks_by_size() { > > all_disks_and_size | sort -nr -k2 | checkdisk $FAI_BOOTSTICK > > } > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > largestdisk() { > > all_disks_and_size | sort -nr -k2 | checkdisk $FAI_BOOTSTICK | head -1 > > } > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > smallestdisk() { > > all_disks_and_size | sort -n -k2 | checkdisk $FAI_BOOTSTICK | head -1 > > } > > > > set_bootstick() { > > # determine the device of the USB stick we boot from > > # sets the variable FAI_BOOTSTICK > > > > > > > > -- > > regards Thomas
Re: Define sda as the smallest disk
Ok, Thanks Thomas. So, let's say I want to get a `$disklist` as an environment variable for the setup-storage step (or '-D'), and this disklist is : `$(newdisk_list=$(all_disks_by_size |sort -r | tr "\n" " ")` How could I change my disk_config file to use this new list ? By modifying `class/20-hw-detect.sh` (?); in the beginning of the scripts, it says that the outputs of `*.sh` scripts are ignored ... Thanks, Rémy Le mer. 31 janv. 2024 à 12:42, Thomas Lange a écrit : > > > On Wed, 31 Jan 2024 11:15:46 +0100, Rémy Dernat > > said: > > > Hi Thomas, > > That looks fantastic. Is there any examples to use these functions ? > No, the documentation is really bad. In FAI the disk list is created > by these two steps: > > set_bootstick > all_disks_and_size | checkdisk $FAI_BOOTSTICK | once_only > > > > From the sources (lib/subroutines) > > matchdisks() { > # matchdisks PATTERN PATTERN > > checkdisk() { > # read lines with device name and size and check if device is a disk > # $1 can be a device name that will be ignored. Used for the device > # name of the USB stick if we boot from it > > disks_by_id() { > # list all disks by ID and their link to the device name > > all_disks_and_size() { > # print a list of devices and their block size > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > all_disks_by_size() { > all_disks_and_size | sort -nr -k2 | checkdisk $FAI_BOOTSTICK > } > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > largestdisk() { > all_disks_and_size | sort -nr -k2 | checkdisk $FAI_BOOTSTICK | head -1 > } > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > smallestdisk() { > all_disks_and_size | sort -n -k2 | checkdisk $FAI_BOOTSTICK | head -1 > } > > set_bootstick() { > # determine the device of the USB stick we boot from > # sets the variable FAI_BOOTSTICK > > > > -- > regards Thomas
Re: Define sda as the smallest disk
> On Wed, 31 Jan 2024 11:15:46 +0100, Rémy Dernat said: > Hi Thomas, > That looks fantastic. Is there any examples to use these functions ? No, the documentation is really bad. In FAI the disk list is created by these two steps: set_bootstick all_disks_and_size | checkdisk $FAI_BOOTSTICK | once_only >From the sources (lib/subroutines) matchdisks() { # matchdisks PATTERN PATTERN checkdisk() { # read lines with device name and size and check if device is a disk # $1 can be a device name that will be ignored. Used for the device # name of the USB stick if we boot from it disks_by_id() { # list all disks by ID and their link to the device name all_disks_and_size() { # print a list of devices and their block size # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - all_disks_by_size() { all_disks_and_size | sort -nr -k2 | checkdisk $FAI_BOOTSTICK } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - largestdisk() { all_disks_and_size | sort -nr -k2 | checkdisk $FAI_BOOTSTICK | head -1 } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - smallestdisk() { all_disks_and_size | sort -n -k2 | checkdisk $FAI_BOOTSTICK | head -1 } set_bootstick() { # determine the device of the USB stick we boot from # sets the variable FAI_BOOTSTICK -- regards Thomas
Re: Define sda as the smallest disk
Hi Thomas, That looks fantastic. Is there any examples to use these functions ? Best regards, Rémy Le lun. 29 janv. 2024 à 17:31, Thomas Lange a écrit : > > FAI 6.2 now provides some helper functions to create your own disklist: > > grepv_disks() > grep_disks() > notmatchdisks() > matchdisks() > smallestdisk() > largestdisk() > all_disks_by_size() > all_disks_and_size() > once_only() > checkdisk() > disks_by_id() > > > Here's an older script how to change the disklist: > https://fai-project.org/download/misc/99-disklist.sh > > > > On Mon, 29 Jan 2024 17:13:39 +0100, Rémy Dernat > > said: > > > > So, I would like to define something like disk1 / sda is : > > fdisk -l 2>/dev/null |awk '/Disk / {print $2,$3}' |sort -n -k2 |head -1 > > > Then, this would be used by setup-storage. > > -- > regards Thomas
Re: Define sda as the smallest disk
FAI 6.2 now provides some helper functions to create your own disklist: grepv_disks() grep_disks() notmatchdisks() matchdisks() smallestdisk() largestdisk() all_disks_by_size() all_disks_and_size() once_only() checkdisk() disks_by_id() Here's an older script how to change the disklist: https://fai-project.org/download/misc/99-disklist.sh > On Mon, 29 Jan 2024 17:13:39 +0100, Rémy Dernat said: > So, I would like to define something like disk1 / sda is : > fdisk -l 2>/dev/null |awk '/Disk / {print $2,$3}' |sort -n -k2 |head -1 > Then, this would be used by setup-storage. -- regards Thomas