Loading up virtual machines is an easy to accomplish task, but configuring them properly is an ongoing balancing act. It’s very likely that in a virtualized environment you will over/under provision resources to a VM.
Adjusting CPU or Memory resources under Hyper-V is simple. You shutdown the VM, open the VM’s settings, and increase or decrease the allocated RAM or virtual CPU cores. When it comes to shrinking or expanding a virtual hard disk however, things get slightly more complicated.
The reason for the added complexity is that the VM thinks it’s running on physical hardware, so when you expand a hard disk, you need to let the OS know about your plans for it before you can start using the space just like if you were to add an unformatted hard drive to you desktop. To do this, you’ll probably want to boot the VM onto a Live OS disk to aid in the partitioning. In this guide, I’ll be using Parted Magic.
Start by shutting down the virtual machine. Once you have done so, right click on the VM and choose ‘Export’. This will create a backup of your VM in case something goes wrong. After all, editing drive partitions can be very dangerous if something goes wrong.
Now, right click on the VM and choose ‘Settings’.
Next, expand the IDE Controller node and select the virtual hard disk you want to expand. On the right side of the window, click the ‘Edit’ button below the Virtual hard disk path.
Using the Edit Hard Disk Wizard, choose the ‘Expand’ option, then click next and set the new disk size and complete the wizard. This will expand the virtual hard disk.
In your VM’s settings window, mount the .iso file for Parted Magic to the DVD Drive, boot the VM, and connect to the terminal session.
When Parted Magic posts, you’ll have several choices to boot into. You should stick with the Default 32 for a 32 bit OS or Default 64 for a 64 bit OS.
Once the Live OS loads, you’ll be greeted with a full GUI along with a multitude of system tools. In this case, the tool we’ll be using is the Partition Editor. Open it by double clicking the icon on the desktop.
You’ll be greeted with the GParted partitioning application and you should see your expanded space in the top graphic in grey and labeled unallocated.
It’s much easier to expand a partition than it is to copy a partition to a new location. In order to expand a partition, the unallocated space needs to be positioned next to the partition you are trying to expand.
In my case, I need to move the extended partition to the right so that I can extend the boot partition.To do this, I right click the extended partition and choose Resize/Move. Then I drag the partition all the way to the end to consume all of the unallocated space, then press Apply.
Next, I right click the linux-swap partition and choose Resize/Move again. This time, I drag that small partition all the way to the right so that the unallocated space is at the beginning. Then right click the extended partition again, and this time grab at the beginning and shrink the partition all the way to the right. to create free space at the beginning and press Apply.
You now have unallocated space next to the boot partition that you can easily grow into.
Now you can extend your partition. To do so, right click the main partition and choose Resize/Move. Drag the slider all of the way to the right to consume the additional space, then apply. This will grow your partition into the new space.
You’re done extending your partition. Now you can shutdown the VM and unmount the DVD. When you reboot the VM you’ll have gained the new space in your OS. You can verify this by running fdisk -l in the terminal.