Operating System - HP-UX
1822355 Members
5288 Online
109642 Solutions
New Discussion юеВ

Possible to move LV's from 1 VG to Another

 
SOLVED
Go to solution
Alzhy
Honored Contributor

Possible to move LV's from 1 VG to Another

Is it possible to move logical volumes with filesystems on it from 1 Volume Group to another without destroying data on it? With Veritas VM, I can move volumes and their filesystems from one diskgroup to another with data preserved.
Hakuna Matata.
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: Possible to move LV's from 1 VG to Another

With LVM, the only way to do that is to create another LV in the VG you want to move to, then move your data, umount both LVs, modify /etc/fstab to reflect the new VG and remount the LV.

There is no way to just move an LV between VGs without going through a lot of other steps, like above.
James R. Ferguson
Acclaimed Contributor

Re: Possible to move LV's from 1 VG to Another

Hi:

No, it is not possible under LVM to move a logical volume and its associated filesystem from one volume group to another.

You will need to create a new logical volume (optionally in a new volume group) and copy the data from the old to the new filesystem. This can be done easily with 'cpio' or with 'fbackup'/'frecover'.

# cd /olddir || exit 1
# find . -depth ???print | cpio -pudlmv /newdir

...or:

# cd /olddir
# fbackup -i . -f - | (cd /newdir; frecover -Xsrf -)

When the copy has been completed, you can edit '/etc/fstab' to reflect the '/newdir' mountpoint's device with the '/olddir' name.

Regards!

...JRF...
Alzhy
Honored Contributor

Re: Possible to move LV's from 1 VG to Another

Yes but is it POSSIBLE to move a PV (or PV's) that are components of an LV with a filesystem (data) on it from 1 VG to another WITHOUT destorying data? Are there any undocumented procedures that anyone is aware - ie. since we know the extents on the disk (or disks) where our LV resides - isn't there a way to lvextend a new LV (on the target VG) to house the extents from the PV (or PV's)? With VRTS VM, this is possible because a deport or deletionof a PV (or disk) does not constitute destruction of its "slices" so that it is still possible to "recreate" what use to be the volumes (or LV's in LVM) on the target diskgroup (or VG in LVM).
Hakuna Matata.
Patrick Wallek
Honored Contributor

Re: Possible to move LV's from 1 VG to Another

NO, you can NOT move a PV that is part of one VG to another VG with LVM.

James Murtagh
Honored Contributor

Re: Possible to move LV's from 1 VG to Another

Hi Nelson,

Although I don't have time to check this I would say it is possible but only if the filesystem (lv) is completely contained within the disks you are moving. If you have an extent map you can lvcreate the logical volume within the new volume group and fsck the filesystem.

For instance on one call I was working on someone had removed all the logical volumes and removed the disk from the volume group. They wanted to know if this data on this disk could be accessed by a third party if the disk went off-site. All I had was a bdf and I rebuilt it all (after much cursing as they had extended LVs all over the place!)

Still, not conventional or supported and I wouldn't advise doing it this way.

Regards,

James.
James Murtagh
Honored Contributor
Solution

Re: Possible to move LV's from 1 VG to Another

Hi Nelson, (again)

Had a bit of time, here is the output of the commands I used to do this, hope it pastes ok!

# mkdir /dev/vg01
# mknod /dev/vg01/group c 64 0x010000
# vgcreate /dev/vg01 /dev/dsk/c1t4d0
Increased the number of physical extents per physical volume to 1023.
Volume group "/dev/vg01" has been successfully created.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf
# lvcreate -l 5 vg01
Logical volume "/dev/vg01/lvol1" has been successfully created with
character device "/dev/vg01/rlvol1".
Logical volume "/dev/vg01/lvol1" has been successfully extended.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf
# newfs -F vxfs /dev/vg01/rlvol1
version 4 layout
20480 sectors, 20480 blocks of size 1024, log size 1024 blocks
unlimited inodes, largefiles not supported
20480 data blocks, 19384 free data blocks
1 allocation units of 32768 blocks, 32768 data blocks
last allocation unit has 20480 data blocks
# mkdir /itrc
# mount /dev/vg01/lvol1 /itrc
# touch /itrc/james
# umount /itrc
# lvremove /dev/vg01/lvol1
The logical volume "/dev/vg01/lvol1" is not empty;
do you really want to delete the logical volume (y/n) : y
Logical volume "/dev/vg01/lvol1" has been successfully removed.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf
# vgremove vg01
Volume group "vg01" has been successfully removed.
# vgextend vg00 /dev/dsk/c1t4d0
Volume group "vg00" has been successfully extended.
Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf
# lvcreate -l 5 vg00
Logical volume "/dev/vg00/lvol11" has been successfully created with
character device "/dev/vg00/rlvol11".
Logical volume "/dev/vg00/lvol11" has been successfully extended.
Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf
# fsck -F vxfs /dev/vg00/rlvol11
file system is clean - log replay is not required
# mount /dev/vg00/lvol11 /itrc
# ls /itrc
james lost+found

So there you are, the filesystem and data is still intact. However, note some things here:

1) I didn't have to check any extent maps as I knew the lvol was created in the first five extents of the disk
2) My primary disk was fully populated, hence I didn't have to create a physical volume group to ensure that disk was used (defined in /etc/lvmpvg).

Regards,

James
monasingh_1
Trusted Contributor

Re: Possible to move LV's from 1 VG to Another

I agree with james that if you are absolutely possible with the size and extents of lv on a PV you can get the data back. Long back once accidently I had deleted all LVs in a vg and then on someone's advise just re-created same LVs in the SAME ORDER AND SAME SIZE and found the data back...
Also note that the PV you are trying to move between VGs is used for creating new LV on new VG otherwise lvcreate will use some extent from the remaining PVs before using your newly included disk.
do some test/practice before trying it for production PV/LV and take the backup before.
Jakes Louw_1
Frequent Advisor

Re: Possible to move LV's from 1 VG to Another

Yes.

Consider that the source LVOL is :
/dev/vg01/source_lvol
mounted on /my_data_source

Create a new LVOL of the same size using LVCREATE on the "other" VG:

lvcreate -L 1000 (same as source!) -n target_lvol /dev/vg_other

umount /my_data_source

dd if=/dev/vg01/rsource_lvol of=/dev/vg_other/rtarget_lvol bs=1024k
(Note I'm using the Block devices)

When the dd is finished with identical IN and OUT blocks, then mount /my_data_source onto /dev/vg_other/target_lvol .

Note: since you are in effect copying every block between the source and the target, you DO NOT need to do a MKSF/NEWFS on the new raw LVOL.
This method leaves the source untouched.