Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ali-Raza-Arain/8fbedc80ad5b8848f36f9b66f67b1b83 to your computer and use it in GitHub Desktop.
Save Ali-Raza-Arain/8fbedc80ad5b8848f36f9b66f67b1b83 to your computer and use it in GitHub Desktop.
Extending your default LVM space in Ubuntu Server

Introduction

Ubuntu, by default, may leave a significant portion of disk space unused during installation. This guide will walk you through the process of extending your default Logical Volume Management (LVM) space to make better use of available resources. This is particularly useful when you're running out of space on your root filesystem.

image

Step 1: Check Free Space

  1. Open a terminal and use the command df -h to check the free space on your root filesystem. Identify the available space and assess whether you need to extend your storage.

    df -h

Step 2: Check Free Space in Volume Group

  1. To determine the free space in your Volume Group (VG), use the command vgdisplay. Look for the "Free" field, which indicates the amount of space available for extension.

    vgdisplay

    If no free space is available, proceed to the next section.

Step 3: Extend Logical Volume

  1. Run lvdisplay to check the current size of the Logical Volume (LV).

    lvdisplay
  2. Extend the LV to the maximum available space using the lvextend command.

    lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
  3. Confirm the changes by running lvdisplay again.

    lvdisplay

Step 4: Extend Filesystem

  1. Verify the almost full root filesystem using df -h.

    df -h
  2. Extend the filesystem to cover the increased LV size using resize2fs.

    resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
  3. Confirm the successful extension by running df -h once more.

    df -h

For a more detailed study or guide, visit Ubuntu: Extend your default LVM space.

Note: Be cautious and ensure you have backups before making significant changes to your system's storage configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment