0

I have 4 LVs, type is ext4. I want to know how to safely extend them since they are all used for production.

From what I know the steps are.

  1. unmount
  2. extend
  3. resize FS
  4. mount again

Are these steps correct or is there something I am missing?

5
  • You've tagged this as 12.04 which is an old and LONG DEAD release of Ubuntu. What version of Ubuntu are you in fact using? Additionally the 'proper' way to extend partitions has a couple of approaches, and you can safely extend logical volumes and filesystems while running (ext4 allows for live resizing and extending filesystems, not shrinking.)
    – Thomas Ward
    Commented Apr 30 at 19:20
  • The simplest way is lvresize -l +100%FREE -r /dev/mapper/blah but you are really missing many details. And if you're really running 12.04, the post should be deleted since this is a long-dead version and since you haven't upgraded to a supported version in many years.
    – doneal24
    Commented Apr 30 at 19:32
  • @doneal24 that's why I asked the OP what OS they use, but the process for filesystem resize is idifferent than extending the LV itself. Refer to my answer where I focus on the LV resize and then its underlying filesystem resize process accordingly (which affect all LVM2 type systems, but also has caveats and prerequisites I specify.)
    – Thomas Ward
    Commented Apr 30 at 19:35
  • @ThomasWard meant to add 22.04 sorry Commented Apr 30 at 20:01
  • @ThomasWard Using the -r flag to lvresize saves one step in your answer. You can automagically resize the file system to match the logical volume size with this. It will not work for shrinking most file systems but will work for expanding logical volumes.
    – doneal24
    Commented Apr 30 at 23:45

1 Answer 1

0

The answer depends on what we're calling a logical volume. Assuming we're talking about LVM style setups, there are three components to an LVM setup:

  1. Physical volumes (PVs) - partitions on drives that're formatted as LVM2 members.

  2. Volume groups (VGs) - groupings of volumes on different PVs.

  3. Logical volumes (LVs) - logical partitions/volumes which are created as part of VGs.


ALWAYS make sure you back up mission critical data before fussing with your system schemas and partitions. Even in LVM environments!


If you are intending to add new PVs to volume groups you can do this relatively safely without any special actions. If you are going to shrink or extend existing PVs, you should do so extremely carefully and probably from an unmounted state.


If you are going to be adding new VGs or adding PVs to VGs, you can do this without much extra effort. If you're removing or shrinking VGs because of changing PVs, then do so from a safer state where you're not running on the VGs / LVs itself.


Specifically with Logical Volumes that're ext4 filesystems, we can relatively easily extend them without issues. And we can do it live without unmounting the filesystem.

There are a few prerequisites we have to make sure though:

  1. The PVs that the LVs and VGs are part of have been properly expanded to accommodate new free space (so the VGs and LVs can extend into the extents).

  2. The VGs reflect the larger 'free space' and it shows as unused when you look at vgs output.

  3. The LV is part of a VG that has the extra space / extents.

If all these prerequisites are met, then you can do a live resize/extend and extend the LV and its corresponding filesystem.

  1. Double check that pvs and vgs reflect the changes in disk and that there are free extents on the VG.

  2. Extend the LV to take up the space you want. In this example, I'm extending the LV to fill all 100% available 'free' extents in the VG (which is quite common when dealing with expanding file storage needs). In this example, the VG in vgs is vg-ubuntu22 and the LV is named root for my root partition. It shows in /dev/mapper/ accordingly as vg--ubuntu22-root.

    sudo lvextend -l +100%FREE -r /dev/mapper/vg--ubuntu22-root

  3. Extend the filesystem. Since this is an ext4 filesystem, we can safely extend the volume without any need to unmount, etc.

    sudo resize2fs /dev/mapper/vg--ubuntu22-root

  4. The system will now reflect the larger filesystem size after doing a live resize. This does NOT work on all filesystems, but works extremely well on ext4, and ONLY works on extending. It is not safe to shrink a filesystem while it's running.

6
  • what i have is One PV, inside there is one VG, Inside the VG there are 4 LVs, all 4 logical volumes are mounted/used in production, In Vcenter i will increase the size of the disk then restart the machine and there will be unallocated space inside the disk, i will run sudo pvresize /dev/sdX so it reflects inside the PV, then i will run sudo vgextend VG_NAME /dev/sdX to allocate the size inside the VG, then i am guessing lvextend -L and resize2fs, from what i understood i would need to unmount the LVs first and then extend the size. is this correct or No need to unmount Commented Apr 30 at 20:24
  • also i applied sudo pvcreate /dev/source_disk directly to /dev/sdb i believe i don't need to run vgextend Commented Apr 30 at 20:30
  • lvresize -l +100%FREE -r /dev/mapper/vg--ubuntu22-root will extend the logical volume to take up the entire free space in the VG and resize the file system to match the LV size. This can be done live. No need to run resize2fs or the equivalent for xfs/zfs/blah.
    – doneal24
    Commented Apr 30 at 23:51
  • @doneal24 adjusted accordingly. I usually avoid -r because I'm old school and don't trust tools to properly chain together for that component ;)
    – Thomas Ward
    Commented May 1 at 0:50
  • @ThomasWard thank you for the answer, but i was wondering if i need to unmount the LV and then extend. is this a safer way or i don't need to unmount at all, just resize and it should work even in production environment where the LV is receiving data? Commented May 1 at 4:39

You must log in to answer this question.

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