How to extend LVM PV to the beginning of disk?
Solution 1:
If your existing PV has < 300GB of data
If your existing PV has less than 300GB of data on it, then you can simply relocate that data to the front of the disk and then use pvresize
. First, create a new pv:
pvcreate /dev/sda1
Relocate data from the existing pv onto the new pv:
pvmove /dev/sda2 /dev/sda1
Remove the old pv:
vgreduce myvg /dev/sda2
Now, use parted
or fdisk
or whatever to resize /dev/sda1
to cover the entire disk, and then use pvresize
to extend the pv to cover the partition.
Using an external device without downtime
You can use pvmove
to relocate your data to a different device without any server downtime. You would create a new pv:
pvcreate /dev/sdb
Add it to your vg:
vgextend myvg /dev/sdb
Relocate data from your existing pv to the new pv:
pvmove /dev/sda2 /dev/sdb
Remove your existing pv from the volume:
pvremove /dev/myvg /dev/sda2
Now, repartition /dev/sda, create a new pv, and reverse the above process.