1 (edited by figure002 2012-02-26 12:58:27)

Topic: [SOLVED] Can't have overlapping partitions

Hello,

I recently changed some partitions on my harddisk. After that change GParted is no longer able to display the partition table. Instead it shows one single block with the text "unallocated". Double-clicking that block shows the error message: "Can't have overlapping partitions."

So how was this problem caused? At first my partition table looked something like this (square brackets = extended partition):

|-------------------[|------------------|-----------------------------------------------|---------|]
         linux               linux                            home                          swap

But I needed Windows for something, so I shrinked those two partition with Linux on them, in order to make extra room for a Windows partition. The result is as follows:

|-----------|-----------[|-----------|-----------------------------------------------|---------|]
    linux        win         linux                         home                          swap

I can successfully boot from both Linux partitions and the Windows partition, so no problems there. But as described above, I can no longer use GParted to view/edit the partition table. This is the fdisk output for my current partition table:

$ fdisk -l
omitting empty partition (5)

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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
Disk identifier: 0x94749474

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    43161599    21580768+  83  Linux
/dev/sda2   *    43161600    92618751    24728576    7  HPFS/NTFS/exFAT
/dev/sda3   *    92618752   624797695   266089472    f  W95 Ext'd (LBA)
/dev/sda4       123636303   620584959   248474328+  83  Linux
/dev/sda5        92620800   123633663    15506432   83  Linux
/dev/sda6       620587008   624795647     2104320   82  Linux swap / Solaris

I've searched the forums for solutions, and found several, but none explain how to actually do this (I'm not an advanced user). And I didn't find a clear explanation what exactly the problem is. Sure, some partition is overlapping another partition. But how's that even possible? How am I even able to boot from all three partitions without any problems?

One putative solution I found on the forum is to resize the offending partition. Another is to just remove the offending partition. But which is the offending partition? And how can I infer this from the fdisk output above? And what is the best solution, and what commands should I use to achieve this?

2

Re: [SOLVED] Can't have overlapping partitions

From this fdisk output, I see the following problem:

The primary partition /dev/sda4 is located within the extended partition /dev/sda3. This means that a primary partition uses part of the extended partition, that isn't allowable. Only logical partitions can use parts of an extended partition.
I really can't understand how this happened! I don't think GParted would make such partitions, unless it is any very old version. I suppose that you left the home and swap partitions unchanged.

Normally, the 4 primary partitions 1-4 can't overlap. The logical partitions 5,6,... must be all within the extended partition, preferably in order.
Some links with info related to the partitioning format according the MBR standard:
http://en.wikipedia.org/wiki/Master_boot_record
http://en.wikipedia.org/wiki/Disk_partitioning
http://en.wikipedia.org/wiki/Extended_Boot_Record

A secondary error, is the BOOT flag to the extended partition. Normally only the mswindows system partiiton needs a boot flag (older versions even wouldn't boot with 2 boot flags). However, this isn't critical error for late versions.

A third observation is that the partitions aren't aligned, but this isn't very important (it can be important for the SSD drives and the "advanced format" hard drives, and for older operating systems as well).

Now, what to do with this situation...  I don't know any software that would automatically arrange the partitions.
I remember we had a few similar situations in the forum. One of them was this one, but finally we had to reiinstall linux partitions.

(1) One solution can be to backup the content of the partitions /dev/sda4, 5 and 6, delete partitions /dev/sda3 to /dev/sda7, rebuild /dev/sda3, rebuild /dev/sda4 to 6 as logical /dev/sda5 to 7, and restore content. The bootloader needs to be reconfigured, as partition numbers are changed.
(2) Alternatively, you could backup the /home partition, reinstall the second linux installation and restore home.
(3) Another alternative would be to work with some hexadecimal editor on the master boot record, partition boot records and extended boot records to build a valid chain of logical partitions. I am not sure if this is possible, because I can't say if the space between partitions is enough for the extended boot records (I don't like to experiment on your system).
I think that the way (2) is easier that the others.

Any other idea on the problem is welcome!

*** It is highly recommended to backup any important files before doing resize/move operations. ***

3

Re: [SOLVED] Can't have overlapping partitions

figure002, what tools and what versions of tools did you originally use to change the partitions on the disk drive?

I agree with Class413 in that I am not aware of any tools which will automatically fix this problem.

4

Re: [SOLVED] Can't have overlapping partitions

Thanks for your replies.

