I want to extend the sda1 to take the full unallocated size:

enter image description here

The steps are as the following:

  1. Move sda2 to the right

  2. Increase the size of sda1 to fill the space

But the thing is, I didn't get how to do so! Any help?

  1. Boot a live system (for example boot from a usb stick).
  2. Resize sda2 all the way to the right.
  3. Move sda5 all the way to the right inside sda2.
  4. Resize sda2 from the left to the right.
  5. Resize sda1 all the way to the beginning of sda2.

Apply after each single step in this case. Changing size on the right hand side will go fast, changing size on the left hand side will take way more time.

Make sure to have a backup. If you don't have one, the closest point in time is always the best point in time to make one. Especially when changing partitions.

You can make one within the live sessions or you can use the opportunity of being in a live session to copy your entire HDD to an external HDD. Do the latter one only if you have a lot of storage space on your external HDD. You can use this command:

dd if=/dev/sda bs=8M | gzip -9 > /yourExternalHddMountPoint/folder/image.gz

9 is the best compression. A lower number will make the process faster but will take more storage space on your external HDD.

If you choose to copy your HDD rather than backing up you files, you can always take the entire HDD back to the previous state with this command (in a live session, of course):

cat /yourExternalHddMountPoint/folder/image.gz | gunzip -d -c | dd of=/dev/sda bs=8M
|improve this answer|||||
  • Very good answer. This covers all steps that are needed. But please add the advice to create a backup before starting! – Byte Commander Mar 31 '15 at 13:10

Updated answer. Since I wrote the following I've noticed that according to the screenshot, your swapspace is not in use. If it were in use it would show as mounted. Since it is not being used (cannot be benefited from) you may as well first delete the swapspace (sda5) and then the extended partition. This will free up still more space and make the task of expanding the primary partition much easier.

--- original answer --- Generally speaking you cannot resize the partition you are booted from for the simple reason that before you can resize or move a partition, you must unmount it, and if you could unmount it, your system would stop working.

First backup your data if you have a brain. I've read too many sob stories here not to recommend this first.

Boot to external media such as a portable external hard drive to which Ubuntu is installed, rather like the Mubuntsticks self-booting flash drives (pen drives) I keep promoting as a solution. Alternatively you can use a bootable ubuntu live CD/DVD or Ubuntu installation boot flash drive of you have one.

Now, provided you are ready, moving the second partition to the right involves selecting that partition, right clicking, select resize move, and make sure the space after it is ZERO. After you do that, you should be able to resize the primary partition, provided it is not mounted.

|improve this answer|||||
  • Thank you for explaining the need to unmount and the importance of a backup, but you did not explain how to handle the extended partition. You can't just move sda2 - you have to enlarge it to the right, move the inner logical volumes (here: sda5) to the right border and then shrink the extended partition from the left. – Byte Commander Mar 31 '15 at 13:15
  • I am NOT saying you are incorrect, but I've never heard of moving the petition by enlarging it and then shrinking it in the direction you enlarged it. – gyropyge Mar 31 '15 at 17:57
  • Not normal partitions, but the extended partition only. This is because an extended partition is just a container for logical volumes. Therefore the inner volumes have to be moved before the outer partition can be moved. And the inner volumes only can be moved when the outer partition has enough "unallocated" space inside. You can check and try this behaviour in GParted, even without applying the chances: you can not move an extended partition containing logical volumes! – Byte Commander Mar 31 '15 at 20:42
  • 2
    I don't honestly remember if extended partitions to be used, however it would not even matter in the case of the pictured example above. The only L-partition in that extended partition is the swap and it can be deleted. As you can see it is not mounted. I've discovered that for some reason many ubuntu installations become "detached" from their assigned swapspace. It can be remedied by manually editing the file named "fstab" (in the ETC folder in the root directory). Even that can be tricky. Instead I usually install the "Dynamic Swapspace Manager". pqxx.org/development/swapspace – gyropyge Apr 2 '15 at 20:31
  • You are right. In preferred recipe is many completly unneeded operation. It all can be done on-line. first is swapoff, delete swap and extended partition. second is add some free space to sda1, file system won't be touched. you should leave some free space for new swap. next you can create new swap partition at the end as sda2, or extended plus swap as sda5. last step for swap you must format new swap by mkswap /dev/sda2 or /dev/sda5, maybe edit /etc/fstab and swapon -a . If all is perfect, you can extend on line ext3/ext4 filesystem on increased sda1 by tune2fs . No any reboot is needed. – Znik Jun 22 '17 at 10:48

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.