5

I have server with 2TB disk, that someone initially partitioned like this:

  • 300GB standard primary partition for operating system files(CentOS 7).
  • 1.7TB LVM with some pretty big logical volumes - for other needs.

Since actual size of of operating system files turned out to be just around 400GB, later it's been moved to it's own logical volume on LVM, so this 300GB partition at beginning of disk become unused.

So, I removed this partition, and now want somehow to move start position of PV to beginning of disk, so it will utilize whole disk space. But i can't find any tools to do so - pvextend can only extend PV to end of disk, not to beginning.

Yes I know that I can just add that old partition to VG as another PV, but having multiple PV's on single disk look's like something pretty weird.

Also I know that I can copy partitions to some external device or cloud storage, and then just recreate physical disk partitioning from scratch. But I don't want this because of long server downtime.

So, is there any way to just quickly extend PV to beginning of disk?

10

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.

  • 1
    If you can't move the pv for some reason, you can also just create a second pv in the free space. You have to be careful when defining stripes then, because a stripe with two pv on the same disk would decrease performance. – Josef Jan 25 '16 at 9:57

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.