virtualMachine

Extend an existing virtual disk

NOTE: Before proceeding with the steps below, back up your existing virtual disk by making a copy of it.

To extend an existing virtual disk and increase the disk space available on your virtual machine, follow the steps below:

  • If you are using VirtualBox, use the VBoxManage tool on the host system (bundled with VirtualBox) to clone the existing VMDK disk to VDI format. Replace the DISK placeholder with the full path to your virtual disk.

    In VirtualBox, you can obtain the location of the virtual disk by right-clicking the virtual machine and checking the value of the “Settings -> Storage -> Select your disk -> Location” property.

    $ VBoxManage clonehd DISK.vmdk cloned.vdi --format vdi
    

    Resize the cloned disk to your desired size (here, 36 GB or 36864 MB). Note that approximately 2 GB of the disk will be utilized by Linux system volumes like /dev and /run/shm.

    $ VBoxManage modifyhd cloned.vdi --resize 36864
    $ VBoxManage clonehd cloned.vdi expanded.vmdk --format vmdk
    

Resizing and cloning operations

  • If you are using VMware, use the vmware-vdiskmanager tool (bundled with VMware Workstation and VMware Fusion) to resize the existing VMDK disk to your desired size (here, 36 GB). Replace the DISK placeholder with the full path to your virtual disk.

    $ vmware-vdiskmanager -x 36GB DISK.vmdk
    

NOTE: The remaining steps in this section assume that you are using VirtualBox, but you can perform similar steps in VMware Workstation and other VMware products.

  • In the VirtualBox user interface, select the virtual machine and then use the “Settings -> Storage” menu to remove the current VMDK disk and replace it with the expanded one.

    Replacing disk image

  • Download the GParted LiveCD ISO image.

  • In the VirtualBox user interface, select the virtual machine and then use the “Settings -> Storage -> Add Optical Drive” menu item to select and attach the GParted LiveCD ISO image file.

    Attaching ISO

  • Save the changes and boot the virtual machine.

  • Once the GParted LiveCD starts, it will automatically launch the GParted partition editor, which looks like this:

    Partition editor

    Select the /dev/sda1 partition, click the “Resize/Move” button and enter the new size of the disk (in this example, 36864) in the “New size (MiB)” field. Click the “Resize/Move” button so that the /dev/sda1 partition fully utilizes the unallocated space.

    Partition resize

  • In the main GParted window, click the “Apply” button to apply and save the changes to the partition table.

    Partition table save

  • Shut down the virtual machine by clicking the “Exit” link on the GParted LiveCD desktop once the changes are applied.

  • In the VirtualBox user interface, select the virtual machine and then use the “Settings -> Storage” menu to detach the GParted LiveCD from the virtual machine.

  • Save the changes and boot the virtual machine.

Your virtual disk should have been resized. Check this by running the command below at the console and verifying the size of the /dev/sda1 partition:

    $ df -h

Verification

Last modification September 5, 2018