Chinaunix首页 | 论坛 | 博客
  • 博客访问: 302968
  • 博文数量: 118
  • 博客积分: 313
  • 博客等级: 二等列兵
  • 技术积分: 615
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-12 22:51
文章分类

全部博文(118)

文章存档

2012年(68)

2011年(50)

分类:

2012-01-17 21:59:04

原文地址:解析PVID及案例分析 作者:liyf0371

pvid是aix系统中ODM,LVM用于识别PV的序列号,操作系统通过pvid来识别pv。当pv被添加到系统中之后,可以通过两种方式生成pvid
1,cfgmgr -v
2,lspv 如果没有PVID的话,执行chdev -l hdiskn -a pv=yes
也就是说当系统可以识别硬盘并将硬盘认可为pv(即lvm的组件)的时候。系统就分配了pvid给硬盘,系统的odm库中保存有pvid。pvid的生成原则是:主板序列号+形成pv时候的时间戳,pvid除了写入odm库,在硬盘头信息里(0扇区的头几个字节)以及VGDA 也将写入pvid,也就是说pvid存在三个地方。

To make a disk into a physical volume, the PVID is placed onto the disk. ThePVID is an combination of the machine's serial number (from the systems EPROMs) and the date the PVID was generated. This combination ensures the extremely low chance of PVIDs being duplicated. When the system is booted, the disk configurator looks at the PVID residing on the disk and compares it with an entry in the ODM. If an entry is found, then the disk is given the hdiskx number in the ODM that is associated with the PVID. If there is no matching entry, then the next name in the pool of 'free' hdisk names is allocated to the physical volume.

可以通过 lquerypv -H hdisk5查看pv上的pvid

[test1:/pvidtest]#lquerypv -H hdisk5
[test1:/pvidtest]#lquerypv -H /dev/hdisk5
00c2c8723c5beb130000000000000000
[test1:/pvidtest]#lspv
hdisk0          00c2c8724fe40e12                    rootvg          active
hdisk1          00c2c872071205fd                    test1vg         active
hdisk2          00c2c872604e4d20                    test2vg         
hdisk3          00c2c8723c33abbf                    None            
hdisk4          00c2c872605457f4                    None            
hdisk5          00c2c8723c5beb13                    sjhvg           active
hdisk6          00c2c8726f46381a                    heartvg  

可以看到三个pv的pvid前几位数字是相同的(即主板序列号),后几位数字是不同的。
可以通过以下方法修改pvid
chdev -l hdisk1 -a pv=clear 清除pv 磁盘头的pvid
chdev -l hdisk1 -a pv=yes 重新定义pvid,如果pvid存在,使用这个命令也没风险。

如果pv已经加入卷组,首先还得先varyoffvg ,exportvg
执行以上步骤,pv的pvid将会改变。这里修改的只是磁盘头的pvid,并没有修改vgda中的pvid。

当pv已经是一个卷组的成员时,切记不要随便修改pvid,当然如果vg是varyon的,你也是修改不了的。
[test1:/]#chdev -l hdisk5 -a pv=clear
Method error (/etc/methods/chgfcparray):
        0514-062 Cannot perform the requested function because the
                 specified device is busy.

因为当pv加入一个卷组的时候,pvid将被写入vgda,如果你擅自修改卷组的pvid,然后新生成的pvid将不能和卷组vgda中的pvid相匹配,这样就无法importvg,就无法varyonvg,很有可能就会丢失数据!当importvg的时候,odm将读取pv上的vgda,如果vgda上pvid与自身磁盘上的pvid不符合的话,将出现错误!

注意:当pv加入卷组以后,pvid在硬盘上存在于至少两个地方,一个是在硬盘头,一个是在vgda中。这两个地方的pvid一般是相同的,但是由于pvid的修改,可能造成不一致,这样就有可能丢失数据。



案例分析:刻意修改pvid造成数据丢失。

[test1:/]#lspv
hdisk0          00c2c8724fe40e12                    rootvg          active
hdisk1          00c2c872071205fd                    test1vg         active
hdisk2          00c2c872604e4d20                    test2vg         
hdisk3          00c2c8723c33abbf                    None            
hdisk4          00c2c872605457f4                    None            
hdisk5          00c2c872605458d0                    None            
hdisk6          00c2c8726f46381a                    heartvg      

[test1:/]#smit mkvg
[test1:/]#lspv
hdisk0          00c2c8724fe40e12                    rootvg          active
hdisk1          00c2c872071205fd                    test1vg         active
hdisk2          00c2c872604e4d20                    test2vg         
hdisk3          00c2c8723c33abbf                    None            
hdisk4          00c2c872605457f4                    None            
hdisk5          00c2c872605458d0                    sjhvg           active
hdisk6          00c2c8726f46381a                    heartvg

--用hdisk5创建了sjhvg,同时建立了pvidtest文件系统。

[test1:/]#mount /pvidtest
[test1:/]#df -g
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          10.00      4.57   55%    30883     3% /
/dev/hd2           4.00      1.19   71%    44828    14% /usr
/dev/hd9var        4.00      2.94   27%     2253     1% /var
/dev/hd3           5.00      3.90   22%     5301     1% /tmp
/dev/hd1           0.25      0.25    1%       94     1% /home
/proc                 -         -    -         -     -  /proc
/dev/hd10opt       0.50      0.16   68%     4986    12% /opt
/dev/lv00          0.25      0.24    4%       18     1% /var/adm/csd
/dev/lv03          9.56      9.56    1%        4     1% /pdmdatatest
/dev/lv02         19.09      3.52   82%   108534    12% /ptc
/dev/sjhlv00      10.94      4.96   55%      482     1% /sjh1
/dev/sjhlv         0.08      0.08    1%        4     1% /pvidtest


