Bootstrap FreeKB - LVM (Logical Volume Manager) - Resize an LVM Logical Volume using the lvresize command
LVM (Logical Volume Manager) - Resize an LVM Logical Volume using the lvresize command


This assumes you are familiar with LVM (Logical Volume Manager). If not, check out my article Getting Started with LVM (Logical Volume Manager).

Before resizing a logical volume, you'll need to ensure the physical volume has available space.

The lvresize command can be used to add or remove space from an LVM logical volume. For example, let's say /dev/myVG/myLV is 1 GB.

~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/myVG/myLV
  LV Name                lv_foo
  VG Name                datavg
  LV UUID                kI5KSn-KGz8-ttcU-LwSS-MO4Q-gJiS-cY55aO
  LV Write Access        read/write
  LV Creation host, time server1, 2020-09-15 13:55:08 -0500
  LV Status              available
  # open                 1
  LV Size                1.00 GiB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:6

 

When increasing the size of a logical volume, there is no need to unmount the volume. The --resizefs flag and the --extents option can be used to add extents to the logical volume. In this example, the logical volume will use all of the available extents.

~]# lvresize --resizefs --extents +100%FREE /dev/myVG/myLV

 

The --resizefs flag and the --size option can be used to increase the size of the logical volume. In this example, the logical volume is increased to 2 GB.

~]# lvresize --resizefs --size 2G /dev/myVG/myLV

 

If the increase was successful, something like this should be displayed.

Size of logical volume myVG/myLV changed from 1.00 GiB (32 extents) to 2.00 GiB (64 extents).
  Logical volume myLV successfully resized.
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/myVG-myLV is mounted on /var/lib/mysql; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/myVG-myLV to 6553600 (4k) blocks.
The filesystem on /dev/mapper/myVG-myLV is now 6553600 blocks long.

 


Decrease size

To decrease myLV, you will first need to use the umount command to unmount the volume. For example, lets say /dev/myVG/myLV is mounted on /var.

~]# umount /var

 

You can now reduce the size of the volume. In this example, myLV is reduced to 900 MB. Prior to reducing the size of the volume, ensure no data is using the end of the sectors that will be eliminated.

~]# lvresize --resizefs --size 900M /dev/myVG/myLV

 

Use the mount command to remount the volume.

~]# mount -t ext4 /dev/myVG/myLV /var

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


July 06 2023 by Jim Rodgers
Thank you for these examples using the -r option. Is this a recent option as your is the only example using it that I have found.

Add a Comment


Please enter 048178 in the box below so that we can be sure you are a human.