1

I am trying to image my Ubuntu disk using Clonezilla and it fails because I get an error saying:

error cannot have overlapping partitions

Below is how my disk is set up and the lsblkoutput:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1         7:1    0  42,2M  1 loop /snap/snapd/14066
nvme0n1     259:0    0 953,9G  0 disk 
├─nvme0n1p5 259:3    0   976M  0 part [SWAP]
└─nvme0n1p1 259:1    0 952,9G  0 part /

And here is the output of fdisk -l /dev/nvme0n1

Disk /dev/nvme0n1: 953,9 GiB, 1024209543168 bytes, 2000409264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6e617337

Device         Boot      Start        End    Sectors   Size Id Type
/dev/nvme0n1p1 *          2048 1998407679 1998405632 952,9G 83 Linux
/dev/nvme0n1p2      1998409726 2000397734    1988009 970,7M  5 Extended
/dev/nvme0n1p5      1998409728 2000408575    1998848   976M 82 Linux swap / Sola

And here is how it appears in gparted:

enter image description here

Any advice how to fix this error so I can image/save my disk?

8
  • Please describe what you have plugged into your PC/NTB, if only this disk, and want to save it (for later use I suppose) or two drives, in which case we can directly tell you steps needed to copy drive. Nov 27, 2021 at 0:27
  • For example, pv won't care for the layout you have in case it is somehow wrong. See my answer here superuser.com/a/1116299/402107 Nov 27, 2021 at 0:28
  • @LinuxSecurityFreak I want to know how I can fix this overlapping issue, as I can see from fdisk it seems that nvme0n1p2 and nvme0n1p2 are overlapping, is that normal or this is what is causing the problem? If so, how it can be fixed? Thanks in advance for your help.
    – Tak
    Nov 27, 2021 at 0:33
  • @LinuxSecurityFreak Thank you, good night.
    – Tak
    Nov 27, 2021 at 1:13
  • 1
    If nothing else, you can reasonably safely delete partitions 5 and 2 since they jointly hold a single swap partition. That'll fix the overlap error but you will need to fix up the expectation of what's now a missing swap partition in the cloned image. Let's see if anyone else comes up with a cleaner solution Nov 27, 2021 at 1:50

1 Answer 1

2

Answer adapted from: how-to-fix-overlapped-partitions-in-the-mbr-table. You can try this but i think much be easier solution to just delete swap and logical partition


Fixing the partition table with sfdisk:

  1. Boot with live Ubuntu disk;

  2. Confirm the problem on your disk device, here /dev/sda with parted e.g.

     sudo parted /dev/sda unit s print which should show:
    
     Error: Can't have overlapping partitions.
    
  3. Partition details can be checked with:

     sudo fdisk -l -u /dev/sda 
    

which, for you, according to your post is:

Disk /dev/nvme0n1: 953,9 GiB, 1024209543168 bytes, 2000409264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6e617337

Device         Boot      Start        End    Sectors   Size Id Type
/dev/nvme0n1p1 *          2048 1998407679 1998405632 952,9G 83 Linux
/dev/nvme0n1p2      1998409726 2000397734    1988009 970,7M  5 Extended
/dev/nvme0n1p5      1998409728 2000408575    1998848   976M 82 Linux swap / Solaris
  1. Checking the overlaps: You can see that your extended partition /dev/nvme0n1p2 is smaller than your swap partition /dev/nvme0n1p5.

To make things more clear your swap partition is inside the that extended partition and hence it's size should be smaller that extended partition size ideally.But in your case swap size is greater than logical partition size itself.

Device            Size  

/dev/nvme0n1p2    970,7M  
/dev/nvme0n1p5    976M    

or in other words end sector of nvme0n1p2 should be greater than end sector of nvme0n1p5.But in your case

nvme0n1p2end = 2000397734

nvme0n1p5end = 2000408575

and hence the problem.

