Friday, June 28, 2024

Oracle ASM/AFD disks automotive script

Oracle ASM/AFD disks automotive script

                          Alireza Kamrani.

                              06/28/2024

Creating partitions is not a mandatory step when provisioning disks and is a specific procedure dependent on the version of Oracle ASM and the peculiarities of storage level planning. Let's delve into the methods of automation when partitions are indeed necessary. 

Below is a bash script that will generate the necessary commands:


An important parameter of the script is:


lvPrefix="mp_";


which determines the prefix for multipath aliases that will be selected from the list of devices for generating commands:


#/bin/bash

lvPrefix="mp_";


while read -r lvDisk lvType lvSize; do

  lvASMDiskName=$(echo $lvDisk | sed -e "s/$lvPrefix//g" | tr '[:lower:]' '[:upper:]');


 read lvType lvPhysSec lvLogSec lvAlignment lvOptIO lvSize <<< $(lsblk -l /dev/mapper/$lvDisk -o TYPE,PHY-SEC,LOG-SEC,ALIGNMENT,OPT-IO,SIZE | awk '$1 == "mpath"');

  if [[ $lvType=="mpath" ]]; then

    if [[ $lvPhysSec -ne $lvLogSec ]]; then lvSec=$lvLogSec; else lvSec=$lvPhysSec; fi;

    lvFirstSec=$(( ( $lvOptIO + $lvAlignment ) / $lvSec ));

echo "parted -s /dev/mapper/$lvDisk mklabel GPT;parted /dev/mapper/$lvDisk mkpart primary ${lvFirstSec}s 100%;parted -s /dev/mapper/$lvDisk name 1 $lvASMDiskName; #<--size is $lvSize";

lvChecks="$lvChecks\nparted /dev/mapper/$lvDisk align-check optimal 1;";

  else

echo "[ERROR] issue during fisrst sector calculation for disk '$lvPhysDisk'."

 fi;

done < <(lsblk -l -o NAME,TYPE,SIZE | awk -v prefix="$lvPrefix" '$2 == "mpath" && ($1 ~ "^" prefix)' | sort -u);


-----

The loop iterates over the list of disks obtained by executing the command:


lsblk -l -o NAME,TYPE,SIZE | awk -v prefix="$lvPrefix" '$2 == "mpath" && ($1 ~ "^" prefix)' | sort -u

------

A) A partition label, based on the multipath alias without the prefix. That is, a partition on a disk with the alias [mp_data00] will have the label [DATA00]. 

B) An offset parameter based on the type of sector (physical/logical), the optimal size of input/output, and alignment. The result of execution is a set of commands ready for usage:

parted -s /dev/sda mklabel GPT;parted /dev/sda mkpart primary 2048s 100%;parted -s /dev/sda name 1 DISK00; #<--size is 250.000 GB

parted /dev/sda align-check optimal 1;


parted -s /dev/sdb mklabel GPT;parted /dev/sdb mkpart primary 2048s 100%;parted -s /dev/sdb name 1 DISK01; #<--size is 250.000 GB

parted /dev/sda align-check optimal 1;


parted -s /dev/sdb mklabel GPT;parted /dev/sdb mkpart primary 2048s 100%;parted -s /dev/sdb name 1 DISK02; #<--size is 250.000 GB

parted /dev/sdb align-check optimal 1;

----

For each disk, there will be a line for creating a partition and a command for checking alignment. A comment in the form of the disk size is added for additional reliability. When ordering disks, you likely remember their size and at least will be able to see an obvious difference in case of allocation errors or incorrect disk selection.

2. Creating ASM Disks (ASM lib)

At this stage, we will generate commands for creating disks using the partition labels set in the previous script

#!/bin/bash

lvPrefix="mp_";

while read -r lvPartition lvType lvPartLabel lvSize; do

  if [[ -z $lvPartition ]]; then

    continue;

  fi

 echo "oracleasm createdisk $lvPartLabel /dev/mapper/${lvPartition}; #<--Size : $lvSize";

done < <(lsblk -l -o NAME,TYPE,PARTLABEL,SIZE | awk -v prefix="$lvPrefix" '$2 == "part" && ($1 ~ "^" prefix)' | sort -u);


Output:


oracleasm createdisk DATA00 /dev/sdb1; #<--Size : 250G

oracleasm createdisk DATA01 /dev/sdc1; #<--Size : 250G

oracleasm createdisk DATA02 /dev/sdd1; #<--Size : 250G

Overall, this approach can also be used for other libraries (e.g., Oracle AFD) and modified for cases without creating partitions.


Sincerely, 

Alireza Kamrani

06/28/2024


No comments:

Post a Comment

Oracle ASM/AFD disks automotive script

Oracle ASM/AFD disks automotive script                           Alireza Kamrani.                               06/28/2024 Creating partitio...