2

first the story: I moved my Windows partition "to the left", then were unable to (dual) boot Windows, tried the repair option on the Win8 CD ... and now seem to have more than 4 primary partitions. gparted now shows the whole disk unallocated "Can't have overlapping partitions".

Here's what the partition table looks like (viewed from live CD):

ubuntu@ubuntu:~$ sudo parted /dev/sda unit s print
Error: Can't have overlapping partitions.    

ubuntu@ubuntu:~$ sudo fdisk -l -u /dev/sda

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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: 0x000524e5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2046   134217727    67107841    5  Extended
/dev/sda2       134217728   150798335     8290304   82  Linux swap / Solaris
/dev/sda3   *   150798336   151515135      358400    7  HPFS/NTFS/exFAT
/dev/sda4   *   237004800   237721599      358400    7  HPFS/NTFS/exFAT
/dev/sda5       237721600   488394751   125336576    7  HPFS/NTFS/exFAT

/dev/sda1 is where my ext4 Linux partition used to be. I am aware of the answers at GParted shows "unallocated" on my sda drive (parallel boot with Win XP) and also read a lot more. I understand that I can only have 4 primary partitions and /dev/sda5 should be within an extended partition - causing the "overlapping" warning.

What I do not know: How do I solve the problem? I'd prefer to keep my old linux partition - but even if I did not, I can't just reinstall Ubuntu, because the disk is in an invalid state. And I am lucky that windows works fine on /dev/sda5 and would prefer not to remove this partition.

What I also do not understand: What are the two mini-partitions 3 and 4 good for? I assume that windows had created them as boot partitions or something like that ... so, can I remove one of them? Windows mounts the second one as D: and shows files like Temp\disklayout.txt including information on the disk like it used to be before the "repairs":

  Partition ###  Typ               Größe    Offset
  -------------  ----------------  -------  -------
  Partition 0    Erweitert           63 GB  1023 KB
  Partition 4    Logisch             63 GB  1024 KB
  Partition 1    Primär            8096 MB    64 GB
  Partition 2    Primär             350 MB   113 GB
  Partition 3    Primär             119 GB   113 GB

Thanks a lot for helpful directions!

Update 1

I tried to get rid of the superfluous partition using sfdisk and writing a modified table to the disk. And when the last partition showed up twice, I used fdisk to remove that one. The result looked good.

/dev/sda1 : start=     2046, size=134215682, Id= 5
/dev/sda2 : start=134217728, size= 16580608, Id=82
/dev/sda3 : start=237004800, size=   716800, Id= 7, bootable
/dev/sda4 : start=237721600, size=250673152, Id= 7

When I then did a try with fixparts, it's analysis is ... irritating:

MBR command (? for help): p

** NOTE: Partition numbers do NOT indicate final primary/logical status,
** unlike in most MBR partitioning tools!

** Extended partitions are not displayed, but will be generated as required.

Disk size is 488397168 sectors (232.9 GiB)
MBR disk identifier: 0x000524E5
MBR partitions:

                                                   Can Be   Can Be
Number  Boot  Start Sector   End Sector   Status   Logical  Primary   Code
   2             134217728    150798335   logical     Y        Y      0x82
   3      *      237004800    237721599   logical     Y        Y      0x07
   4             237721600    488394751   primary              Y      0x07

Although sfdisk displays the first partition, fixparts won't.

Update 2

Well, well. I wasn't so lucky with fixparts, but testdisk did the trick. Not alone, but the critical part. Here's what helped for me (I'm writing from the once-lost Ubuntu, jippi) - may be helpful for someone else.

A warning in advance: I never thought that messing around with parition tables was so much fun! But probably don't do that (without a full disk backup), if have have important data on the disk.

  • The first part would probably been easier just using fdisk /dev/sda to delete the superfluous partition.
    • Downloaded the partition table via fsdisk -d /dev/sda > SomeUSBFile
    • Manually removed the superfluos partition from this file (and changed the numbers of the remaining partitions accordingly)
    • Written the modified partition table via fsdisk /dev/sda < SomeUSBFile
    • Deleted the last partition, that now was displayed two times via fdisk
  • The Linux partition was still missing, so I ran testdisk from the Ubuntu live USB stick. It found that there actually is no extended partition, but a primary linux partition instead. But it did not see the Windows 10 partitition.
    • So I, again, wrote the partition table to a file fsdisk -d /dev/sda > SomeUSBFile
    • let testdisk write the new partition table (the one, it found after searching for partitions),
    • exported this partition table to another file,
    • copied the line of the linux partition, and
    • inserted this line into the original partition table's file to
    • import this modified version via fsdisk /dev/sda < SomeUSBFile.
  • Windows still run :)
  • The ubuntu live-USB then allowed to mount the linux partition (which is strange, as I had enabled encryption during the linux installation...), and install a new grub MBR to /dev/sda (http://howtoubuntu.org/how-to-repair-restore-reinstall-grub-2-with-a-ubuntu-live-cd)
  • Finally, the swap partition (the old one was now "unknown" in gparted) has to be recreated in gparted.
BurninLeo
  • 186

1 Answers1

1

My FixParts utility (part of the gdisk package in Ubuntu) might be able to fix the problem; however, I can't promise that -- the fact that your logical partition resides entirely outside the space allocated to the extended partition might throw it for a loop. (That problem is extremely rare, and I don't recall enough details of how FixParts reads MBR partition tables to predict how it will react.) You can try running FixParts on the disk and view the partition table to see if it can detect your partitions without risk -- it won't save the partition table until you tell it to do so (via the w option).

If FixParts flakes out on the disk, there are at least three other options:

  • Using fdisk or some other tool, delete some or all of your partitions and then re-create them. The output you've already shown provides everything you need -- the start and end points (in sectors) and partition type codes.
  • Delete all your partitions and then use TestDisk to recover a valid partition table. This approach is normally one of last resort, and it sometimes fails, but it may be helpful if you have problems with the preceding approach.
  • Back up all your partitions' contents, erase the partition table, create new partitions, and restore your partitions' contents. This is a major undertaking and you may encounter problems getting everything to boot again, so I'd do it only as a last resort. Backing up before trying other approaches is advisable, though.

As oldfred says, the Windows partitioning tool is unreliable when working with MBR partition tables that contain extended and logical partitions. I recommend avoiding it if at all possible.

Rod Smith
  • 45,120
  • 7
  • 66
  • 108