Ubuntu – How to move the extended/swap partition

gpartedpartitioning

I'm trying to use gparted (booted from a live CD).

I can enlarge sda2, but I can't seem to be able to move its starting point (note how the arrows near the "Free space preceding" are grayed out. If I try to enter anything other than 0, it zeros out).

enter image description here

I'm trying to move this partition to the end, and increase sda1 to take all the unallocated space.

(FYI this is a vm running in VirtualBox)

Best Answer

You can not move the left border of the extended partition (/dev/sda2) because it contains a logical volume (/dev/sda5) right at its start.

Extended partitions are containers for logical volumes, but they are like a box without a bottom. If you would lift up the bottomless box, all its contents would still rest on the floor in the same place. It's the same for logical volumes, they do not move or resize automatically if you modify their container. As logical volumes may not exist outside their enclosing extended partition, it is not permitted to move or resize the extended partition in a way that would cause parts of its contained logical volumes to appear outside its borders.

You can still achieve your goal and make /dev/sda1 take up the remaining unpartitioned space on the disk, there are just a few more steps needed:

  1. Enlarge the extended partition (/dev/sda2) by moving its right border by the amount of space you want to finally add to /dev/sda1, probably you want to move it all the way to the right.

  2. Move the swap partition (logical volume /dev/sda5) inside the enlarged extended partition to the right end of its container.

  3. Shrink the extended partition (/dev/sda2) by moving its left border all the way to the right so that there's no more unallocated space left inside it (maybe one or two MB may not get assigned due to partition alignment, but that's no problem).

  4. Finally enlarge the primary partition (/dev/sda1) by moving its right border to occupy all the unpartitioned space you just shuffled right next to it.