1

I need an explanation or a confirmation of how LVM volume can be expanded.

Below here's the storage management that come from a single VM that has 1 physical disk, this one is split into sda1 as a primary partition for Linux boot, sda2, as a primary partition and managed by LVM, sda3 and sda5 are unknown to me. I only see that sda3 is a primary partition too but sda5 is a logical one.

NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   50G  0 disk
├─sda1        8:1    0  976M  0 part /boot
├─sda2        8:2    0 40,5G  0 part
│ ├─vg-swap 254:0    0  3,8G  0 lvm  [SWAP]
│ ├─vg-root 254:1    0 22,9G  0 lvm  /
│ ├─vg-home 254:2    0  4,8G  0 lvm  /home
│ ├─vg-var  254:3    0  5,7G  0 lvm  /var
│ └─vg-tmp  254:4    0  3,3G  0 lvm  /tmp
├─sda3        8:3    0    1K  0 part
└─sda5        8:5    0  3,5G  0 part

Now what if i want to extend my VG, for example , add +5GB to /var or /home. I read a lot of articles whom i sum up two ways to add storage :

  1. people add a new disk to the VM configuration , create a new primary partition and then add it to the VG - logical volume is extended but now the VM got 2 disks

  2. people expend disk from the VM configuration, then create a new primary partition and then add it to the VG

These methods seems to work once isn't it ? i mean if i add +5 GB to my VM then create a primary partition, and i want to do the same tomorrow, i may be blocked due to primary partitions limits from sda1-sda4 ?

How can i properly extend one of my logical volume many times ?

EDIT

Here's a graphical view of current partitioningenter image description here

1 Answer 1

2

First of all, sda3 is not a primary partition, but an extended partition so you can keep adding new logical partitions every time you resize your disk (after resizing the extended partition).

You don't need a new partition, you can resize your LVM PV partition after resizing the disk. The problem is that, you'll need to move the sda3 extended partition (and the sda5 logical partition in it) to the end of the disk first to make a free space directly after sda. This isn't that easy, so people usually choose adding a new PV to the volume group instead. But if you can use for example GParted which can move the partition for you (CLI tools like fdisk can't do that), you can then resize the sda2 partition, resize the PV format on it with pvresize /dev/sda2 and then resize your LVs with the usual lvresize.

But the resize "option" is only complicated because sda2 isn't at the end of your disk -- if you add a new partition, it will be at the end so any subsequent disk resizes will be simpler -- next time, you'll just resize the new partition (which is now at the end of the disk) with fdisk or parted, then resize the LVM PV format with pvresize. No need for moving this time and also no need for another new partition.

4
  • It seems not so easy actually. I assume sda3 got the "free" space so it means i can "delete/recreate" it from fdisk cli but i'm not 100% sure to get things right..i'll have a look with gparted live before testing with cli.
    – motorbass
    Mar 21, 2023 at 8:50
  • I said that moving the the partition isn't easy. If you want to go that way, you need to move both sda3 and sda5 to the end of the disk. fdisk can't do that. Mar 21, 2023 at 9:01
  • Yes, i was reading many times to be sure to understand. I already did that without LVM on another case and it wasn't tricky to extend, but now, with LVM enabled it's becoming tricky ;) in an other hand, if i go to the other solution (create a pv for every increase i need) it means that the partition list sdX will be incremented too..
    – motorbass
    Mar 21, 2023 at 9:05
  • I tried something (this is a test VM by the way) from gparted gui, i removed sda3 then extend sda2, reboot and PV got updated. even if it seems to work, i'm not sure if it's best practices. Now it only remains sda1 and sda2 (extended so)
    – motorbass
    Mar 21, 2023 at 9:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .