Skip to content

快速列出ASM DISK和OS DISK DEV设备对应的脚本

#!/bin/bash -x
ORACLEASM=/etc/init.d/oracleasm
echo"ASM Diskgroup Mapping luns"
echo"----------------------------------------------------"
for f in `$ORACLEASMlistdisks`
do
dp=`$ORACLEASM querydisk -p  $f |head-2| grep /dev | awk-F: '{print $1}'`
echo"$f: $dp"
done

Oracle官方有使用KFED更为便捷的脚本,该文档介绍如下:

 

That information can be obtained with the following shell script:

#!/bin/bash
for asmlibdisk in `ls /dev/oracleasm/disks/*`
do
echo “ASMLIB disk name: $asmlibdisk”
asmdisk=`kfed read $asmlibdisk | grep dskname | tr -s ‘ ‘| cut -f2 -d’ ‘`
echo “ASM disk name: $asmdisk”
majorminor=`ls -l $asmlibdisk | tr -s ‘ ‘ | cut -f5,6 -d’ ‘`
device=`ls -l /dev | tr -s ‘ ‘ | grep -w “$majorminor” | cut -f10 -d’ ‘`
echo “Device path: /dev/$device”
done

The script can be run as OS user that owns ASM or Grid Infrastructure home (oracle/grid), i.e. it does not need to be run as privileged user. The only requirement it that kfed binary exists and that it is in the PATH.

If an ASMLIB disk was already deleted, it will not show up in /dev/oracleasm/disks. We can check for devices that are (or were) associated with ASM with the following shell script:

#!/bin/bash
for device in `ls /dev/sd*`
do
asmdisk=`kfed read $device | grep ORCL | tr -s ‘ ‘ | cut -f2 -d’ ‘ | cut -c1-4`
if [ “$asmdisk” = “ORCL” ]
then
echo “Disk device $device may be an ASM disk”
fi
done

The second scripts takes a peek at sd devices in /dev, so in addition to the requirement for the kfed binary to be in the PATH, it also needs to be run as privileged user. Of course we can look at /dev/dm*, /dev/mapper, etc or all devices in /dev, although that may not be a good idea.

The kfed binary should be available in RDBMS home (prior to version 11.2) and in the Grid Infrastructure home (in version 11.2 and later). If the binary is not there, it can be built as follows:

cd $ORACLE_HOME/rdbms/lib
make -f ins* ikfed

Where ORACLE_HOME is the RDBMS home (prior to version 11.2) and the Grid Infrastructure home in version 11.2 and later.

The same can be achieved without kfed with a script like this:

#!/bin/bash
for device in `ls /dev/sd*`
do
asmdisk=`od -c $device | head | grep 0000040 | tr -d ‘ ‘ | cut -c8-11`
if [ “$asmdisk” = “ORCL” ]
then
echo “Disk device $device may be an ASM disk”
fi
done