Increase vmdk disk in VirtualBox

The steps below are specific to increase a VMDK disk in VirtualBox 6.1.40 for a CentOS 7 guest VM and on a MacOS host. The steps should still be relevant enough for your specific situation and will give an idea of what is needed to increase your VM’s disk space. You may have to tweak and adjust as needed for your scenario.

There are 2 general parts. First, you need to increase the VMDK storage of your guest VM in VirtualBox. Second, you then boot into your guest OS with the increased storage and run some commands to expand the guest OS’s file system to make use of the extra storage that has become available.

The example below increased a 60GB storage file to 160GB.

Part 1: expand VMDK storage file

cd ~/VirtualBox VMs/MyGuestVM
VBoxManage createmedium disk --filename ./MyGuestVM2.vmdk --format VMDK --size 163840
VBoxManage clonemedium disk ./MyGuestVM.vmdk --existing ./MyGuestVM2.vmdk

Once you have created the new VMDK file and cloned the original one into the new one, open the VirtualBox tool and swap out the storage file for the new one. Then launch your Guest OS.

Part 2: expand Guest OS file system

Now that your Guest OS has more storage available, you need to expand its file system to use that new storage. It does not happen automatically. The steps below are for CentOS 7 but other Linux flavours and versions should have similar steps. At the least you get an idea of what your next steps may be for your case.

First get some details about your storage and file systems. All commands must be run as root user.

$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   60G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   59G  0 part 
  ├─centos-root 253:0    0   37G  0 lvm  /
  ├─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 18.1G  0 lvm  /home
sr0              11:0    1 1024M  0 rom  

And

$ vgdisplay
# Take note of the "VG Name" value, for instance "centos"

Use the information gathered above to add a new partition, extend the volume, and extend the file system.

$ fdisk /dev/sda  # add primary partition
$ reboot

After the reboot, continue with next steps:

$ pvcreate /dev/sda3
$ vgextend centos /dev/sda3
$ lvextend -r -l +100%FREE /dev/centos/root

Verify the new storage:

$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  160G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   59G  0 part 
│ ├─centos-root 253:0    0  137G  0 lvm  /
│ ├─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
│ └─centos-home 253:2    0 18.1G  0 lvm  /home
└─sda3            8:3    0  100G  0 part 
  └─centos-root 253:0    0  137G  0 lvm  /
sr0              11:0    1 1024M  0 rom  

Leave a Reply

Your email address will not be published.