Expanding a disk with ubuntu and virtualbox

I have no more free space in my virtualbox disk.  And i created the disk as "static" which is an obstacle when you want to expand the disk:


 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage modifyhd Linux1.vdi --resize 20000  
0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize hard disk operation for this format is not implemented yet!

The disk says "Format variant: fixed"


 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage showhdinfo Linux1.vdi  
UUID: 3492e240-1589-479f-a6d7-f58586a7a671
Parent UUID: base
State: created
Type: normal (base)
Location: /home/walter/VirtualBox VMs/intraweb/Linux1.vdi
Storage format: VDI
Format variant: fixed default
Capacity: 4853 MBytes
Size on disk: 4854 MBytes
In use by VMs: intraweb (UUID: 76173fac-f9b3-4cf9-9daf-06e363eecd6d)

The first thing you have to do, just clone the disk.  Once cloned, it will be dynamic:

 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage clonehd Linux1.vdi Linux1d.vdi  
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VDI'. UUID: e8f06a57-805e-464f-8cbc-3e23d082a003
walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage showhdinfo Linux1d.vdi
UUID: e8f06a57-805e-464f-8cbc-3e23d082a003
Parent UUID: base
State: created
Type: normal (base)
Location: /home/walter/VirtualBox VMs/intraweb/Linux1d.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 4853 MBytes
Size on disk: 4475 MBytes

Now, i changed the original disk with this new one in the Virtual Box GUI Management and everything was smooth.

Next, i just resized the disk to have 20 Gig instead of only 4 Gig
 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage modifyhd ~/VirtualBox\ VMs/intraweb/Linux1d.vdi --resize 20000  
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Now i started the ubuntu desktop to use gparted and resize the guest operating system:

Choose to "Try Ubuntu"

Make sure to choose the right disk, i can not take any responsibility if something of this goes wrong:


I was not able to move the swap disk, so i removed it with fdisk.

fdisk /dev/sda
d 5
d 2
w
And then i started gparted again. Now i was able to resize the partition.  Then, i rebooted the virtual machine and opened gparted again.  Added the swap partition and rebooted.