Xen/Suso's Xen method

From SusoSight

Changing a LVM PV and VG UUID

This assumes that you are using lvm on a disk file called lvmdisk01, not a real disk partition.

Do all this as root:

# losetup /dev/loop2 lvmdisk1
# vgscan
# vgcfgbackup -f TemplateVG.cfg TemplateVG

Now edit TemplateVG.cfg file and change the IDs for the volume group, physical volume and logical volumes too. You can use a program like uuidgen to generate unique ids for you to use. Keep track of what ID you gave the physical volume as you will use it in the pvcreate command below.

Tip: if you use Vim as your editor, a map like this in your root's .vimrc file will be very useful, just type uuid when you are over the id line that you want to change:

map uuid :.!uuidgen<C-M>0i<Tab><Tab><Tab>id = "<Esc>$a"<Esc>
# vgchange -a n TemplateVG

Now run pvcreate using the --uuid option and use the NEW uuid that you generated an changed to in the VG config file.

# pvcreate -ff --uuid CFhjSe-EqSc-pnDz-4UcP-ylxh-hcY6-oV6BGR --restorefile TemplateVG.cfg /dev/loop2

It will complain that it couldn't find the physical volume with the specified uuid, but it will still create the physical volume.

# vgcfgrestore -f TemplateVG.cfg TemplateVG

Now change the name of the volume group to something you will be using.

# vgrename TemplateVG NewvolumenameVG

And if you want, make all the logical volumes active.

# vgchange -a y NewvolumenameVG

That's it, now you can change the volume group name if that's what you need to do. You should try mounting one of the logical volumes now to make sure the data is still in tact.