VirtualBox Disks Tasks

1 minute read


So I ran into an issue the other day… I have been using the default 16 GB .vdi files that VirtualBox creates when creating VM’s and noticed that I needed to expand to 50 GB. This is tough as I have like 4 production VM’s and wanted to make sure I didn’t lose any data. Well I ended up doing the following: Backing them up, deleting snapshots, resize the disks, un-attach the disks, rename the disks, expand the disks, re-attach, boot into GParted expand, boot into CentOS and expand the OS. Here is the steps in more detail.

To Resolve:

1a. So I read that best practice when it comes to expanding disks is to delete all the VM’s snapshots. Thankfully, this is easy to do via the GUI.

  1. Next, I wanted to rename the actual VDI files while I was expanding them to match their hostname. Well VirtualBox has a process for this:

2a. Go into the machines settings and remove the disk. Then go into File -> Virtual Media Manager and remove the disk there. Remember to “keep” the files!

  1. Rename the .vdi files to whatever you want.

  2. Open up Powershell as Admin in the disk’s directory and type for each vm and disk:

cmd /c "vboxmanage modifymedium disk vm-name.vdi --resize 51200"
  1. Download GParted iso and boot to that. Choose “33” for english and “0” for GUI. Select the disk and just expand all the way. Apply changes and then open Terminal and type poweroff now

  2. Boot into your VM and type:

# Determine free physical disk space (should be like 36 GB if you went from default 16 to 50 like I did)
sudo pvs

# PV = /dev/sda2 and get free avail space
sudo vgdisplay

# look for lv path, usually /dev/centos/root

# Now just expand vg to physical
sudo lvextend /dev/centos/root /dev/sda3

# lastly, expand the file system
sudo xfs_growfs /dev/centos/root

That’s it! Open up Caja to confirm.