[test1:/ptc/apache]#cp -p config.xml webAppConfig.xml /pvidtest
[test1:/ptc/apache]#cd /pvidtest
[test1:/pvidtest]#ls
config.xml        lost+found        webAppConfig.xml

--忘文件系统里写几个测试数据。

[test1:/]#exportvg sjhvg
[test1:/]#importvg -y sjhvg hdisk5
sjhvg

--export/import vg都是没问题的。

[test1:/]#chdev -l hdisk5 -a pv=clear
Method error (/etc/methods/chgfcparray):
        0514-062 Cannot perform the requested function because the
                 specified device is busy.

--vg没有varyoff是改变不了pvid的。

[test1:/]#chdev -l hdisk5 -a pv=clear
hdisk5 changed
[test1:/]#lspv
hdisk0          00c2c8724fe40e12                    rootvg          active
hdisk1          00c2c872071205fd                    test1vg         active
hdisk2          00c2c872604e4d20                    test2vg         
hdisk3          00c2c8723c33abbf                    None            
hdisk4          00c2c872605457f4                    None            
hdisk5          none                                None            
hdisk6          00c2c8726f46381a                    heartvg   
      
[test1:/]#chdev -l hdisk5 -a pv=yes
hdisk5 changed
[test1:/]#lspv
hdisk0          00c2c8724fe40e12                    rootvg          active
hdisk1          00c2c872071205fd                    test1vg         active
hdisk2          00c2c872604e4d20                    test2vg         
hdisk3          00c2c8723c33abbf                    None            
hdisk4          00c2c872605457f4                    None            
hdisk5          00c2c8723c469fbe                    None            
hdisk6          00c2c8726f46381a                    heartvg   

--注意看pvid已经改变了。vg也消失了。

[test1:/]#varyonvg sjhvg
0516-008 varyonvg: LVM system call returned an unknown
        error code (3).
[test1:/]#varyonvg -b sjhvg
0516-008 varyonvg: LVM system call returned an unknown
        error code (3).
[test1:/]#varyonvg -f sjhvg
0516-008 varyonvg: LVM system call returned an unknown
        error code (3).

--vg已无法varyon。

[test1:/]#lqueryvg -Atp hdisk5
0516-320 lqueryvg: Physical volume hdisk5 is not assigned to
        a volume group.
Max LVs:        256
PP Size:        23
Free PPs:       628
LV count:       2
PV count:       1
Total VGDAs:    2
Conc Allowed:   0
MAX PPs per PV  1016
MAX PVs:        32
Conc Autovaryo  0
Varied on Conc  0
Logical:        00c2c87200004c00000001203c374e76.1   sjhlv 1  
                00c2c87200004c00000001203c374e76.2   loglv02 1  
Physical:       00c2c872605458d0                2   0  
Total PPs:      639
LTG size:       128
HOT SPARE:      0
AUTO SYNC:      0
VG PERMISSION:  0
SNAPSHOT VG:    0
IS_PRIMARY VG:  0
PSNFSTPP:       4352
VARYON MODE:    0
VG Type:        0
Max PPs:        32512

--获取hdisk5 vgda的信息。

以下开始修复:

1.[test1:/]#exportvg sjhvg

2.创建逻辑卷名对应表文件。第一字段为VGDA区中的逻辑卷的名,第二字段为在新卷组中新的逻辑卷名,可相同也可不同;为了修复原有卷组的内容,通常逻辑卷名保持不变。
[test1:/tmp]#cat pvidfixlv
sjhlv:sjhlv
loglv02:loglv02

3.在硬盘上重新创建卷组,保留原有卷组的数据结构。
[test1:/tmp]#recreatevg -y sjhvg -l /tmp/pvidfixlv hdisk5
sjhvg
[test1:/tmp]#lsvg -o
sjhvg
test1vg
rootvg

4.修改/etc/filesystems
/fs/pvidtest:
        dev             = /dev/sjhlv
        vfs             = jfs2
        log             = /dev/loglv02
        mount           = false
        check           = false
        options         = rw
        account         = false

--recreatevg 后,系统自动创建了目录/fs,所有的文件系统加载到了/fs下,原来的mountpoint是以/为基准的。

[test1:/tmp]#lsvg -l sjhvg
sjhvg:
LV NAME             TYPE       LPs   PPs   PVs  LV STATE      MOUNT POINT
sjhlv               jfs2       10    10    1    closed/syncd  /fs/pvidtest
loglv02             jfs2log    1     1     1    closed/syncd  N/A

/pvidtest:
        dev             = /dev/sjhlv
        vfs             = jfs2
        log             = /dev/loglv02
        mount           = false
        check           = false
        options         = rw
        account         = false

--修改/etc/filesystems之后的样子。

[test1:/tmp]#mount /pvidtest
[test1:/tmp]#cd /pvidtest
[test1:/pvidtest]#ls
config.xml        lost+found        webAppConfig.xml
[test1:/pvidtest]#lsvg -l sjhvg
sjhvg:
LV NAME             TYPE       LPs   PPs   PVs  LV STATE      MOUNT POINT
sjhlv               jfs2       10    10    1    open/syncd    /pvidtest
loglv02             jfs2log    1     1     1    open/syncd    N/A

--文件都在,状态也都正常。修复完毕。
阅读(1555) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~