Score:0

Linux LVM - create a mirror, break it, take one of the pieces to a different system, use it there

ng flag

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.

HBruijn avatar
in flag
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.
stark avatar
mu flag
Another problem with mirroring vs file copy is that your GUID is no longer GU.
Steve avatar
ng flag
@HBrujin If the file system were umounted during the mirror break it could not be corrupted - could it?
Steve avatar
ng flag
@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.
HBruijn avatar
in flag
When the file system is not mounted no such corruption should happen.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.