Optimizing Oracle ASM Disk creation, using bash scripts – part #1 (multipath)
Quite often in large companies, the allocation and partitioning of disks for Oracle Automatic Storage Management (Oracle ASM) are performed by different teams. This can lead to the following negative consequences:
In my opinion, the best way to avoid these problems is to use a unified naming convention at all levels and to carry out operations using scripts.
In this article, we will explore a scenario where disks were allocated from network storage and represented at the OS level through the use of multipath technology.
Multipath in Linux is a technology that allows optimizing access to data storage through multiple paths or interfaces. This is particularly useful in environments with large data volumes and high availability, where it is important to ensure reliability and higher performance in case of failure of one of the paths or storage devices. At the OS level, each disk will be represented by several LUNs. Multipath will allow managing these LUNs from different paths (ports, interfaces, etc.) and provides the capability for automatic switching to an alternative path in case of failure of one.
For example, this is how a disk with two paths is presented when executing the [multipath -ll] command:
mydisk (3600a0980383033424635345637383551) dm-1
[size=2.0G][features=1 queue_if_no_path][hwhandler=1 rdac][rw]
\_ round-robin 0 [prio=2][active]
\_ 2:0:0:1 sdb 8:16 [active][ready]
\_ round-robin 0 [prio=1][enabled]
\_ 1:0:0:1 sda 8:0 [active][ghost]
Each disk in Linux multipath configuration possesses a crucial and beneficial attribute known as an 'alias'. An alias in Linux multipath is essentially a user-defined name or label assigned to a specific path or disk device. This feature offers a human-readable and meaningful identifier, simplifying the management and referencing of multipath configurations. Typically, aliases are configured in the file '/etc/multipath.conf', following a specific format:
multipaths {
multipath {
wwid <WWID>
alias mydisk
}
}
For building a simple and logically comprehensible naming scheme, an correct alias is a necessary precondition on which we will create disk partitions and disk names in ASM. The overall scheme looks as follows:
<multipath alias> --> <partition label> --> <ASM disks name>
For a practical example, imagine that the storage team has created and connected three disks from the network storage system and provided each of them with a understandable alias:
mp_disk00
mp_disk01
mp_disk02
1. Creating Partitions
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:
#!/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);
echo -e "$lvChecks";
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.
The loop iterates over the list of disks obtained by executing the command:
Recommended by LinkedIn
lsblk -l -o NAME,TYPE,SIZE | awk -v prefix="$lvPrefix" '$2 == "mpath" && ($1 ~ "^" prefix)' | sort -u
resulting in the name and size of each disk:
mp_disk00 mpath 250G
mp_disk01 mpath 250G
mp_disk02 mpath 250G
Next, in the loop body, the following are calculated:
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.
After creating the partitions, we move to the next step.
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);
Again, the 'lvPrefix' here defines the mask for the disks to be processed.
The output of the command:
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.
(!) Please note that all scripts are written for conditions that may not be relevant to the standards of a specific technical implementation. Always check the code for compliance and first test in a non-productive environment.
Conclusion:
The article offers a detailed guide on scripting to streamline the creation of Oracle Automatic Storage Management (ASM) disks for the case of multipath technology usage. It methodically outlines the process, leveraging disk and partition attributes in a sequential manner. This approach simplifies and automates the setup of ASM disks, ensuring a more efficient and error-resistant deployment in database management systems.
Co-Founder/SAP Technical Expert at DigitalMeta, s.r.o.
2yNice one as always! I'll be waiting for continuation of the series. :)