7

for debug purposes i need to extend my disk to all unallocated space, for example

my full disk size is 931.5GB and i have the following partitions

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 107.5G  0 part /
└─sda3   8:3    0   3.8G  0 part [SWAP]

so my /dev/sda2 partiton is less than 931.5GB and i need to increase this partition with parted command to have more espace

unallocated space is : 819.72GB (see with gparted) parted /dev/sda resizepart 2 500GB but this command returns the following error :

 Can't have overlapping partitions

i am doing all this with a live usb in order to do not have mounted /dev/sda, the curious thing is that parted allow me to shrink the partition, i mean this

 parted /dev/sda resizepart 2 50GB

one more thing, if i can get the solution to this problem i would like to use the option -s in order to automate this process with some bash scripts

This is the output for fdisk -l command

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: C680462D-DE3F-4A97-B2A2-50226E7F9668

Device         Start       End   Sectors   Size Type
/dev/sda1       2048   1050623   1048576   512M EFI System
/dev/sda2    1050624 226453503 225402880 107.5G Linux filesystem
/dev/sda3  226453504 234440703   7987200   3.8G Linux swap

Thanks

10
  • What happens if you remove the SWAP partition temporarily. I can't tell because I can't "see with gparted" Commented Sep 15, 2016 at 19:12
  • how can i do that ? Commented Sep 15, 2016 at 19:13
  • Please edit your question and include the output of sudo fdisk -l so that we can see where your partitions begin and end. Commented Sep 15, 2016 at 19:15
  • done, please check the output for fdisk -l in the question Commented Sep 15, 2016 at 19:20
  • Checked and answered. Commented Sep 15, 2016 at 19:32

3 Answers 3

1

The reason you can't grow /dev/sda2 is your swap partition at /dev/sda3 is too close to /dev/sda2 to allow for any growth. Note that your /dev/sda2 partition starts at sector 226453503 and your swap partition begins at the very next sector 226453504. So in effect you are asking to grow a partition over the following one (a very bad idea, which is why gparted does not allow it).

In order to resolve this problem you could move the swap to the tail end of the drive (gparted comes to mind) or remove it and add it back after growing /dev/sda2 (with whatever partitioning tools you are most comfortable with). Sadly I have no suggestions for automating the process as it appears to be situationally dependent. However at least now you know the root cause of your problem.

There's a very similar issue and solution here.

4
  • ok, i understand, i'll try this and i'll report back Commented Sep 15, 2016 at 19:37
  • 1
    that's fix mi issue, i deleted swap partition and then i can grow my partition, thanks a lot Commented Sep 15, 2016 at 20:04
  • 1
    You might need that swap partition. did you reserve space for it and put it back? Commented Sep 15, 2016 at 20:29
  • Your OS may not find the swap partition when its UUID changes or it moves to sda4. Best to keep both the same. Commented Sep 29, 2023 at 15:47
0

Another pretty simple solution for anyone who may encounter this after adding a new boot partition (or any other partition, although may require some more steps) is to sort the partitions using gdisk before trying to resize via parted:

gdisk /dev/sdX
Command (? for help): s

After that, parted did not present the overlapping partitions error.

4
  • How is this a solution? The partitions are already in order of increasing start sector. This shouldn't change anything. Furthermore, even if the order was different, changing the order of the partition entries would not change the fact that the swap partition blocks the OS partition from growing into the unallocated space. Commented Sep 29, 2023 at 15:35
  • That is not always true. In my case, I had to convert the partition table from MBR to GPT. An additional boot partition was added at the beginning of the drive sectors, most likely due to a malfunction of the conversion or simply because GPT is designed to support dynamic resizing and reconfiguration of partitions, which means you can create, resize, and delete partitions without the same restrictions imposed by MBR where everything had to be in order from the start. A simple sort did the trick for me and stopped the overlap of the partitions. Commented Oct 1, 2023 at 12:46
  • Without knowing what exactly gdisk did to your disk, we cannot tell whether (1) it actually changed, as you believe, the start and/or end points of one or more partitions to fix the overlap, potentially resizing filesystem(s) or making other adjustments, (2) gdisk wrongly reports that there is an overlap if the start sector of a partition is earlier than the end sector of the previous partition and sorting the order of partition entries allowed it to see that no partitions overlap, or (3) there is an overlap but sorting the entries triggered a bug so gdisk no longer can see the overlap. Commented Oct 2, 2023 at 15:04
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Oct 9, 2023 at 1:38
0

To automate Elder's answer for a large number of clonzilla images with different disk sizes and partition sizes and assuming the basic layout EFI + OS + Swap is always the same and the OS is not hibernated on swap, the most difficult part is to move the swap partition to the end of the disk. Gparted does not seem to accept positions relative to the end (using negative start/end numbers). You'd have to process the output of parted print to find out how large the disk is and to automate the calculation of the start and end positions to use in the mkpart command of gparted (and align the start of the partition as desired, e.g. at multiples of 2048 sectors). You'd need some programming, e.g. as a shell script.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.