Now you can simply solve it by reducing you swap partition size simply using gparted. (~ 600MB - 700MB)

OR you can use command line tools :

sfdisk

Using sfdisk

  1. As suggested in the documentation that - "In cases where we do not know if the starting or ending sector is the problem, we assume that the starting sector of each partition is correct, and that the ending sector might be in error", we assume that the starting sector of extended partition nvme0n1p2 is correct. Hence we will be looking to change the end sector of swap partition nvme0n1p5.

Calculations:

nvme0n1p5newEnd = nvme0n1p2end - 1 = 2000397734 - 1 = 2000397733

nvme0n1p5newSize = nvme0n1p5newEnd - nvme0n1p5start = 2000397733 - 1998409728 = 1988005

  1. Dumping a copy of the partition table in an file using the sfdisk command:

sudo sfdisk -d /dev/sda should dump the partition table details. This can be dumped to a file, which after necessary corrections are made, can be fed back to sfdisk. [To OP: Please edit your Question and include the output of sudo sfdisk -d /dev/sda]

Dump a copy of partition table with:

    sudo sfdisk -d /dev/sda > sda-backup.txt 
  1. Open the file with root privilege, created in the previous step, using text editor of your choice. In the example I'll use nano.

     sudo nano sda-backup.txt (`sda-backup.txt` assuming the file is in the current directory, else repalce it with the file's absolute
    

path.)

Change the old size of nvme0n1p5 (1998848) to the corrected size (1988005) so that your new partition table dump would look something like:

output not attached by op

Save the file (Ctrl+O for nano) and close the editor (Ctrl+X for nano).

  1. Feeding back the corrected partition details to the partition table using the sfdisk command:

     sudo sfdisk /dev/sda < sda-backup.txt
    
  2. Confirm if the problem is resolved by running parted on your disk device:

     sudo parted /dev/sda unit s print
    
  3. If step 9 confirm that the partition table is fixed, you can then use GParted or other partition editors with the device.


The GParted documentition also suggests an alternative method, using testdisk to scan the disk device to rebuild the partition table. The testdisk application is included on GParted Live. So if you are not comfortable with the command-line way, you can try the alternative.

source


Using Gparted

unmount your swap partition before continuing
  1. current state

enter image description here

  1. resize the root partition

enter image description here

  1. root partition before resize

enter image description here

  1. root partition after resize

enter image description here

  1. created empty space after root partition

enter image description here

  1. deleting swap

enter image description here

  1. delaeting logical partition

enter image description here

  1. all partitions removed except root

enter image description here

  1. create new logical partition

enter image description here

  1. leave some free space before partition (so it doesn't overlap) and select partition type as Extended partition

enter image description here

  1. this is how it should look now

enter image description here

  1. create swap partition

enter image description here

  1. leave some free space after partition so it doesn't exceed and select filesysytem as linux swap

enter image description here

  1. this is how it should look now

enter image description here

  1. copy the UUID of your new swap and replace it in your /etc/fstab

enter image description here


9
  • I will hereby flag this answer for Need of moderation - deletion. IMHO, please note we do not support directly nor indirectly copy-pasting of someone else's hard work. Nov 27, 2021 at 10:11
  • 2
    @roaima i was in mid of editing {already stated} and that's why whole answer was in quote to let anyone know that this answer has been take from other questions; i have not directly copied but anyway i have stated the source as per the rules
    – Madhubala
    Nov 27, 2021 at 10:13
  • @Madhubala What you could have done is commenting with the link of such answer. That would have been proper course of action for me personally. Nov 27, 2021 at 10:16
  • @LinuxSecurityFreak yeah you are correct but since the calculation part can't be written in comments {it did cost me time in that} i thought it would be good to write it as an answer ; anyway what should be i do - delete the answer ?
    – Madhubala
    Nov 27, 2021 at 10:24
  • You've quoted your reference now, thank you +1 for the extra customisation Nov 27, 2021 at 10:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .