Description
Customers who have opted to use a custom ISO for operating system installation of their virtual server rather than the template-based installs provided will be limited in their ability to automatically expand their server's disk space in the event their VPS plan or storage is upgraded. These instructions provide a solution for Linux-based distributions that have been previously configured with LVM partitioning. Alternatively, these instructions can be adapted for customers of custom ISO installations who have opted to purchase secondary disk storage for the virtual machine. These steps can be performed safely on a live file system.
Resources
- Growing Logical Volumes - https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/lv_extend
- Resizing an EXT4 File System - https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/storage_administration_guide/ext4grow
Solution
Instructions below attempt to follow an LVM Volume Group named 'vg00' and expansion of the root file system through Logical Volume 'root'. You will need to adjust the commands below for your specific VG and LV system names for the volumes you wish to expand.
Once you have purchased additional storage or upgraded your VPS plan level, you will need to restart your virtual server from the control panel for disk changes to take affect. Your disk will be automatically resized during the reboot and changes will be reflected under fdisk. In this example, a 160 GiB virtual server disk has been expanded to 180 GiB as reflected in fdisk. There are currently only two default partitions for device /dev/sda. Partition 1 (/dev/sda1) is the boot partition and partition 2 (/dev/sda2) is the system's LVM partition which requires expansion.
# fdisk -l
Disk /dev/sda: 193.3 GB, 193273528320 bytes, 377487360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b254e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 335544319 166722560 8e Linux LVM
Determine your existing LVM configuration. In this case, physical partition /dev/sda2 is the only physical volume under LVM. Logical Volume 'root' is the intended target to be expanded which is part of Volume Group 'vg00'.
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg00 lvm2 a-- <159.00g 4.00m
# vgs
VG #PV #LV #SN Attr VSize VFree
vg00 1 2 0 wz--n- <159.00g 4.00m
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root vg00 -wi-ao---- 151.00g
swap vg00 -wi-ao---- 7.99g
Start by creating a new disk partition with fdisk and defining its type as an LVM member.
# fdisk /dev/sda
>> New Partition: n
>> Primary Partition: p
>> Partition Number (Default): 3
>> First Sector: select default
>> Last Sector: select default
>> Partition Type: t
>> Partition Number (Default): 3
>> Partition Type (LVM): 8e
>> Write Partition Table: w
Reload the partition table after creating the new partition by either rebooting the system or running partprobe.
# partprobe
# shutdown -r
Create a new LVM Physical Volume (PV) by adding the recently created physical partition to the LVM table.
# pvcreate /dev/sda3
Extend the existing LVM Volume Group (VG) 'vg00' by associating the new PV.
# vgextend vg00 /dev/sda3
Extend the existing LVM Logical Volume (LV) by associating the remaining free space of the VG. In this particular case, we're extending the volume with 100% of the available space for 20 GiB.
# lvextend -l +100%FREE /dev/vg00/root
Once extended, the file system must be resized to access the expanded disk space. Start by determining your file system type. Instructions below focus on the XFS and EXT4 file systems only. Instructions for resizing additional file system types can vary and the user should refer to their file system's documentation for further guidance.
# lsblk -f /dev/vg00/root
Resizing an EXT4 File System
# resize2fs /dev/vg00/root
Resizing an XFS File System
# xfs_growfs /dev/vg00/root
The increased disk space should now be reflected under the system's disk device and volume utilities.
# df -h
# lvs