Advice on User Scripts for Creating RAID Volumes during commissioning

Apologies TL;DR

I’m wondering if anyone can weigh in on this and let me know if I’m on the right track or if there’s a better way to do this.

I’ve gotten a fresh bunch of servers with fresh hard drives in them. When the nodes get enlisted they turn up ‘new’ without any storage, simply because no Logical Volume(s) has been created yet.
I could simply create the RAID volumes on the WEBcli before the PXE boot, but I’m lazy and doing this at scale is not really feasible (cattle vs pets)

So I (plagiarised) came up with this script which installs the MegaRAID cli and continues to do a fancy ‘for loop’ and creates standalone Logical Drives for each disk in the machine which the node sees on next boot as /dev/sda, /dev/sdb and dev/sdc.

#!/bin/bash
#Script hacked up by Sean Shuping for MAAS enrollment
#references:
# https://phoenixnap.com/kb/how-to-set-up-hardware-raid-megacli
# http://erikimh.com/megacli-cheatsheet/
#Download and install LSI MegaRAID Megacli
#Install alien, unzip and libncurses5 to convert rpm package to deb
if lspci | grep -q MegaRAID
then 
echo "MegaRAID Controller found will check for volumes"
sudo apt update
sudo apt -y install alien unzip libncurses5
wget https://github.com/dvntstph/devzero-misc/raw/master/MAAS/LSiMegaRaid/8-07-14_MegaCLI.zip
unzip *Mega*.zip
sudo alien -k --scripts Linux/MegaCli-8.07.14-1.noarch.rpm
sudo dpkg -i *megacli*.deb
 if sudo /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -LAll -a0 | grep -q "No Virtual Drive Configured"
 then 
 echo "Will continue to create Volumes"
	 DEVICEID=$(sudo /opt/MegaRAID/MegaCli/MegaCli64 -EncInfo -aALL | grep "Device ID" | awk -F: '{print $2}')
	 for SLOTNUMBER in $(sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL  | grep "Slot Number" | awk -F: '{print $2}')
	 do 
	 sudo /opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r0 [$DEVICEID:$SLOTNUMBER] -a0 
	 done
	 else
	 echo " At least one Volume Found, Skipping"
 fi
else 
echo "MegaRAID Controller not found, nothing to see here"; exit
fi

The issue though is that my user script gets executed last, and as a result I need to commission the nodes twice, because the SMARTctl validate ‘fails’ the first time as there’s no volume to check (yet). On the second run of commissioning, the nodes ‘pass’ and move to a ready state because the Volume was created at the end of the first round of commissioning.

Is there a way to bump the order of Commissioning Scripts or am I going about this the wrong way.

I also found that when composing Virtual Machines on KVM pods those guests were automatically running my user script, so I had to modify the script logic which checks to see if there is in fact a RAID card present, if not it gracefully exits so that KVM guests wouldn’t fail their commissioning.

I renamed with script from MegaRAID_single_RAID0.sh to 00-b-User-MegaRAID_single_RAID0.sh.

This floats the commissioning script higher in the execution order and now runs before all the native MAAS commissioning scripts.
When a new node is provisioned, the storage gets created and all the validation are successful.

1 Like

brilliant work, @dvnt! kudos.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.