class413:
Thank you for the clear explanation. You are right, I left the home and swap unchanged. I'm curious though, how can you tell that /dev/sda4 is located within the extended partition /dev/sda3 from the fdisk output? And it's really strange if it is, because /dev/sda4 has always been in the extended partition (I'm guessing as a logical partition); I just changed the size and moved it a bit (as described in the first post). Is it a primary partition because it has the number 4 (/dev/sda4)? Is there a way to change that number to something else (to make it a logical partition again)?

You gave me some possible solutions. Solution 2 is very simple and I can do that, but that means I have to reinstall everything all over again. I really don't want to do that, since I've configured quite a lot. I wouldn't even consider solution 3 since I've never worked with hex editors and it sounds very tricky. I was hoping for a solution similar to solution 1. But that involves deleting partitions. But I don't know how to delete partitions; I would normally use GParted for that. Could you point me in the right direction (which commands do I need for that)?

Would deleting /dev/sda4 solve the problem with GParted?

gedakc:
I used Parted Magic 6.0, a live CD with GParted 0.8.0 if I'm not mistaking. Are there manual ways to fix the problem?

5

Re: [SOLVED] Can't have overlapping partitions

You might try using fdisk to delete partitions 4, 5, and 5, and then recreate all of these as logical partitions 5, 6, and 7 with the exact same sector start and end and file system type.  The fdisk command only makes changes in memory until you decide to write the changes to the partition table.  Also it should not overwrite any of the data in the partitions if you are very careful to use exactly the same sector start and end values.

NOTE:  Be sure you know what your are doing if you attempt this path.  Also I highly recommend you make backups of your data in case something goes wrong.

6

Re: [SOLVED] Can't have overlapping partitions

I'm curious though, how can you tell that /dev/sda4 is located within the extended partition /dev/sda3 from the fdisk output?

To understand better, look at the table data in a slightly different form:

/dev/sda1        from sector 63    to sector 43,161,599
/dev/sda2        from sector 43,161,600    to sector 92,618,751

/dev/sda3        from sector 92,618,752    to sector 624,797,695 (this is the extended partition)

/dev/sda5        from sector 92,620,800    to sector 123,633,663
/dev/sda4        from sector 123,636,303    to sector 620,584,959
/dev/sda6        from sector 620,587,008    to sector 624,795,647

/dev/sda4 is a primary partition, because its number is 4 (Linux uses numbers 1-4 for the 4 partitions that are explicitely declared in the partition table).
Its position on the hard drive space is within the space of the extended partition.

And it's really strange if it is, because /dev/sda4 has always been in the extended partition (I'm guessing as a logical partition)

Logical partitions are a chain of partitions. In head of each one there is info for the actual partition and a "pointer" to the next one. So, the issue is related to the partition boot record structure, not just to the number. The system reads the record of the extended partition that points to the first logical partition only. It is named 5; the record of the partition 5 points to the start of another partition that is named 6, and so on, until no pointer to any next partition is found. The boot record of the extended partition (3 in this case) knows nothing about partitions 6 and further.
This is a very old scheme, heritage of the first IBM PC in the 1970s and still running on most of the personal computers on the Earth. Take into account that the initial scheme had a maximum of just 4 partitions; the extended partition was a complication to allow more than 4 partitions on a hard drive, keeping the compatibility with the previous system.


The solution decribed by gedack doesn't involve GParted and can avoid reinstallation if successful. Of course, a backup is the best idea, to be safe in case something goes wrong.

*** It is highly recommended to backup any important files before doing resize/move operations. ***

7

Re: [SOLVED] Can't have overlapping partitions

gedakc wrote:

You might try using fdisk to delete partitions 4, 5, and 6, and then recreate all of these as logical partitions 5, 6, and 7 with the exact same sector start and end and file system type.  The fdisk command only makes changes in memory until you decide to write the changes to the partition table.  Also it should not overwrite any of the data in the partitions if you are very careful to use exactly the same sector start and end values.

NOTE:  Be sure you know what your are doing if you attempt this path.  Also I highly recommend you make backups of your data in case something goes wrong.

That sounds like a good solution. It would indeed be great if it wouldn't overwrite any data provided I use the exact same sector position. I am new to fdisk, but I'll do some research before I actually attempt this. And I'll be sure to have backups of my data. Right now I'm in the middle of my final year of study and I can't afford to lose time reinstalling my system as I need this laptop. So I'll postpone any further steps until July when hopefully I've graduated. Of course I'll report back here.

