Extend the disk, partition and filesystem on an LVM server when the root filesystem is full
To resolve disk space issues, you may extend the disk or partition on the affected server. These steps are for servers that use LVM (Logical Volume Manager), which is the default layout for an Ubuntu installation, and where the root filesystem (/) is full. To check whether your server uses LVM, run lsblk and look for a type of lvm on the root filesystem.
Before you begin: if the server is a virtual machine, first increase the size of the virtual disk in your hypervisor. Run all commands as root.
These steps extend the partition, the LVM volume and the filesystem to use the new space. They are performed online and do not require a reboot.
df -h /
lsblk
Note the device that holds the root filesystem (for example /dev/mapper/ubuntu--vg-ubuntu--lv) and the LVM partition it sits on (for example /dev/sda3). These names can vary between servers: the logical volume path depends on the volume group and logical volume names, and the disk and partition (such as /dev/sda and partition 3) depend on the disk type and how the server was partitioned. Replace them with the names shown on your server in the commands that follow.
parted /dev/sda resizepart 3 100%
This grows partition 3 to the end of the disk. Replace /dev/sda and the partition number with your own values. A notice about updating /etc/fstab may be displayed and can be ignored.
pvresize /dev/sda3
lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
The -r option also resizes the filesystem, so no separate resize command is needed.
df -h /
The root filesystem should now show the added space. These steps are performed online and do not require a reboot.
If your server does not use LVM, these steps do not apply. You can use any disk extension or partition management method that suits your server setup and device specifications. As a sample reference, see:
This link is provided as a reference only.