How to resize the disk of an Ubuntu-VM correctly with GParted
2
votes
2
answers
2257
views
I use VirtualBox on Windows 10 to run a VM using Ubuntu 16.04.1 LTS.
I got the VM from my University with a disk size of 20GB which was way to optimistic ... so I want to resize it to 50GB
so I already did
0. (on the host) Make a BackUp ;)
1. (on the host) VBoxManage clonehd "source.vmdk" "clone.vdi" --format vdi
2. (on the host) VBoxManage modifyhd "clone.vdi" --resize 51200
3. (on the host) Downloaded GParted.iso
4. (in the VM) Booted into GParted
5. (in the VM) Expanded The Swap from 2GB to 4GB according to the RAM of the VM I also changed
Now I see the following image
As you can see obviously the new diskspace got added at the end of the disk. But now I'm facing the problem that I cannot expand the primary partition because the swap partition is "in the way". I neither am able to move the swap-partition.
**How can I expand the primary partition and/or move the swap partition to the end of the disk?**
The Idea I had was:
1. Delete

/dev/sda5
2. Delete /dev/sda2
3. Create new Partition /dev/sda2
with file format linux-swap
and the end of the disk
4. Expand /dev/sda1
to use the rest of the disk
**Is this the way to go? Will Ubuntu automatically "know" where the swap partition will be after this action?**
Asked by derHugo
(137 rep)
Oct 3, 2017, 01:15 PM
Last activity: Jul 25, 2025, 04:06 PM
Last activity: Jul 25, 2025, 04:06 PM