# HDD partition table chaos.

## dE_logics

I'm somehow found the root cause of many of people's problems which I see around the Internet and they have no solution.

For e.g. If I make an extended partition with 3 logical partitions in it, then I delete the first partition and create 2 or more partitions instead... what do I get? "Partition table are not in order.".

Ok, this can be fixed using testdisk (DO NOT do it with fdisk otherwise things will turn chaos), but this time it did not work....

Testdisk failed to detect the Linux partition (83), and writing the new MBR to the disk removed them.

So my question is, is there anyway to manually 'rename' the devices (/dev/sdb1, /dev/sdb3 etc...) so as to make then 'in order' without using testdisk (since it did not work this time). That's why LVM rocks.

These MBR things are getting a bit too hectic so I've also decided to peep into the core of the matter. Where do get a complete tutorial, book etc... about all these things?... MBR, blocks, sectors clusters... all in a bit detail?

----------

## eccerr0r

The partition ordering warning is just a warning I thought, it doesn't matter if it's out of order.

A lot of my disks I deliberately made partitions out of order, usually /dev/sda1 is root, /dev/sda2 is boot, and /dev/sda3 is swap -- but boot is on the outside tracks (legacy/1024 cylinder issues kept small not to waste prime space), swap is next (in prime fastest portion of disk space), then root is the rest (of the slower portion of the disk).

Works just fine... and to the bootloader, or any other piece of software wanting to access the disk, /dev/sda1 -- number 1 -- contains the most important partition of the disk...the data.

```
Disk /dev/sda: 40.0 GB, 40019582464 bytes

255 heads, 63 sectors/track, 4865 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0xeb21eb21

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *          64        4865    38572065   83  Linux

/dev/sda2               1          63      506016   82  Linux swap / Solaris

Partition table entries are not in disk order

```

Is it really causing issues or just triggering the warning?

----------

## frostschutz

Use cfdisk or sfdisk or parted. Anything but fdisk.

----------

## dE_logics

It causes major Windows issues... it just wont boot... it tries to see what's in the HDD, and it just hangs (with 100% HDD usage), I suspect this is case the partitions are not in order.

I've even backed up the MBR (actually the first 5 MB), to analyze that.

----------

## dE_logics

Any reference to some books or something?

----------

## frostschutz

You can use sfdisk -d /dev/yourdisk > file

Might look like this

```
# partition table of /dev/sdd

unit: sectors

/dev/sdd1 : start=       62, size=  1046746, Id=83, bootable

/dev/sdd2 : start=        0, size=        0, Id= 0

/dev/sdd3 : start=  1046808, size= 14905296, Id= 5

/dev/sdd4 : start=        0, size=        0, Id= 0

/dev/sdd5 : start=  4359158, size=  2265418, Id=83

/dev/sdd6 : start=  1046870, size=  1656082, Id=83

/dev/sdd7 : start=  2703014, size=  1656082, Id=83

/dev/sdd8 : start=  7108982, size=  8843122, Id=83

/dev/sdd9 : start=  6624638, size=   484282, Id=83

```

Then you edit that and reorder it to anything you want.

Just change the order and sdx numbers, not the start / size / id.

Also do NOT exchange primary for logical partitions.

```
# partition table of /dev/sdd

unit: sectors

/dev/sdd1 : start=       62, size=  1046746, Id=83, bootable

/dev/sdd2 : start=  1046808, size= 14905296, Id= 5

/dev/sdd3 : start=        0, size=        0, Id= 0

/dev/sdd4 : start=        0, size=        0, Id= 0

/dev/sdd5 : start=  1046870, size=  1656082, Id=83

/dev/sdd6 : start=  2703014, size=  1656082, Id=83

/dev/sdd7 : start=  4359158, size=  2265418, Id=83

/dev/sdd8 : start=  6624638, size=   484282, Id=83

/dev/sdd9 : start=  7108982, size=  8843122, Id=83

```

