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

Tip: Safely unmap VSCSI Devices



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}'

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
VIOS1+2# sh


If you don't want to remove all free hdisks you could limit the search to only the hdisks we unmapped before:

VIOS1+2# cat freepvids.txt | while read pvid ; do /usr/ios/cli/ioscli lspv -free | grep $pvid | awk '{print "rmdev -dl "$1" #"$2}' ; done | tee
VIOS1+2# 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

Also on unixwerk