0

Using LVM, I would like to create a mirror of a LV, sync it, break it off, attach the mirror-piece to a different system, use it there.

Start with a ordinary linear LV. Here is the procedure I have:

#### create a mirror
##   variables
OLDPV=/dev/sdf
NEWPV=/dev/sdj
VG=somevg
OLDLV=data
NEWLV=mirr

## add storage to machine, put it under LVM control, add to $VG
pvcreate -vy $NEWPV
vgextend -vy $VG $NEWPV 

## create a mirror
lvcreate -vy --type raid1 -m1 -L $SIZE -n $OLDLV $VG

## previous lvcreate should select the empty PV we just added

## use "lvs -v" to monitor progress of mirror synchronization (Cpy%Sync)
lvs -v

## Once the sync is 100# -- split the mirror
## Question: do I need to umount LV?
lvconvert -vy --splitmirrors 1 --name $NEWLV $VG/$OLDLV $NEWPV
## convert source vol back to 'linear'
lvconvert -vy --type linear -n $OLDLV $VG

## pull $NEWPV out of $VG (put it in 'temp' - assumes no temp already exists)
vgsplit -vy $VG temp $NEWPV
## disassociate temp VG
vgchange -vy --activate n temp

## safely remove $NEWPV from instance
vgremove -vy temp

## attach mirrored LV to a separate machine
vgscan
vgmerge -yv temp $LOCALVG

Is this the correct set of steps to safely clone a disk/LV and reuse it elsewhere? Is there additional LVM clean up that should happen on the original host system?

Thanks in advance.

Steve
  • 1
  • Creating a mirror and then breaking it (with LVM or hard- or software RAID) is usually not the right method IMHO. Typically with such an approach you will end up with a with corrupt file-systems and (some) data inconsistencies. Second with that approach you're usually copying the full raw storage capacity, where other approaches only copy the actual data, which is what I actually care about and which can be much, much quicker. - I prefer creating a LVM snapshot (after flushing all pending writes) and then use something like rsync to copy all data from that snapshot to your second disc. – HBruijn May 23 '23 at 08:04
  • Another problem with mirroring vs file copy is that your GUID is no longer GU. – stark May 23 '23 at 11:52
  • @HBrujin If the file system were umounted during the mirror break it could not be corrupted - could it? – Steve May 23 '23 at 15:00
  • @stark The "copy" file system & LV & associated PV are going to be pulled off the system; does it's GUID matter at that point? P.S. - thanks for the replies, it really helps. – Steve May 23 '23 at 15:03
  • When the file system is not mounted no such corruption should happen. – HBruijn May 30 '23 at 12:20

0 Answers0