Increase live Ubuntu server disk space (requires LVM) without any downtime.
All of the commands below need to be executed as root user.
-
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
fdiskofgdisk.fdisk /dev/sda n (new partition) p (primary) w (to write the changes)
-
Create a new physical volume. If the last one is
/dev/sda3then create/dev/sda4etc..pvcreate /dev/sda4
-
Extend the volume group using the newly created physical volume.
vgextend ubuntu-vg /dev/sda4
-
Extend the logical volume using all remaining free space in volume group. You can run
lvdisplayto get the logical volume path.lvextend --resizefs -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
-
(Optional) If you do not include the
—resizefsflag 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 byresize2fsbut 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
Remember to run these as root.
pvs
vgs
lvspvscan
vgscan
lvscanpvdisplay
vgdisplay
lvdisplaydf -h
du -h -d3