Skip to content

Instantly share code, notes, and snippets.

@tomdaley92
Last active June 14, 2024 01:09
Show Gist options
  • Save tomdaley92/025e1b8ba1389ce738d0bf930ca1aa20 to your computer and use it in GitHub Desktop.
Save tomdaley92/025e1b8ba1389ce738d0bf930ca1aa20 to your computer and use it in GitHub Desktop.

Increasing LVM Disk Space (Ubuntu)

Increase live Ubuntu server disk space (requires LVM) without any downtime.

All of the commands below need to be executed as root user.

  1. Create a new partition using unallocated space.

    First we'll need to determine exactly which disk was added or had its size increased.

    lsblk

    This next command shows sector start/end of the free space of the disk, which is wise to verify when creating the partition.

    ⚠️ It might or might not be device /dev/sda, depending on the request and whether a disk was extended or added, so this is on you to make sure! The example shown below assumes device is /dev/sda.

    parted /dev/sda unit s print free

    Create a new partition with fdisk of gdisk.

    fdisk /dev/sda
    n (new partition)
    p (primary)
    w (to write the changes)
  2. Create a new physical volume. If the last one is /dev/sda3 then create /dev/sda4 etc..

    pvcreate /dev/sda4
  3. Extend the volume group using the newly created physical volume.

    vgextend ubuntu-vg /dev/sda4
  4. Extend the logical volume using all remaining free space in volume group. You can run lvdisplay to get the logical volume path.

    lvextend --resizefs -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
  5. (Optional) If you do not include the —resizefs flag with the previous lvextend command you will need to run an additional command to inform the underlying filesystem of the new space. Most linux file systems are covered by resize2fs but in this case we are dealing with an XFS file system so we would use a different utility.

    xfs_growfs /dev/ubuntu-vg/ubuntu-lv
    

Troubleshooting

List of LVM commands that each show you slightly different things

Remember to run these as root.

pvs
vgs
lvs
pvscan
vgscan
lvscan
pvdisplay
vgdisplay
lvdisplay

Disk Usage assesment

df -h
du -h -d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment