Extend CentOS 7 VirtualBox Disk Partition


linux-floppies

I recently had need to extend my Centos 7 volume from 8GB to 16GB. I used the Gparted live CD for this project which made it a little easier.

Use the command df -h to view your current partition. Below is my original 8GB partition, roughly 6.7GB after the swap space and Linux itself.

linux_before_resize

  1. The first step is to increase the size of the VirtualBox VDI file. Shutdown the VM if it’s running and resize the disk. In the below example I increased a 8192MB volume to 16384MB via the Windows CMD.
    • vboxmanage modifyhd "D:\VM\CentOS7\CentOS7.vdi" --resize 16384
  2. Next, attach the Gparted live CD to the VM from within VirtualBox Settings of the VM. Leave the primary VDI attached as SATA. Boot the VM into Gparted and hit Enter to select the default whenever a boot option prompt appears.
    • virtualbox-livecd
  3. Resize the partition by highlighting the /dev/sda2 lvm2 partition and clicking Resize/Move. Click and drag the black triangle to the max size and click Resize. Click Apply to save the new partition and exit out of Gparted.
    • gparted-increase-partition
  4. Shutdown the VM and remove the Gparted live CD from your VM configuration from within settings.
  5. Next, extend the volume from within CentOS. Boot the VM and extend the partition by the difference in the space added, in this case, around 8GB.
    • [root@localhost ~]# lvextend -L+8G /dev/centos/root
  6. Finally, extend the Linux filesystem. In order for the OS to utilize the new space, the filesystem must be extended onto it.
    • [root@localhost ~]# xfs_growfs /dev/mapper/centos-root

Now you should see the new, larger volume from within Linux.

linux_after_resize