Recently I created a CentOS (Version 7) VM using VirtualBox for some development work I was doing, but foolishly I set the virtual disk to the default size of 8 gigs, figuring it would be easy to resize it later.
Well, after piecing together bits of information from several places I was finally able to get my virtual disk resized as well as my CentOS partition that was on it. Here are the steps that worked for me!
Expand VirtualBox Drive
The first thing you need to do is expand your virtual drive which I did using the VBoxmanage command line tool provided by VirtualBox (reference).
Note: Ensure virtual box root folder is on your path (e.g., C:\Program Files\Oracle\VirtualBox).
Resize the drive with the command VBoxmanage to the desired size in megabytes (e.g., here I am resizing the drive to 20 gigs):
VBoxmanage modifyhd MyCentosDisk.vdi --resize 20000
Resize Partition with GParted
Download the gparted live cd.
Attach the gparted live cd as a drive to your virtual machine and make it the “Primary Master”.
Note: Ensure the checkbox “Live CD” is selected when you add the CD drive.
Now start your VM.
The gparted UI will load. Now resize the parition by expanding it to use the available free space on the virtual disk.
Shutdown your VM, remove the gparted live cd drive and set your virtual disk to once again be the “Primary Master” drive.
However, after you restart your VM you will notice that CentOS is still not aware of the additional space:
Expand CentOS Partition
Now you will need to expand your Linux partition to use the free space on the drive.
First check the sizes of the current partitions and get the name:
On my system the name of the partition to expand was “/dev/centos/root”.
Extend the volume with the available free space:
lvextend -l +100%FREE /dev/centos/root
Now you are ready to perform the online resize:
NOTE: resize2fs works on other distributions of Linux but not on CentoOS, so you must use xfs_growfs (reference).
I hope that helps!