Moving one or more physical volumes/lvols into a new volume group

Hy,

I had to do a little test, for later use in production, making 2 vgs out of 1, dividing the lvols between them...

Starting point:

1 vg named vgtest
3 lvols names test1,test2,test3
2 PVs

we need to separate the lvols into 2 vgs, we need lvols test1 and test2 in one vg and lvtest3 on another vg:

First we need to have lvtest3 on a single disk, at the momento it has extents on the 2 disks:

--- Logical volumes ---
LV Name /dev/vgtest/lvtest1
LV Status available/syncd
LV Size (Mbytes) 1000
Current LE 125
Allocated PE 125
Used PV 1

LV Name /dev/vgtest/lvtest2
LV Status available/syncd
LV Size (Mbytes) 1000
Current LE 125
Allocated PE 125
Used PV 1

LV Name /dev/vgtest/lvtest3
LV Status available/syncd
LV Size (Mbytes) 1000
Current LE 125
Allocated PE 125
Used PV 2

--- Physical volumes ---
PV Name /dev/dsk/c0t2d0
PV Status available
Total PE 254
Free PE 0
Autoswitch On
Proactive Polling On

PV Name /dev/dsk/c0t3d0
PV Status available
Total PE 255
Free PE 134
Autoswitch On
Proactive Polling On

# lvdisplay -v /dev/vgtest/lvtest3 | more
--- Distribution of logical volume ---
PV Name LE on PV PE on PV
/dev/dsk/c0t2d0 4 4
/dev/dsk/c0t3d0 121 121

We use pvmove to move the 4 extens on t2d0 to t3d0 disk:

# pvmove -n /dev/vgtest/lvtest3 /dev/dsk/c0t2d0 /dev/dsk/c0t3d0
Transferring logical extents of logical volume "/dev/vgtest/lvtest3"...
Physical volume "/dev/dsk/c0t2d0" has been successfully moved.
Volume Group configuration for /dev/vgtest has been saved in /etc/lvmconf/vgtest.conf

# lvdisplay -v /dev/vgtest/lvtest3
--- Distribution of logical volume ---
PV Name LE on PV PE on PV
/dev/dsk/c0t3d0 125 125

Now that we have lvol test3 on one disk we are ready to move it to a new vg named vgnewtest:

first we export a the vg with a map, and create the new devices:

#vgchange -a n /dev/vgtest
Volume group "/dev/vgtest" has been successfully changed.
#
# vgexport -m /tmp/vgtestmap
# ll /dev/*/group
crw-r----- 1 root sys 64 0x000000 Dec 17 16:14 /dev/vg00/group
crw-rw-rw- 1 root sys 64 0x010000 Dec 18 11:08 /dev/vgtest/group
# vgexport -m /tmp/vgtestmap /dev/vgtest
#
# mkdir /dev/vgtest
# mknod /dev/vgtest/group c 64 0x010000
# mkdir /dev/vgnewtest
# mknod /dev/vgnewtest/group c 64 0x020000

Now we change the vgid of the the disk of lvol3:

# vgchgid /dev/rdsk/c0t3d0

We import the 2 vgs:

# vgimport -m /tmp/vgtestmap /dev/vgtest /dev/dsk/c0t2d0
vgimport: Warning: Volume Group contains "2" PVs, "1" specified. Continuing.
Warning: A backup of this volume group may not exist on this machine.
Please remember to take a backup using the vgcfgbackup command after activating the volume group.
# vgimport -m /tmp/vgtestmap /dev/vgnewtest /dev/dsk/c0t3d0
vgimport: Warning: Volume Group contains "2" PVs, "1" specified. Continuing.
vgimport: Quorum not present, or some physical volume(s) are missing.
Warning: A backup of this volume group may not exist on this machine.
Please remember to take a backup using the vgcfgbackup command after activating the volume group.
# strings /etc/lvmtab
/dev/vg00
/dev/dsk/c0t1d0s2
/dev/vgtest
/dev/dsk/c0t2d0
/dev/vgnewtest
/dev/dsk/c0t3d0

Now we have to vgs, we are going to start with vgtest and remove the stale info the vg has about the t3d0 disk and the test3 lvol:

