Assumption: you are running virtualbox under windows and want to extend a linux partition. gparted should be installed.
- start a command line (window+r -> cmd
- go to your virtual installation directory (e.g.: cd C:\Program Files\Oracle\VirtualBox\)
- run the following command:
VBoxManage.exe modifyhd "C:\Users\maxmustermann\VirtualBox VMs\linuxhdd.vdi" --resize 51200
Replace maxmustermann with your username and the following directories with the path to your virtual disk image.
Replace 51200 with your desired size in MB (51200 is 50Gb).
- start virtual OS
- open terminal
- if swap is between the partition you want to extend and the free space, then you have to turn off swap. Otherwise, go to step 7.
sudo swapoff -a
- start gparted
- delete swap
- extend partion
- recreate swap: create linux extended partition. Right click on this partition and select create linux swap.
- activate swap
sudo swapon /dev/sdXX
Press TAB after sudo swapon and the right swap partition should be autocompleted.
*Thanks to Moritz Stolz for his help.