Moving LVM volume group from one physical disk onto another

I'm an out-of-my-depth PHP developer who has to deal with the following sysadmin problem.

We have an Ubuntu (Ubuntu 14.04.1 LTS) server running Xen (xen-hypervisor-4.4-amd64 4.4.0-0ubuntu5.1).

It has two physical disks (250GB and 2TB), each containing an LVM filesystem (/dev/sdb is the old 250GB, /dev/sda is the new 2TB).

root@xen:~# pvscan
  PV /dev/sdb3   VG tiffany-vg   lvm2 [232.17 GiB / 85.48 GiB free]
  PV /dev/sda5   VG xen-vg       lvm2 [1.82 TiB / 1.77 TiB free]
  Total: 2 [2.05 TiB] / in use: 2 [2.05 TiB] / in no VG: 0 [0   ]

I need to move the group "tiffany-vg" to the new/larger disk (/dev/sda), with the aim of removing the older 250GB physical disk from the server. The target disk already contains another LVM group called "xen-vg" which must remain separate.

I want to move "tiffany-vg" to sit next to "xen-vg" on /dev/sda and I really need to not lose any data! I really don't want to cause any data loss?

I have probably used some terminology wrong and I am sure you understand what I am trying to say.

UPDATE:

The "target" disk (/dev/sda) currently looks like this ...

root@xen:~# parted /dev/sda
#...snip
Number  Start   End     Size    Type      File system  Flags
 1      1049kB  256MB   255MB   primary   ext2         boot
 2      257MB   2000GB  2000GB  extended
 5      257MB   2000GB  2000GB  logical                lvm

Solution 1:

A volume group can have multiple physical disks (or in your case, partitions).

First you need to have space on your larger disk (/dev/sda).

You did not mention that in your post, but based on your question, I would assume that you can make space and then add a new partition that we shall call: /dev/sdaX

EXTENSION AFTER UPDATE:

You can make space on your /dev/sda with simply merging the volume groups, but you don't want to do that - as you stated in your original post. What you need to do is actually more simple than that.

Follow these steps:

Step -5: reduce your physical volume on /dev/sda5 to make space for a new partition:

pvresize /dev/sda5 -L 1500G

Step -4: Use parted to reduce the size of /dev/sda5 to 1600G (yes, a little bit bigger than we used in pvresize!)

Step -3: Use parted to create a new partition, /dev/sda6, with the new available space (it will be around 400G).

Step -2: Check if the kernel could automatically detect the partition change. See if /proc/partition matches the new state (thus, /dev/sda6 is visible). If not, you need to reboot. (Probably it will.)

Step -1: You can make /dev/sda5 to be as big as it can again:

 pvresize /dev/sda5

Step 0: Format /dev/sda6 to a physical volume:

pvcreate /dev/sda6

From this point, /dev/sda6 is our /dev/sdaX.

EXTENSION END

First: you should give /dev/sdaX to the volume group tiffany-vg:

vgextend tiffany-vg /dev/sdaX

Second: you should move all of your data between the (already) two physical volumes of the volume group tiffany-vg:

pvmove tiffany-vg /dev/sdb3 /dev/sdaX

Third: you should remove /dev/sdb3 from the tiffany-vg volume group:

vgreduce tiffany-vg /dev/sdb3

NOTE: The second step above will be a little bit critical, be curious. If it is a root partition, better to do that from a rescue disc. Good luck!

IF YOU SIMPLY MERGED THE VOLUME GROUPS

Step 1: You can simply merge the xen-vg into your tiffany-vg:

vgmerge tiffany-vg xen-vg

Step 2: Move all of your data from /dev/sdb3 to /dev/sda5:

pvmove tiffany-vg /dev/sdb3 /dev/sda5

Step 3: Remove /dev/sdb3 from your new, big volume group:

vgreduce tiffany-vg /dev/sdb3

But beware: here your old, xen-vg volume group ended his life, and all of its volumes are moved below /dev/tiffany-vg. You need to change every reference to them in the system configs ( it is unlikely you needed to change anything out of /etc/fstab).

END