My Adventures in Coding

November 21, 2016

VirtualBox – Resize a CentOS Virtual Drive

Filed under: CentOS,Linux,VirtualBox — Brian @ 9:51 pm
Tags: , , , ,

Recently I created a CentOS 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 partition 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:

df -h

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:

vgdisplay -v

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:

xfs_growfs /dev/centos/root

NOTE: resize2fs works on other distributions of Linux but not on CentoOS, so you must use xfs_growfs (reference).

I hope that helps!

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: