LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Extending LVM Volume with more than 4 partitions? (https://www.linuxquestions.org/questions/linux-newbie-8/extending-lvm-volume-with-more-than-4-partitions-4175435977/)

willkruss 11-06-2012 07:03 PM

Extending LVM Volume with more than 4 partitions?
 
Hi,
I have an LVM partition on a CentOS 6 VPS and currently have extended it a few times and need to extend it further.

fdisk -l:

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004a08c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 14 103424 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 14 1306 10380288 8e Linux LVM
/dev/sda3 1306 2610 10480089 8e Linux LVM
/dev/sda4 2611 5221 20972857+ 8e Linux LVM

Disk /dev/mapper/VolGroup00-LogVol00: 42.8 GB, 42832232448 bytes
255 heads, 63 sectors/track, 5207 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

If I try to create a new partition I'm told that I have to delete one to do that. Unfortunately this isn't possible as the data is live. I'm really at a loss here :-(

Cheers,
- Will

Ser Olmy 11-06-2012 07:25 PM

This is not related to LVM. You've hit the 4 partition limit of the MBR partition table.

The MBR only has room for four entries, limiting you to a maximum of four primary partitions. A workaround exists; one of the four primary partitions can be a so-called extended partision, which in turn can contain a number of sub-partitions ("logical" partitions).

Unfortunately, you've already created four primary partitions. You will need to convert the last of these to an extended partition containing a logical partition. This typically involves backing up data and deleting and recreating the partition in question, although various utilities exist which claim to be able to do a non-destructive conversion.

In either case, your existing /dev/sda4 partition will become /dev/sda5, so you'll need to reconfigure LVM.

willkruss 11-06-2012 07:43 PM

Hi,

Okay, but as I'm using an LVM and the whole thing is actually one big partition, I can't just 'backup' sda4 and recreate it as an extended partition.

Any suggestions on how to go about this with minimal disruption (it's a live cPanel server)?

Thanks.

willkruss 11-06-2012 07:45 PM

Is it possible to merge sda3 and sda4? The blocks are sequential.

Thanks.

Ser Olmy 11-06-2012 08:00 PM

These partitions are PVs in an LVM Volume Group, right? No, there's no way to simply merge the partitions. Each partition contains LVM metadata that identifies it as an LVM Physical Volume.

However, it is possible to add a temporary drive (say, an external USB drive) to the VG, use pvmove to migrate all data from /dev/sda4, and then remove /dev/sda4 from the VG with vgreduce.

You could then create an extended partition (/dev/sda4, which should take up all available disk space) and any number of logical partitions (/dev/sda5++), which you could then add back to the VG before using pvmove/vgreduce again to get rid of the temporary drive.

willkruss 11-06-2012 08:04 PM

Actually, if that's not possible, if I add another physical HDD to the OS. Can I then create it as a new partition (I assume /dev/sdb1) and add that to the LVM without losing anything? If so, can someone please tell me the commands to do this?

Thanks,
- Will

Ser Olmy 11-06-2012 08:22 PM

Quote:

Originally Posted by willkruss (Post 4823789)
Actually, if that's not possible, if I add another physical HDD to the OS. Can I then create it as a new partition (I assume /dev/sdb1) and add that to the LVM without losing anything?

Sure you can. Create a partition with fdisk (or whatever), run pvcreate on the partition, add it to the volume group with vgextend and extend any logical volume in the volume group with lvextend.

(Or use the new partition as temporary storage to migrate data from /dev/sda4, as I suggested in my previous post, which would allow you to repartition /dev/sda without losing data.)

willkruss 11-06-2012 08:30 PM

Thanks Ser, I'll give it a go this evening!

syg00 11-07-2012 02:31 AM

So you'll wind up wasting half that (original) disk - no big deal I suppose these days. Allocating multiple pv's like that is limiting in a LVM setup.
In future you would be better off to have one large pv (maybe even the entire disk in the case of the new disk), and use vg's to carve it up if you wish; that way you can expand at will, and not waste disk real estate.

willkruss 11-07-2012 02:55 AM

Ahh it's a thin provisioned VPS so no actual disk space is lost anyhow :-)


All times are GMT -5. The time now is 07:44 PM.