No one can discuss that virtual machines are a very important tool. Maybe, nowadays, with all the container solutions they are a bit less important but they are still very useful.
When we are using a virtual machine, one of the possible problems we can find in some point is that our hard drive can reach its maximum capacity. Luckily, this is not the end of the world and we can expand our HDs.
Important note: We are going to loss the snapshots we have. (But, it is a small price to pay to avoid to start a new machine from scratch.
This quick manual is going to be based on VirtualBox, I guess that for other virtualization tools it must be similar using the appropriate tools.
First thing we need to do, it is to stop our virtual machine.
After that, we have some command line tools that they are going to do this process “simple”.
The first command we are going to execute is going to clone our HD in “vmdk” format to a new one with “vdi” format:
VBoxManage clonehd <virtual_machine_path>/<hd_name>.vmdk" <new_name>.vdi --format vdi
This process will take some time depending on the HD size.
Once the command has finish its execution, we are going to increase the size of the cloned HD. Les’t imagine the initial size of the HD was 80GB and we want to duplicate it:
VBoxManage modifyhd <new_name>.vdi --resize 163840
Again, once the operation is finished, we need to clone the new HD from a “vdi” format to “vmdk” format:
VBoxManage clonehd <new_name>.vdi <hd_name_new>.vmdk --format vmdk
After waiting for the operation to finish, we will have our new HD ready to plug in our virtual machine. This is going to be the next step. Go to the VirtualBox user interface and replace the old HD device with the new one.
Now, if we start our virtual machine we will still see the old size and we will not be able to find the new 80GB added. This is because we are missing one step. Turn off your virtual machine again if you have turned it on before reading these lines and follow the next step.
In a similar way we have replace the old HD with the need one, we are going to load in the CD-ROM unit the GParted live iso.
Now, we should run again our virtual machine but, instead of leaving to boot as usual, we will press F12 on startup to be able to choose the unit we want to use to boot the virtual machine. CD-ROM will be one of the offered option. After this and a few options selected during GParted start, GParted will boot. Now we just need to expand the current partition to cover the new added space.
And, that is all. We can shutdown the virtual machine, remove the live iso from our devices attached to the virtual machine and boot it again. Now, we will be able to see the 160GB HD.