Then you restore it:

sfdisk /dev/yourdisk < file

Be aware that you may mess up your partition table by doing so

don't try this without backup

----------

## Jaglover

Why not use fdisk? fdisk can correct partition order in expert mode, takes just a few keystrokes. What you people have against fdisk? It never failed for me.

----------

## eccerr0r

As another possibility, IIRC Windows XP boot CD partitioner automatically "fixes" it for you...  At least I remember something like that happening when I tried installing Windows after Linux...  There was something that "fixed" my partition order after manually selecting it to be such...

----------

## Jaglover

I think it is possible partition tables created by Linux (or other FOSS) fdisk may not be always readable by Windows due to more advanced disk handling. Haven't installed Windows in many years, but I remember cases when Windows was unable to recognize drives pre-partitioned using non-DOS utilities.

----------

## eccerr0r

It does complain about "Non-DOS partition" but I do recall it reordering the partition table for me, without my consent.  It doesn't need to know what each partition descriptor byte means, just needs to make sure each entry in the table in disk order...

----------

## dE_logics

That sfdisk method is surely a risky and error-vulnerable method, anyway I'll try it soon.

As of fdisk.... no never again, it done nothing but chaos... I had enough of that.

----------

## dE_logics

sfdisk is talking crap! It says - 

```
# partition table of /dev/sdb

unit: sectors

/dev/sdb1 : start=       63, size=  1943802, Id= 5

/dev/sdb2 : start=        0, size=        0, Id= 0

/dev/sdb3 : start=        0, size=        0, Id= 0

/dev/sdb4 : start=        0, size=        0, Id= 0

/dev/sdb5 : start=      126, size=   208719, Id=83

/dev/sdb6 : start=   208908, size=   417627, Id=83

/dev/sdb7 : start=   626598, size=   112392, Id= b

/dev/sdb8 : start=   739053, size=   144522, Id=82

/dev/sdb9 : start=   883638, size=   626472, Id=83

/dev/sdb10: start=  1510173, size=   208782, Id=83

/dev/sdb11: start=  1719018, size=   224847, Id=83

```

Where as fdisk and everything else says - 

```
/dev/sdc1               1         121      971901    5  Extended

/dev/sdc5               1          13      104359+  83  Linux

/dev/sdc6              14          39      208813+  83  Linux

/dev/sdc7              40          46       56196    b  W95 FAT32

/dev/sdc8              47          55       72261   82  Linux swap / Solaris

/dev/sdc9              56          94      313236   83  Linux

/dev/sdc10             95         107      104391   83  Linux

/dev/sdc11            108         121      112423+  83  Linux
```

----------

## snilsson

 *dE_logics wrote:*   

> sfdisk is talking crap! It says - 
> 
> ```
> # partition table of /dev/sdb
> 
> ...

 

Except from listing two different drives is shows more or less the same information.

sfdisk lists size as sectors, and it show the empty (not used) primary partitions as well.

Try using fdisk with sectors as unit and the only difference is that sfdisk show size where fdisk show end sector.

```
# sfdisk -d /dev/sde

# partition table of /dev/sde

unit: sectors

/dev/sde1 : start=       56, size=1953514696, Id=83

/dev/sde2 : start=        0, size=        0, Id= 0

/dev/sde3 : start=        0, size=        0, Id= 0

/dev/sde4 : start=        0, size=        0, Id= 0

# fdisk -l -u /dev/sde

Disk /dev/sde: 1000.2 GB, 1000204886016 bytes

224 heads, 56 sectors/track, 155733 cylinders, total 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

Disk identifier: 0xb679465c

   Device Boot      Start         End      Blocks   Id  System

/dev/sde1              56  1953514751   976757348   83  Linux

```

----------

## dE_logics

Oh, ok. Thanks.

----------

## dE_logics

Ok, it worked. thanks.

----------