class413 wrote:

To understand better, look at the table data in a slightly different form:
[...]

Thanks again for a great explanation. I have much better understanding of the problem now. I still don't understand how a logical partition became a primary partition (/dev/sda4), but that aside, at least I have an idea of how to fix this now. From your explanation I understand that MBR is a very old scheme; maybe next time I partition my harddisk I should consider a more modern partitioning scheme (e.g. GPT), if it's supported by GNU/Linux/gparted/Windows.

8 (edited by figure002 2012-02-26 02:48:52)

Re: [SOLVED] Can't have overlapping partitions

The issue with overlapping partitions has been causing a few annoyances. For example, automatic mounting of disks no longer works (USB sticks, external hard drives, CD-roms, etc.) and I am no longer able to write to some file systems (they are first mounted as read+write, but once I try to write data, the mount suddenly becomes read-only. So this is pretty annoying as I am no longer able to do many of the tasks I usually do. So today I've decided to backup all my data and execute gedakc's suggestion. I used the latest Parted Magic live CD. Here's the log:

root@PartedMagic:~# fdisk /dev/sda
omitting empty partition (5)

Command (m for help): d
Partition number (1-6): 4

Command (m for help): d
Partition number (1-6): 5

Command (m for help): d
Partition number (1-5): 5

Command (m for help): p

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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
Disk identifier: 0x94749474

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    43161599    21580768+  83  Linux
/dev/sda2   *    43161600    92618751    24728576    7  HPFS/NTFS/exFAT
/dev/sda3   *    92618752   624797695   266089472    f  W95 Ext'd (LBA)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First sector (92620800-624797695, default 92620800): 92620800
Last sector, +sectors or +size{K,M,G} (92620800-624797695, default 624797695): 123633663            

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First sector (123635712-624797695, default 123635712): 123636303
Last sector, +sectors or +size{K,M,G} (123636303-624797695, default 624797695): 620584959

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First sector (123635712-624797695, default 123635712): 620587008
Last sector, +sectors or +size{K,M,G} (620587008-624797695, default 624797695): 624795647

Command (m for help): p

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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
Disk identifier: 0x94749474

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    43161599    21580768+  83  Linux
/dev/sda2   *    43161600    92618751    24728576    7  HPFS/NTFS/exFAT
/dev/sda3   *    92618752   624797695   266089472    f  W95 Ext'd (LBA)
/dev/sda5        92620800   123633663    15506432   83  Linux
/dev/sda6       123636303   620584959   248474328+  83  Linux
/dev/sda7       620587008   624795647     2104320   83  Linux

Command (m for help): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap      c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      

Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): 82
Changed system type of partition 7 to 82 (Linux swap)

Command (m for help): p

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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
Disk identifier: 0x94749474

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    43161599    21580768+  83  Linux
/dev/sda2   *    43161600    92618751    24728576    7  HPFS/NTFS/exFAT
/dev/sda3   *    92618752   624797695   266089472    f  W95 Ext'd (LBA)
/dev/sda5        92620800   123633663    15506432   83  Linux
/dev/sda6       123636303   620584959   248474328+  83  Linux
/dev/sda7       620587008   624795647     2104320   82  Linux swap

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

I tried opening GParted again and success! I can now visualize my partition table again using GParted. I also tried accessing my data, and it is still intact! This is my first time working with fdisk and I'm very impressed. big_smile

Many thanks class413 and gedakc!

So the next step is to try and reboot into the operating systems. But I'll expect troubles with booting because, as class413 explained, "the bootloader needs to be reconfigured, as partition numbers are changed". I'm not sure how I'm going to do this, but I'll probably use one of the Ubuntu CD's to boot in rescue mode and reconfigure GRUB.

UPDATE:
Turns out that GRUB didn't need to be reconfigured! I could immediately boot in all three operating systems without a problem (all data still intact). Even the mounting problems caused by the overlapping partitions (as described in the beginning of this post) are gone. cool

(The only problem I still experience is that my MP3 player still goes from read+write to read-only. But I suspect that this is a file system error in the hard disk of the MP3 player itself.)

9

Re: [SOLVED] Can't have overlapping partitions

'Glad to hear you were successful in resolving the overlapping partitions problem.

To help others searching for answers to this problem, you can edit the initial post and prefix SOLVED in front of the title.