This page specifically describes a way to address the following condition on an OEL 7 VirtualBox virtual machine where the "/" filesystem is on a Logical Volume, however the concepts should apply to other situations...
df -h | grep -v tmpfs
i.e "/mnt/u01", "/mnt/u02" and "/mnt/AHF" are directly mounted disks (virtual disk images) whereas "/" is a filesystem on a logical volume that is nearly full.
Using the output of lsblk in conjunction with the df output from above we can see that "/" is a 17GB filesystem on a 17GB Logical Volume called "ol-root" which is on a 19GB partition called "sda2" which is on a 20GB disk...
lsblk
How do we add space so we can install other software in "/opt", for example?
vboxmanage list vms
vboxmanage showvminfo OracleLinux7 | grep UUID
In this case we can infer that "u01.vdi", "u02.vdi" and "AHF.vdi" map directly to "/mnt/u01","/mnt/u02" and "/mnt/AHF", therefore we can focus on "OracleLinux7.vdi"...
vboxmanage showmediuminfo disk /media/${USER}/HDD1/VirtualBox/OracleLinux7/OracleLinux7/OracleLinux7.vdi
Other useful commands...
vboxmanage list hdds
We will increase from 20GB to 50GB...
vboxmanage modifymedium disk "/media/${USER}/HDD1/VirtualBox/OracleLinux7/OracleLinux7/OracleLinux7.vdi" --resize 51200
All of the following steps should be run on the target Virtual Machine as 'root'
Using lsblk we can already see that the "sda" disk has increased in size to 50GB...
lsblk
We can use fdisk to get further information...
fdisk -l /dev/sda
We can use pvs and pvdisplay to understand how /dev/sda2 is used by the Logical Volume Manager (LVM)...
pvs /dev/sda2
pvdisplay /dev/sda2
We can see that /dev/sda2 is in the "ol" Volume Group and therefore we can use vgs and vgdisplay to get more information about that Volume Group...
vgs ol
vgdisplay ol
We can use lvs and lvdisplay to get information about the Logical Volumes in the "ol" Volume Group...
lvs ol
lvdisplay ol
To add the extra 30GB we created at disk level to the "/" Filesystem, we need to add more space to the Logical Volume "/dev/ol/root". Before we can do that we need to increase the size of the Volume Group by adding Physical Volume space. We can achieve this in one of two ways:
Increase the size of the "/dev/sda2" partition
Add a new "/dev/sda3" partition.
Option 2 would make sense if we needed to use multiple Virtual Disk Images (e.g. vdi files on different disks of our host system). This option is not yet documented here.
To increase the size of /dev/sda2 to fill the newly extended vdi (now 51200MB) use parted...
NOTE: The default unit for parted is MB (this can be misleading when the prompt shows a size in GB)
parted
Note that at this stage the output of pvs, vgs and lvs will not have changed, but lsblk should show that the new size of the "sda2" partition...
lsblk
We can now call pvresize without options to resize the "sda2" physical volume to the size of the "sda2" partition...
pvresize /dev/sda2
We can see the change in the output of pvs and pvdisplay...
pvs /dev/sda2
pvdisplay /dev/sda2
We can also see that there is free space available in the "ol" Volume Group using vgs and vgdisplay...
vgs ol
vgdisplay ol
To extend the Logical Volume we can use lvextend. We will allocate all 7087 free PEs...
lvextend -l +7087 /dev/ol/root
Use lsblk to see results...
lsblk
For our final task we need to resize the filesystem to use the extra space in the Logical Volume.
First we need to identify whether this is an xfs or ext4 filesystem. This can be found in /etc/fstab...
cat /etc/fstab|grep "/dev/mapper/ol-root"
Use xfs_growfs
xfs_growfs -d /
Use df to check...
df -h | grep -v tmpfs
vboxmanage list vms
vboxmanage showvminfo OracleLinux7 | grep UUID
In this case we can infer that "u01.vdi", "u02.vdi" and "AHF.vdi" map directly to "/mnt/u01","/mnt/u02" and "/mnt/AHF", therefore we can focus on "OracleLinux7.vdi"...
vboxmanage showmediuminfo disk /media/${USER}/HDD1/VirtualBox/OracleLinux7/OracleLinux7/OracleLinux7.vdi
Other useful commands...
vboxmanage list hdds
We will increase from 20GB to 50GB...
vboxmanage modifymedium disk "/media/${USER}/HDD1/VirtualBox/OracleLinux7/OracleLinux7/u01.vdi" --resize 51200
All of the following steps should be run on the target Virtual Machine as 'root'
The following command should show the new disk size...
lsblk
The df command should still show the old size but will also show the device name...
df -h
The following command will resize the filesystem on the specified device to the largest size possible...
resize2fs /dev/sdb
The df command should now show the new size...
df -h