Jul 032023

As an update to my old post – https://sirlagz.net/2016/01/20/live-resizing-lvm-on-linux/ – since utilites mature and change, tasks can get easier (or harder) as there are more commands and functionalities added.

In this instance, parted and lvm have been updated to make this a bit easier.

Step 1 – Resizing Hard Drive

This step remains the same. Expand the disk on your hypervisor, and if it doesn’t automatically update in the virtual machine itself, try running the following command

# for x in /sys/class/scsi_disk/*; do echo '1' > $x/device/rescan; done

If the disk is still the same size in fdisk, then you’ll need to reboot the server.

Step 2 – Resizing Partition

Again we’ll need to use parted in this step, but the commands are a bit easier.

Run parted as root, and then run a print free command to make sure that you have space at the end of the partition.

You can see in my screenshot that my drive has some Free Space at the end

I need to resize both partitions 2 and 5 in my instance, but your situation may or may not be the same. Run the following commands to resize both partitions 2 and 5 to the maximum available space.

resizepart 2 100%
resizepart 5 100%

Now run print free again to verify that the partitions have been resized.

Run quit to exit parted.

Step 3 – Resizing Physical Volume

This is the same as before, do a pvresize to expand the physical volume to the maximum capacity. Make sure you’re specifying the correct partition.

pvrsize /dev/vda5

Step 4 – Resize Logical Volume and Filesystem

Now here is where it changes a bit. I don’t know when LVM got the ability to resize the filesystem as well (assuming it’s a filesystem that the utilities support. I use ext4 on most of my systems), but we can now resize everything in one go.

If you don’t know the path of your logical volume, you can check with the lvdisplay command

Run the lvresize command with the path to resize both the volume and filesystem in one go

lvresize -l +100%FREE -r /dev/VolGroup/lv_root

Now your filesystem will have been expanded to all available space on the disk.


 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



This site uses Akismet to reduce spam. Learn how your comment data is processed.