November 11, 2013

Recovering PVID in AIX

The situation

We have a volume group “o_vg” over two disks like so:

# lspv |grep -i o_vg
hdisk8          0009c6128fff0fb3                    o_vg            active
hdisk13         0009c6126c133561                    o_vg            active

Imagine hdisk13 lost its PVID for any reason and we want to recover it. For example somebody did a mistake and cleared PVID like so:

# varyoffvg o_vg
# chdev -l hdisk13 -a pv=clear
hdisk13 changed

So now we have

# lspv
...
hdisk8          0009c6128fff0fb3                    o_vg
hdisk13         none                                None

Let’s restore lost PVID

# lqueryvg -Atp /dev/hdisk13
...
Physical:       0009c6126c133561                2   0
                0009c6128fff0fb3                1   0
...

Ok we found it “0009c6126c133561”, now we want to convert it to Octal 0009c6126c133561 in octal is = \0000\0011\0306\0022\0154\0023\0065\0141

Writing our “lost” PVID back to our hdisk13

With the file:

# echo "\0000\0011\0306\0022\0154\0023\0065\0141\c" > /tmp/oldpvid
# od -x /tmp/oldpvid
0000000  0009 c612 6c13 3561
0000010

# cat /tmp/oldpvid | dd of=/dev/hdisk13 bs=1 seek=128
8+0 records in
8+0 records out

# lquerypv -h /dev/hdisk13 80 10
00000080   0009C612 6C133561 00000000 00000000  |....l.5a........|

# chdev -P -a pv=yes -l hdisk13
hdisk13 changed

# varyonvg o_vg

That’s all.

For writing we were seeking (seek) for a Block Number ( 128 block ). For reading PVID, you need to skip 128 blocks.

# dd if=/dev/hdisk13 bs=1 skip=128 count=8 > /tmp/diskpvid
8+0 records in
8+0 records out
# od -x /tmp/diskpvid
0000000  0009 c612 6c13 3561
0000010
# lspv |grep -w hdisk13
hdisk13         0009c6126c133561                    o_vg            active