How to grow an LVM volume in the middle?
Yes its possible. A main point of lvm is it abstracts the disk away from the partitions so even if you free up blocks at the end of the disk (or in this case before the start of the next partition) lvm will allow you to add it to an existing partition because it maps the blocks internally. The only tricky bit herr is shrinking lv1, brcause it already has a filesystem on iit, and ext4 filesystems cant be shrunk online.
I consider all block device operations to carry a level of risk, and advise a backup prior to attempting them as a matter of best practice.
There is no songle correct solution, and im not at my pc so I cant test my dyntax, but the way I would do yhis would be -
-
Unmount lvm1 / get it into an unmounted state ( if its a root partition you may need to use a usb disk )
-
Shrink the filesystem on it smaller then it should finally be (you can use resize2fs/resize4fs to zhrink unmounted volumes)
-
use lvreduce yo shrink lvm1 to its desired size. Tjis must not be smaller then the resized ext4 partition.
-
Resize4fs (resize2fs) to expand the filesystem on lvm1.
(Strictly speaking if your math is spot on you dont need to resize the volume smaller then expand it, but I find this much easier yhen working with 512/1024/2048 byte blocks). At this point the hard part is done.
- Use lvexpand to grow lvm2 and resize4fs to grow the filesystem. This can be done online.