All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-lvm] Steps to "clone" a volume group
@ 2007-11-22 15:18 Bryn M. Reeves
  2007-11-22 16:05 ` Alasdair G Kergon
  0 siblings, 1 reply; 6+ messages in thread
From: Bryn M. Reeves @ 2007-11-22 15:18 UTC (permalink / raw)
  To: LVM general discussion and development

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Folks,

This question seems to come up from time to time and although it's
easily possible with the current tools the steps aren't obvious to everyone.

There are a number of reasons why people want to do this; accessing
SAN-based snapshots of LVM PVs, working with system images from
virtualised hosts etc.

I wrote some notes on how to do this using pvchange/vgchange/vgrename
which you'll find below. I'll add this to the wiki but if there are any
suggestions/corrections let me know & I'll include those before I set up
the page.

Regards,
Bryn.


Cloning LVM2 Volume Groups
==========================

These instructions describe the steps required to clone an LVM2 volume
group by creating a duplicate copy of the physical storage (PVs). This
requires the VG be deactivated while the clone is created and
re-named.

Linux loopback devices (/dev/loopN) are used in this example and
provide a convenient method for testing. The volume group being
cloned, t0 consists of two PVs originally present on /dev/loop0 and
/dev/loop1. A new volume group named t0-clone will be created on
devices /dev/loop2 and /dev/loop3.

1. Deactivate the VG

       # vgchange -an t0

2. Create the cloned PV(s)

       E.g., dd, clone LUNs on storage, break mirror etc.

       # dd if=/dev/loop0 of=/dev/loop2
       # dd if=/dev/loop1 of=/dev/loop3

3. For each original PV, create a filter entry in /etc/lvm/lvm.conf to
temporarily mask the PV from the LVM tools.

Preserve a copy of the original filtering rules so that it can be
restored at the end of the process, for example:

       # cp /etc/lvm/lvm.conf /etc/lvm/lvm.conf.orig

To exclude the original loopback devices /dev/loop0 and /dev/loop1, the
filter line could look like this:

       filter = [ "r|/dev/loop0|", "r|/dev/loop1|", "a|.*|" ]

Or, using a regex to match both devices with a single rule:

       filter = [ "r|/dev/loop[01]|", "a|.*|" ]

Once the filters are set up, remove the LVM persistent cache:

       # rm -f /etc/lvm/.cache [versions before 2.02.23]
OR
       # rm -f /etc/lvm/cache/.cache [version 2.02.23 or later]

Verify that the filtering is correct by running pvscan:

       # pvscan
         PV /dev/loop2   VG t0         lvm2 [60.00 MB / 40.00 MB free]
         PV /dev/loop3   VG t0         lvm2 [60.00 MB / 40.00 MB free]
         Total: 2 [120.00 MB] / in use: 2 [120.00 MB] / in no VG: 0 [0   ]

Only the cloned PVs should be displayed. If the original PVs appear,
check the syntax of the filtering rule and clear the persistent cache
again.

4. Modify the cloned volume group name, ID and physical volume IDs to
avoid name and UUID clashes between the original and cloned devices:

For each cloned physical volume, run:

       # pvchange --uuid /path/to/physical/volume

This will generate a new random UUID for the specified physical volume
and update the volume group metadata to reflect the changed identity.

For example:

       # pvchange --uuid /dev/loop2
         Physical volume "/dev/loop2" changed
         1 physical volume changed / 0 physical volumes not changed
       # pvchange --uuid /dev/loop3
         Physical volume "/dev/loop3" changed
         1 physical volume changed / 0 physical volumes not changed

Generate a new UUID for the entire volume group using vgchange:

       # vgchange --uuid t0
         Volume group "t0" successfully changed

Finally, rename the cloned VG:

       # vgrename t0 t0-clone

5. Remove filtering rules & verify both VGs co-exist correctly

Restore the original filtering configuration and wipe the persistent cache:

       # cp /etc/lvm/lvm.conf.orig /etc/lvm/lvm.conf
       cp: overwrite `/etc/lvm/lvm.conf'? y
       # rm -f /etc/lvm/.cache

Run pvscan to verify the new and old VGs are correctly displayed:

       # pvscan
         PV /dev/loop0   VG t0         lvm2 [60.00 MB / 40.00 MB free]
         PV /dev/loop1   VG t0         lvm2 [60.00 MB / 40.00 MB free]

         PV /dev/loop2   VG t0-clone   lvm2 [60.00 MB / 40.00 MB free]
         PV /dev/loop3   VG t0-clone   lvm2 [60.00 MB / 40.00 MB free]
         Total: 4 [240.00 MB] / in use: 4 [240.00 MB] / in no VG: 0 [0  ]

6. Activate volume groups

Both the original and cloned VGs can now be activated simultaneously:

       # vgchange -ay t0
         1 logical volume(s) in volume group "t0" now active

       # vgchange -ay t0-clone
         1 logical volume(s) in volume group "t0-clone" now active

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHRZ3T6YSQoMYUY94RAhnYAKCSiTbv2kf9VzKvuA/d0pHFnuerJwCeMiM4
9z4sfBZlkMDzNhuTd54cqSk=
=gi+p
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [linux-lvm] Editing LVM 2 metadata
@ 2008-11-15  2:37 Michael Jensen
  2008-11-15  2:55 ` Alasdair G Kergon
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Jensen @ 2008-11-15  2:37 UTC (permalink / raw)
  To: linux-lvm

[-- Attachment #1: Type: text/plain, Size: 711 bytes --]

I have a need to edit the metadata on an LVM2 PV.  It is a storage managed snapshot of a LVM VG.

It appears I can alter the metadata contents that are in the first 128KB of the device (/dev/sda) using dd and vi.

However, after I edited the LABELONE area where the binary copy of the PV UUID is stored (200x offset area) and the ASCII version at 12b0x and 16b0x and reboot - vgscan no longer recognizes the VG.

Question - are all the UUID's - VG, LV, PV generated as a self-check hash to ensure they haven't been bit-picked or otherwise compromised by the storage??

I have downloaded the source, but am not sure yet where to find the code that generates the UUID strings.

Thanks,
Mike


      

[-- Attachment #2: Type: text/html, Size: 1049 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <1755237768.33050951226964401629.JavaMail.root@mail2.its.carleton.edu>]

end of thread, other threads:[~2008-11-18  0:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-22 15:18 [linux-lvm] Steps to "clone" a volume group Bryn M. Reeves
2007-11-22 16:05 ` Alasdair G Kergon
2007-11-26 16:58   ` Bryn M. Reeves
  -- strict thread matches above, loose matches on Subject: below --
2008-11-15  2:37 [linux-lvm] Editing LVM 2 metadata Michael Jensen
2008-11-15  2:55 ` Alasdair G Kergon
2008-11-17 22:58   ` [linux-lvm] steps to clone a volume group Michael Jensen
     [not found] <1755237768.33050951226964401629.JavaMail.root@mail2.its.carleton.edu>
2008-11-17 23:27 ` Rich Graves
2008-11-18  0:06   ` Michael Jensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.