Moving LUN's between hosts using metarecover

Sometimes you might need to move a LUN between hosts X and Y on a SAN. Solaris has cool command, metarecover, that lets you do just that. First, you will need to stop all processes on X that might be using the given LUN. Then unmount the LUN and present it to the host Y. Now you can use metarecover to recover metadevice information from the LUN. Couple of things to remember:

There is -n switch that will cause dry run, i.e. metarecover will output what it would do - it will not actually perform recovery operation. Also, be careful about metadevice names on host Y and the ones you are trying to recover. I have not tried it, so I am not sure what would happen. It would probably bomb out. You could use metarename to rename Y’s existing metadevices and try to eliminate possible conflict before recovery.

root@ultra# metarecover -v c3t600508B400011C370000C00002970000d0s2 -p -d
Verifying on-disk structures on
c3t600508B400011C370000C00002970000d0s2.
The following extent headers were found on
c3t600508B400011C370000C00002970000d0s2.
Name  Seq#    Type               Offset
Length
d100     0   ALLOC            205635593
25165825
d110     0   ALLOC                16384
32769
d120     0   ALLOC                49153
32769
d130     0   ALLOC                81922
32769
d140     0   ALLOC               114691
41943041
d150     0   ALLOC             42057732
146800641
d160     0   ALLOC            188858373
2097153
d170     0   ALLOC            190955526
6291457
d180     0   ALLOC            197246983
6291457
d190     0   ALLOC            203538440
2097153
NONE     0     END            251609087
1
NONE     0    FREE            230801418
20807669
Found 10 soft partition(s) on c3t600508B400011C370000C00002970000d0s2.
Checking sequence numbers.
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 100
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 25165824
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               205635594               25165824
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 110
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 32768
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               16385           32768
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 120
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 32768
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               49154           32768
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 130
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 32768
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               81923           32768
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 140
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 41943040
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               114692          41943040
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 150
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 146800640
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               42057733                146800640
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 160
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 2097152
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               188858374               2097152
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 170
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 6291456
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               190955527               6291456
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 180
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 6291456
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               197246984               6291456
mp->c.un_type: 5
mp->c.un_size: 136
mp->c.un_self_id: 190
mp->un_status: 5
mp->un_numexts: 1
mp->un_length: 2097152
mp->un_dev: 30933010
mp->un_key: 43
Ext#    voff            poff            Len
0       0               203538441               2097152
The following soft partitions were found and will be added to
your metadevice configuration.
Name            Size     No. of Extents
d100        25165824         1
d110           32768         1
d120           32768         1
d130           32768         1
d140        41943040         1
d150       146800640         1
d160         2097152         1
d170         6291456         1
d180         6291456         1
d190         2097152         1
WARNING: You are about to add one or more soft partition
metadevices to your metadevice configuration.  If there
appears to be an error in the soft partition(s) displayed
above, do NOT proceed with this recovery operation.
Are you sure you want to do this (yes/no)? yes
c3t600508B400011C370000C00002970000d0s2: Soft Partitions recovered
from device.
root@ultra#