# Expand LVM Volume

### Expanding the Logical Volume

1. **Check Available Space: Before expanding, check how much free space is available in the volume group.**
    
    <div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative"><div class="sticky top-9 md:top-[5.75rem]"></div></div>
    1. **`vgdisplay`**
2. **Resize the Logical Volume: To extend the logical volume, use the following command. Replace `<size>` with the amount you want to add (e.g., `10G` for 10 GB):**
    1. **`sudo lvextend -L +<size> /dev/mapper/ubuntu--vg-ubuntu--lv`**
3. **Resize the Filesystem: After resizing the logical volume, you need to resize the filesystem to use the new space:**
    1. **For ext4 filesystem:**
        1. **`sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv`**
    2. **For XFS filesystem:**
        1. `<strong>sudo xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv</strong>`

**Shrinking the Logical Volume**

1. **Check Filesystem Size: Before shrinking, ensure the filesystem is smaller than the logical volume you want to resize it to. You might need to reduce the filesystem size first.**
    1. **For ext4 filesystem:**
        1. `<strong>sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv <new_size></strong>`
    2. For example, to shrink to 20G: 
        1. `sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 20G`
2. **Reduce the Logical Volume: Now you can safely reduce the logical volume:**
    1. **`sudo lvreduce -L <new_size> /dev/mapper/ubuntu--vg-ubuntu--lv`**
3. **Resize the Filesystem Again (if necessary): If you haven’t already resized the filesystem in the first step, you can do it now.**