问题
有一个场景是我们有两台服务器,硬盘按相同标准格式化成LVM,其中一台服务器坏了修不了,把硬盘插到另一台服务器发现vg重名了导致识别不了。
通过vgdisplay看到报错如下。
WARNING: Duplicate VG name ustack_pv: Existing Q4qvP9-SpLc-Xm0p-Dxaq-zRHY-vwau-h8R1cY (created here) takes precedence over MocWLk-YfKd-3mFG-iU8Z-rFbj-QSR3-qoGXda
WARNING: Duplicate VG name ustack_pv: Existing Q4qvP9-SpLc-Xm0p-Dxaq-zRHY-vwau-h8R1cY (created here) takes precedence over MocWLk-YfKd-3mFG-iU8Z-rFbj-QSR3-qoGXda
WARNING: Duplicate VG name ustack_pv: Q4qvP9-SpLc-Xm0p-Dxaq-zRHY-vwau-h8R1cY (created here) takes precedence over MocWLk-YfKd-3mFG-iU8Z-rFbj-QSR3-qoGXda
--- Volume group ---
VG Name ustack_pv
System ID
Format lvm2
Metadata Areas1
Metadata Sequence No4
VG Access read/write
VG Status resizable
MAX LV0
Cur LV3
Open LV0
Max PV0
Cur PV1
Act PV1
VG Size472.03GiB
PE Size32.00MiB
Total PE15105
Alloc PE / Size15105/472.03GiB
Free PE / Size0/0
VG UUID MocWLk-YfKd-3mFG-iU8Z-rFbj-QSR3-qoGXda
WARNING: Duplicate VG name ustack_pv: Q4qvP9-SpLc-Xm0p-Dxaq-zRHY-vwau-h8R1cY (created here) takes precedence over MocWLk-YfKd-3mFG-iU8Z-rFbj-QSR3-qoGXda
--- Volume group ---
VG Name ustack_pv
System ID
Format lvm2
Metadata Areas1
Metadata Sequence No4
VG Access read/write
VG Status resizable
MAX LV0
Cur LV3
Open LV3
Max PV0
Cur PV1
Act PV1
VG Size472.03GiB
PE Size32.00MiB
Total PE15105
Alloc PE / Size15105/472.03GiB
Free PE / Size0/0
VG UUID Q4qvP9-SpLc-Xm0p-Dxaq-zRHY-vwau-h8R1cY
解决方案
LVM提供命令可以rename这个vg,改名后就可以识别里面的lv,重新挂在到新的服务器上了。
vgrename zOuHvA-QTBR-wNPs-3GIQ-b2zQ-yOeH-2fBS87 newvg
rename后所有lv都是not available状态,需要重置下vg状态才可以用。
lvchange -a y newvg
注意事项
运维组提醒,分区表写死了lv的路径,所以如果想把rename后的vg重新作为启动盘需要提前把名字改回去,或者改分区表。