Sometimes you may need to map ASM Disks to its physical devices.
If they are based on ASMLib you will see their ASM name, ie: ORCL:VOL1 when querying v$asm_disk
When running oracleasm querydisk VOL1 you will get in addition the major - minor numbers, that can be used to match the physical device, ie:
Disk "VOL1" is a valid ASM disk on device [8, 97]
[root@orcldb2 ~]# ls -l /dev | grep 8, | grep 97
brw-rw---- 1 root disk 8, 81 Nov 4 13:02 sdg1
#!/bin/ksh
for i in `/etc/init.d/oracleasm listdisks`
do
v_asmdisk=`/etc/init.d/oracleasm querydisk $i | awk '{print $2}'`
v_minor=`/etc/init.d/oracleasm querydisk $i | awk -F[ '{print $2}'| awk -F] '{print $1}' | awk '{print $1}'`
v_major=`/etc/init.d/oracleasm querydisk $i | awk -F[ '{print $2}'| awk -F] '{print $1}' | awk '{print $2}'`
v_device=`ls -la /dev | grep $v_minor | grep $v_major | awk '{print $10}'`
echo "ASM disk $v_asmdisk based on /dev/$v_device [$v_minor $v_major]"
done
---------- finish here ------------
The output looks like this:
ASM disk "VOL10" based on /dev/sdp1 [8, 241]
ASM disk "VOL2" based on /dev/sdh1 [8, 113]
ASM disk "VOL3" based on /dev/sdk1 [8, 161]
ASM disk "VOL4" based on /dev/sdi1 [8, 129]
ASM disk "VOL5" based on /dev/sdl1 [8, 177]
ASM disk "VOL6" based on /dev/sdj1 [8, 145]
ASM disk "VOL7" based on /dev/sdn1 [8, 209]
ASM disk "VOL8" based on /dev/sdo1 [8, 225]
ASM disk "VOL9" based on /dev/sdm1 [8, 193]
[root@orclp ~]# /etc/init.d/oracleasm querydisk vol1
Disk "VOL1" is a valid ASM disk on device [8, 81]
[root@orclp ~]# ls -l /dev | grep 8,| grep 81
brw-rw---- 1 root disk 8, 81 Oct 29 20:42 sdf1
[root@orclp ~]# powermt display dev=all
...
...
Pseudo name=emcpowerg
Symmetrix ID=000290101698
Logical device ID=0214
state=alive; policy=SymmOpt; priority=0; queued-IOs=0
==============================================================================
---------------- Host --------------- - Stor - -- I/O Path - -- Stats ---
### HW Path I/O Paths Interf. Mode State Q-IOs Errors
==============================================================================
1 qla2xxx sdf FA 7bB active alive 0 0
2 qla2xxx sdq FA 10bB active alive 0 0
...
...
brw------- 1 root root 120, 96 Oct 29 20:41 /dev/emcpowerg
brw------- 1 root root 120, 97 Nov 15 13:08 /dev/emcpowerg1
Comments (3)
Thanks, Alejandro. As with so much of your stuff, I found this quite helpful.
Might I suggest a small change to the script? As you have it, the script could potentially find false positives if the major number is part of the minor number (ie, [120, 0]).
I rewrote a script for our use like so:
------ start -------
#!/bin/ksh
/etc/init.d/oracleasm querydisk `/etc/init.d/oracleasm listdisks` | cut -f2,10,11 -d" " | perl -pe 's/"(.*)".*\[(.*), *(.*)\]/$1 $2 $3/g;' | while read v_asmdisk v_minor v_major
do
v_device=`ls -la /dev | grep " $v_minor, *$v_major " | awk '{print $10}'`
echo "ASM disk $v_asmdisk based on /dev/$v_device [$v_minor, $v_major]"
done
-------- end ---------
Fortunately, our EMC Powerpath is setup such that we can stop there.
Cheers!
Posted by Charles Schultz | November 16, 2007 1:49 PM
Posted on November 16, 2007 13:49
In linux you can query the /proc/partitions pseudofile with awk and grep without dealing with /dev directly
Regards
Posted by dballester | December 3, 2007 4:05 AM
Posted on December 3, 2007 04:05
More formated and informative output:
---------- start here ------------
#!/bin/ksh
export ORACLE_HOME=`grep ASM /etc/oratab | cut -d: -f2`
export PATH=$PATH:~$user/dba/scripts/bin:$ORACLE_HOME/bin
export SID=`grep ASM /etc/oratab | cut -d: -f1`
printf "\n%-15s %-14s %-11s %-7s\n" "ASM disk" "based on" "Minor,Major" "Size (Mb)"
printf "%-15s %-14s %-11s %-7s\n" "===============" "=============" "===========" "========="
for i in `/etc/init.d/oracleasm listdisks`
do
v_asmdisk=`/etc/init.d/oracleasm querydisk $i | awk '{print $2}'| sed 's/\"//g'`
v_minor=`/etc/init.d/oracleasm querydisk $i | awk -F[ '{print $2}'| awk -F] '{print $1}' | awk '{print $1}'`
v_major=`/etc/init.d/oracleasm querydisk $i | awk -F[ '{print $2}'| awk -F] '{print $1}' | awk '{print $2}'`
v_device=`ls -la /dev | awk -v v_minor=$v_minor -v v_major=$v_major '{if ( $5==v_minor ) { if ( $6==v_major ) { print $10}}}'`
v_size=`${ORACLE_HOME}/bin/kfod asm_diskstring='ORCL:*' disks=all | grep ${v_asmdisk} | awk '{print $2}'`
Total_size=`expr $Total_size + $v_size`
Formated_size=`echo $v_size | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'`
printf "%-15s %-14s %-11s %-7s\n" $v_asmdisk "/dev/$v_device" "[$v_minor $v_major]" $Formated_size
done
Formated_Total_size=`echo $Total_size | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'`
printf "\nTotal: %43s\n\n" $Formated_Total_size
---------- finish here ------------
Posted by Yossi Nixon | July 21, 2008 4:15 AM
Posted on July 21, 2008 04:15