Configure LSI MegaRAID SAS controller during RHEL kickstart

I recently had to come up with a solution to simplify the installation of RHEL 5 on a server that had an integrated LSI MegaRAID SAS controller. I wanted to make this as easy and automated as possible, so manually configuring the RAID prior to OS installation was out of the question. What I was looking for was to be able to simply kickstart the server and have the RAID configured, partition the new logical unit, set up LVM, create the file systems and install the OS all automatically.

I was able to accomplish my goals using a kickstart pre script. The script retrieves the MegaCli utility from an FTP server to create a RAID1 volume. And then also handles the partitioning and LVM/filesystem configuration before turning the rest back to the normal anaconda installation process. The reason I had to do the partitioning within the pre-script was because anaconda had already done the disk probing when it started and therefore has no knowledge of the RAID1 volume that is created in the pre-script. And there is no way to tell anaconda to rescan for disks after the fact.

You’ll want to grab the MegaCli64 (I used the 64-bit version) and the library from wherever you have gotten the utility from. This probably came either with media supplied along with the server or as a download from the server vendors website. Alternatively you can download it from the LSI website support section. These 2 files will need to be placed on an FTP server.

Below is the kickstart pre-script that was used. You’ll obviously need to tweak this to suit your specific needs..

#                     PRE-INSTALL HARDWARE RAID SETUP                          #

SERVER=''   # ftp server containing MegaCli and its library

exec < /dev/tty3 > /dev/tty3 2>&1
chvt 3

echo -e "\n\nConfiguring the MegaRAID SAS controller ..."

cd /tmp

echo "open $SERVER
user ftp
type binary
get MegaCli64
quit" | ftp -in

if [ -f MegaCli64 ]; then
  chmod +x MegaCli64
  # Probe for disks
  ./MegaCli64 -PDList -aALL | egrep 'Enclosure Device ID|Slot Number' > /tmp/mirror_disks

  IFS="$(echo -e "\n\r")"

  # Figure out where the disks are
  for line in $(cat /tmp/mirror_disks); do
    if [[ $line =~ Enclosure ]]; then
      e[$c]=$( echo $line | awk -F: '/Enclosure/{print $2}' | sed -e 's/^\s*//' -e 's/\s*$//' )
    elif [[ $line =~ Slot ]]; then
      (( c-- ))
      s[$c]=$( echo $line | awk -F: '/Slot/{print $2}' | sed -e 's/^\s*//' -e 's/\s*$//' )
    (( c++ ))


  rm /tmp/mirror_disks

  # Clear any existing configuration
  ./MegaCli64 -CfgClr -aALL
  # Ensure the drives are in a good state 
  ./MegaCli64 -PDMakeGood -PhysDrv "[${e[0]}:${s[0]},${e[1]}:${s[1]}]" -Force -a0
  # Create a RAID1 volume from the detected disks
  ./MegaCli64 -CfgLdAdd -r1 "[${e[0]}:${s[0]},${e[1]}:${s[1]}]" -a0

  test -b /dev/sda  || mknod /dev/sda  b 8 0
  test -b /dev/sda1 || mknod /dev/sda1 b 8 1
  test -b /dev/sda2 || mknod /dev/sda2 b 8 2

  python /mnt/runtime/usr/lib/anaconda/ driveDict
  echo "FAILED - Could not obtain MegaCli utility from FTP server ($SERVER)"

cd - >/dev/null 2>&1

# We clear to bootblock and create the partitions here in the pre
# script because anaconda only ever scans the disks when it first starts up. However
# we didn't build the RAID array until the pre script, so anaconda would never have
# detected the disk and would have given a "no disk detected" error when it tried to
# partition if attempted from the main kickstart commands section.

echo "Clearing disk partition table ..."
dd if=/dev/zero of=/dev/sda bs=512 count=1
echo "Creating DOS label on disk ..."
parted -s /dev/sda mklabel msdos
echo "Creating primary boot partition ..."
parted -s /dev/sda mkpart primary ext3 0 200
echo "Creating primary LVM partition ..."
parted -s /dev/sda mkpart primary ext3 200 40000

sleep 5

chvt 1

cat <<- EOF
  part /boot --onpart=/dev/sda1
  part pv.00 --size=40000  --onpart=/dev/sda2
  volgroup rootvg --pesize=32768 pv.00
  logvol / --fstype ext3 --name=lvroot --vgname=rootvg --size=6144
  logvol /home --fstype ext3 --name=lvhome --vgname=rootvg --size=1024
  logvol /tmp --fstype ext3 --name=lvtmp --vgname=rootvg --size=1024
  logvol /var --fstype ext3 --name=lvvar --vgname=rootvg --size=4096
  logvol swap --fstype swap --name=lvswap --vgname=rootvg --size=2048 --grow --maxsize=4096
  bootloader --location mbr --driveorder=sda --append=
) > /tmp/filesystems

In addition, you’ll need to add the following line to the main commands section which is located at the start of the kickstart file.

%include /tmp/filesystems

Strictly speaking you don’t need to handle the logical volume/filesystem section in the pre-script. I chose to do it that way since I was doing the rest of the disk work in the pre-script and keeping it all together seemed more tidy.

1 comment

  1. G February 14, 2015 6:49 pm  Reply

    I’ve been heavily using this as a reference to do something similar, Thank you!

Leave a comment

Your email address will not be published. Required fields are marked *