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
  • 2
  • 10
  • 2
    By definition a sda5 must be inside the extended partition as it is a logical partition. And you can only have one boot flag on a primary NTFS partition for Windows to boot from. Not sure how you managed to get this configuration. It almost looks like you copied sda3 into sda4?? And the Linux partition inside sda1 was lost as Windows tools often rewrite partition table without the Linux logical partition. Do not use Windows except to shrink or increase NTFS partitions, or you will have issues. Can you tell if sda4 is a copy of sda3, that may determine what to do. If you can backup do that. – oldfred Apr 04 '16 at 19:50
  • Thank you. Yes, I am aware that sda3 and sda4 are - uum - not perfect. They have probably not exactly the same content (at least one is mounted and refers to the "old" configuration, see edits to my posting). – BurninLeo Apr 04 '16 at 20:12
  • Okay ... another idea: Can I somewhat disable a partition temporarily and see if that helps? I thought of removing if from the partition table via ubuntu live CD but re-enter it, if everything breaks down. I did not ever do something like this, therefore comments would be apprechiated. – BurninLeo Apr 04 '16 at 20:39
  • Do this first. Then at least you can restore to current, but invalid state: First backup partition table, use your drive for sdX or sda, sdb etc. sudo sfdisk -d /dev/sdX >parts_ parts.txt or sudo sfdisk -d /dev/sda > parts_sda.txt Then see what testdisk and/or fixparts show. – oldfred Apr 04 '16 at 21:14
  • An extended partition type 5 is not a real partition or it is a container for logical partitions (kinda). see sudo sfdisk -T. You need to change 5 to 83, then fixparts may see it. Start also then should be 2048. As extended needed 2 sectors before first partition inside it. You may be able to use testdisk also to recover partition. – oldfred Apr 08 '16 at 19:50
  • Okay ... I did not think so far that the first partition may not be extended, but only had a wrong type number. That was probably the best guess that the Windows repair could make for a linux partition. But this looked so sound to me, that I did not consider it. Would have solve the problem faster, probably. Thank you! – BurninLeo Apr 08 '16 at 21:59
  • Your sfdisk effort to delete a "superfluous" partition actually deleted an important partition. When you ran fixparts, it showed the modified partition table without showing the extended partition. You'd have been better off at least trying with fixparts before adjusting the partition table with other tools. I can't promise it would have worked, but it might have done so. – Rod Smith Apr 09 '16 at 14:16
  • I am quite sure, the partition, I deleted, was not important. It was rather an old boot partition of Windows - and Windows had created a new one during my initial repair efforts. Using fixparts first would probably been more sensible -- if I had the idea to change the assumes-extended partition to type 83 in time... – BurninLeo Apr 10 '16 at 11:39

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
  • 44,284
  • 7
  • 63
  • 105
  • Before killing my whole disk, maybe you could give me some directions for MBR beginners: I do not fully understand the fixparts output (see update in my original question). It would be great help, if you could explain me the inconsistency between sfdisk and fixparts. – BurninLeo Apr 08 '16 at 19:10
  • 1
    Sfdisk shows extended partition. Fixparts automatically creates or changes extended partition, so no need to show it. Both are correct. Issue is extended partition, should be a primary Linux partition. And you then have the standard 4 primary partition limit issue which fixparts can help you with. http://askubuntu.com/questions/149821/my-laptop-already-has-4-primary-partitions-how-can-i-install-ubuntu – oldfred Apr 08 '16 at 21:11
  • Your answer gave me the right direction to solve the problem. I never thought I could work on the partition table without killing the whole system - now I am really happy! Thanks, again. – BurninLeo Apr 08 '16 at 22:01