Simply you have to follow the following steps:
- Power off your machine.
- Right click on virtual machine name > Settings > Storage
- Click on Controller : SATA > Add Hard Disk.
- Choose the new hard disk drive type size and hit create.
- Discard the machine state.
- Insert Ubuntu Live CD.
- Boot from ubuntu live cd.
- Open "gparted" (It's installed, not need to installation).
- Check if the system see your new created hard disk.
- Open Terminal.
- Type the following code.
- sudo dd if=/dev/sda of=/dev/sdb (The first is the old partition path, the second is the new partition path).
- Wait until its finish copying data (This step may take some time according to your host specs).
- After finish copying, return to gparted and select refresh devices.
- Select the new partition /dev/sdb it must be typical to the old one after doing dd command.
- It'll show the expanded space as unlocated data.
- Delete Swap partition/Extended partition.
- Right click on root partition /dev/sdb > Resize
- Allocate the whole space without swap allocation.
- Create new extended partition > Choose extended > Create
- Create new linux-swap partition > choose linux-swap > Create
- Now turn off your running machine.
- Right click on machine > settings > Storage.
- Eject ubuntu live cd.
- Right click on the old hard disk > remove attachment.
- Now you can start your vm from the newly created hard disk.
- Check the storage by enter df -kh command.
- It must show you the new size.
Congratulation, enjoy your free space.
This video will help you:
https://youtu.be/ikSIDI535L0