Extend Disk on a VirtualBox VDI

Intro

If you are running your RuBAN installation on a virtual machine you may at some stage need to extend the disk size. This tutorial shows you how to enlarge a disk on a VirtualBox machine hosted on Windows.

Assumptions

This tutorial is based on the assumption that you have a working virtual CentOS machine set up in VirtualBox hosted on a Windows machine.

Instructions

Step 1:

Ensure that your VirtualBox machine is set to Powered Off, not saved.

Step 2:

In the Windows command prompt, navigate to the folder where VirtualBox is installed, so as to be able to access VirtualBox commands.

The relevant folder is typically C:\Program Files\Oracle\VirtualBox

Step 3:

While still in the VirtualBox folder, use the VirtualBox modifyhd command to resize the virtual disk file.

In this example the file CentOS-RuBAN.vdi is being resized to 81920 MB (80 GB):

VBoxManage modifyhd “C:\Users\Alex\VirtualBox VMs\CentOS-RuBAN\CentOS-RuBAN.vdi” --resize 81920

Step 4:

Boot your VirtualBox machine and log on.

Step 5:

If you didn't log on as root already you can use the sudo bash command to enable execution of all commands as root.

sudo bash

Step 6:

Check which partition was extended by running the fdisk -l command.

fdisk -l

Step 7:

We will now assume that the sda partition was extended. If that is the case we can now create a new primary partition on sda:

fdisk /dev/sda

Step 8:

Create a new partition with n, then p and tag it with t as type 0x8e. Write your changes with w and exit fdisk. See below image:

Step 9:

Reboot your virtual machine.

Step 10:

Create a new physical volume. We will now assume that the volume is sda3:

pvcreate /dev/sda3

Step 11:

Add the new partition to your volume group:

vgextend VolGroup /dev/sda3

Step 12:

Now expand your partition, here exemplified as a 80GB expansion:

lvextend -L +80G /dev/mapper/VolGroup-lv_root

Step 13:

Resize the partition:

 resize2fs /dev/mapper/VolGroup-lv_root

 

You have now finalised the process of enlarging the disk on your virtual machine.