Gparted - How to move partition to extend the size

26,328

Solution 1

  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

Solution 2

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.

Share:
26,328

Related videos on Youtube

Shadin
Author by

Shadin

Updated on September 18, 2022

Comments

  • Shadin
    Shadin over 1 year

    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?

  • Byte Commander
    Byte Commander about 9 years
    Very good answer. This covers all steps that are needed. But please add the advice to create a backup before starting!
  • Byte Commander
    Byte Commander about 9 years
    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.
  • gyropyge
    gyropyge about 9 years
    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.
  • Byte Commander
    Byte Commander about 9 years
    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!
  • gyropyge
    gyropyge about 9 years
    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
  • Znik
    Znik almost 7 years
    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.