# vgchange -a y -q n /dev/vgtest
Activated volume group
Volume group "/dev/vgtest" has been successfully changed.
# lvremove -f /dev/vgtest/lvtest3
Logical volume "/dev/vgtest/lvtest3" has been successfully removed.
vgcfgbackup: /etc/lvmtab is out of date with the running kernel:Kernel indicates 2 disks for "/dev/vgtest"; /etc/lvmtab has 1 disks.
Cannot proceed with backup.
# vgreduce -f /dev/vgtest
PV with key 1 sucessfully deleted from vg /dev/vgtest
Repair done, please do the following steps.....:
1. save /etc/lvmtab to another file
2. remove /etc/lvmtab
3. use vgscan(1m) -v to re-create /etc/lvmtab
4. NOW use vgcfgbackup(1m) to save the LVM setup

We are done with the first vg:

# vgdisplay -v /dev/vgtest
+ vgdisplay -v /dev/vgtest
--- Volume groups ---
VG Name /dev/vgtest
VG Write Access read/write
VG Status available
Max LV 255
Cur LV 2
Open LV 2
Max PV 24
Cur PV 1
Act PV 1
Max PE per PV 6652
VGDA 2
PE Size (Mbytes) 8
Total PE 254
Alloc PE 250
Free PE 4
Total PVG 0
Total Spare PVs 0
Total Spare PVs in use 0

--- Logical volumes ---
LV Name /dev/vgtest/lvtest1
LV Status available/syncd
LV Size (Mbytes) 1000
Current LE 125
Allocated PE 125
Used PV 1

LV Name /dev/vgtest/lvtest2
LV Status available/syncd
LV Size (Mbytes) 1000
Current LE 125
Allocated PE 125
Used PV 1

--- Physical volumes ---
PV Name /dev/dsk/c0t2d0
PV Status available
Total PE 254
Free PE 4
Autoswitch On
Proactive Polling On

# mount /dev/vgtest/lvtest1 /test1
# mount /dev/vgtest/lvtest2 /test2
# bdf | grep -i test
/dev/vgtest/lvtest1
1024000 16725 944328 2% /test1
/dev/vgtest/lvtest2
1024000 16725 944328 2% /test2

We procede in the same way with the new vg:

# vgchange -a y -q n /dev/vgnewtest
+ vgchange -a y -q n /dev/vgnewtest
Activated volume group
Volume group "/dev/vgnewtest" has been successfully changed.
#
# lvremove -f /dev/vgnewtest/lvtest1
Logical volume "/dev/vgnewtest/lvtest1" has been successfully removed.
vgcfgbackup: /etc/lvmtab is out of date with the running kernel:Kernel indicates 2 disks for "/dev/vgnewtest"; /etc/lvmtab has 1 disks.
Cannot proceed with backup.
# lvremove -f /dev/vgnewtest/lvtest2
Logical volume "/dev/vgnewtest/lvtest2" has been successfully removed.
vgcfgbackup: /etc/lvmtab is out of date with the running kernel:Kernel indicates 2 disks for "/dev/vgnewtest"; /etc/lvmtab has 1 disks.
Cannot proceed with backup.
More arguments required.
# vgreduce -f /dev/vgnewtest
PV with key 0 sucessfully deleted from vg /dev/vgnewtest
Repair done, please do the following steps.....:
1. save /etc/lvmtab to another file
2. remove /etc/lvmtab
3. use vgscan(1m) -v to re-create /etc/lvmtab
4. NOW use vgcfgbackup(1m) to save the LVM setup
#
# vgdisplay -v vgnewtest
+ vgdisplay -v vgnewtest
--- Volume groups ---
VG Name /dev/vgnewtest
VG Write Access read/write
VG Status available
Max LV 255
Cur LV 1
Open LV 1
Max PV 24
Cur PV 1
Act PV 1
Max PE per PV 6652
VGDA 2
PE Size (Mbytes) 8
Total PE 255
Alloc PE 125
Free PE 130
Total PVG 0
Total Spare PVs 0
Total Spare PVs in use 0

--- Logical volumes ---
LV Name /dev/vgnewtest/lvtest3
LV Status available/syncd
LV Size (Mbytes) 1000
Current LE 125
Allocated PE 125
Used PV 1

--- Physical volumes ---
PV Name /dev/dsk/c0t3d0
PV Status available
Total PE 255
Free PE 130
Autoswitch On
Proactive Polling On

# mkdir /test3
# mount /dev/vgnewtest/lvtest3 /test3
#
# bdf | grep test

/dev/vgtest/lvtest1
1024000 16725 944328 2% /test1
/dev/vgtest/lvtest2
1024000 16725 944328 2% /test2
/dev/vgnewtest/lvtest3
1024000 16725 944328 2% /test3
#

We have finished.