GuestbookSign our guestbook ContactGet in touch with the authors ArchiveAll unixwerk articles since 2003
December 17, 2012

Tip: Safely unmap VSCSI Devices

 

Preface

Commands to be issued on the client LPAR are indicated by the prompt "LPAR# " - a prompt "VIOS1+2# " indicates a command to be issued on the vio servers. Further note that all commands on the VIO servers shown in the below examples have to be issued as root user not as user padmin.

How to Unmap Virtual SCSI Devices from a Client LPAR

Unmapping virtual SCSI devices from a client LPAR can be tricky since the direct relationship of a virtual target on the VIO server and the hdisk on the client LPAR is not always easy to find. The only safe indicator is the PVID. It must be the same on the VIO servers and the client LPAR. This small article describes an almost safe way to unmap a bunch of virtual target devices from a client without running the risk to unmap the wrong device.

So the first we do is to get a list of PVIDs associated to the free disks on the client LPAR:

LPAR# lspv | awk '$3 ~ /^None$/ {print $2}'
  00f64769dad0b7bf
  00f64769dad0b981
  00f64769eed5715e
  00f64769eed571fd
  00f64769eed5725f
  00f64769eed572c7
  00f64769eed5732f
  00f64769eed57397
  00f64769eed573f7
  00f64769eed57455
  00f64769eed574c7
  00f64769eed57547
  00f64769eed575ba
  00f64769eed57627
  00f64769eed5767b
  00f64769eed576d0
  00f64769eed5773b
  00f64769eed57794

Note: Check for HACMP heartbeat disks before considering all LUNs from the list as free.

We put the list of PVIDs into a textfile on the VIO servers:

VIOS1+2# vi /tmp/freepvids.txt

On both VIO servers we get a full list of "VTD <-> PVID" mappings:

VIOS1+2# cd /tmp
VIOS1+2# /usr/ios/cli/ioscli lsmap -all -field 'VTD' 'Backing device' \
           | while read a b c ; do echo "$a $b $c $([ -n "$c" ] && lspv|grep -w $c)" ; done | sed -e 's/^   //' \
           | tee allvscsimaps.out

We check "allvscsimaps.out" against "freepvids.txt":

VIOS1+2# for pvid in $(cat freepvids.txt) ; do echo $(grep -p $pvid allvscsimaps.out) ; done \
             | awk '{print "/usr/ios/cli/ioscli rmvdev -vtd "$2" #"$(NF-1)}' \
             | tee doit.rmvdevs

The result of the above command is a list of rmvdev commands to remove the mappings to the free disks on the LPAR. Don't run the file "doit.rmvdevs" now - we need to remove the disks from the client first:

LPAR# lspv | awk '$3 ~ /^None$/ {print "rmdev -dl "$1" #"$2}' | tee doit.rmdevs
LPAR# sh doit.rmdevs

Now we are ready to run the command file we just created on the VIO servers:

VIOS1+2# sh -x doit.rmvdevs

and we can go on removing the backend devices from the VIO servers:

VIOS1+2# /usr/ios/cli/ioscli lspv -free╣ | awk '/^hdisk/ {print "rmdev -dl "$1}' | tee doit.rmfreeluns.sh
VIOS1+2# sh doit.rmfreeluns.sh


╣ Don't use lspv -free if you use vpath or hdiskpower devices on the VIO servers since all underlying hdisk devices will be shown as free. But you could modify the line such that awk looks for your disk type instead, e.g.
/usr/ios/cli/ioscli lspv -free | awk '/^vpath/ {print "rmdev -dl "$1}' | tee doit.rmfreeluns.sh

Also on unixwerk