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

  1. (on the host) Make a BackUp ;)
  2. (on the host) VBoxManage clonehd "source.vmdk" "clone.vdi" --format vdi
  3. (on the host) VBoxManage modifyhd "clone.vdi" --resize 51200
  4. (on the host) Downloaded GParted.iso
  5. (in the VM) Booted into GParted
  6. (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 GParted 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?

  • If this is a new system, I would just set up logical volumes. That way you can set up partitions wherever you want and combine separate partitions to form file systems. Oct 3 '17 at 13:32
  • Yeah but as I mentioned I got the System from the university (fully installed and with programs builded we have to use)
    – derHugo
    Oct 3 '17 at 13:33
  • Check if /dev/sda2 is in use first. If not, then you should be OK doing what you suggested, Oct 3 '17 at 13:42
  • Ok it said used 0, so I did it now. Waiting for the boot .. how can I in general know, if Ubuntu is using my swap correctly?
    – derHugo
    Oct 3 '17 at 13:43
  • swapon -s will give you details regarding usage. Oct 3 '17 at 13:46

In this particular case, you can probably disable the swap space, move the swap partition, and re-enable it (swapoff dev/sda5, move the partition, then swapon /dev/sda5). Recreating the swap partition by hand as you suggested will likely cause Ubuntu to fail to recognize it (it will have a different UUID than the original swap partition, which in turn means it won't be automatically enabled).

The more generically useful (and arguably safer) option is to instead boot into a maintenance LiveCD (System Rescue CD is what I personally use for this, but there are other options, including one that is also called GParted and is designed specifically for this type of thing), and move and resize things from there as needed.

  • If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
    – derHugo
    Oct 4 '17 at 4:57
  • @derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here. Oct 4 '17 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.