Publié le

I really dislike automated partitions tools, when they do something bad, the sysadmin will lost a lot of time in the troubleshooting process, for example this bad work by debian intaller partition tool:

#####################################################################
root@ts209:~# cfdisk /dev/sda
FATAL ERROR: Bad logical partition 6: enlarged logical partitions overlap
#####################################################################

This is the partition table:
#####################################################################
root@ts209:~# sfdisk -d /dev/sda
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 2048, size= 497664, Id=83, bootable
/dev/sda2 : start= 0, size= 0, Id= 0
/dev/sda3 : start= 501758, size=976269314, Id= 5
/dev/sda4 : start= 0, size= 0, Id= 0
/dev/sda5 : start= 14174208, size= 1492992, Id=82
/dev/sda6 : start= 501760, size= 13672448, Id=fd
/dev/sda7 : start= 15669248, size=961101824, Id=fd
#####################################################################

And when I try to dumb this table from one disk to another, doesn’t work:
#####################################################################
root@ts209:~# sfdisk -d /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now …
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
OK

Disk /dev/sdb: 60801 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 22 does not have an msdos signature
/dev/sdb: unrecognized partition table type
Old situation:
No partitions found
Warning: given size (0) exceeds max allowable size (961101824)

sfdisk: bad input
#####################################################################

Where is the problem? is more clear when you use gparted:
#####################################################################
root@ts209:~# parted /dev/sda u s print free
Model: ATA Hitachi HDP72505 (scsi)
Disk /dev/sda: 976773168s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
63s 2047s 1985s Free Space
1 2048s 499711s 497664s primary ext2 boot
499712s 501757s 2046s Free Space
3 501758s 976771071s 976269314s extended
6 501760s 14174207s 13672448s logical raid
5 14174208s 15667199s 1492992s logical linux-swap(v1)
7 15669248s 976771071s 961101824s logical raid
976771072s 976773167s 2096s Free Space
#####################################################################

The partition order is 1, 3, 6, 5, 7

The problem with sfdisk:
#####################################################################
/dev/sda5 : start= 14174208, size= 1492992, Id=82
/dev/sda6 : start= 501760, size= 13672448, Id=fd
#####################################################################

for sfdisk this isn’t logic because 14174208 > 501760

This is the workaround:
#####################################################################
root@ts209:~# sfdisk -d /dev/sda > partitions.sfdisk-hack
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
#####################################################################

Edit partitions.sfdisk-hack whit your favorite editor and swap both lines with the problem.
#####################################################################
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 2048, size= 497664, Id=83, bootable
/dev/sda2 : start= 0, size= 0, Id= 0
/dev/sda3 : start= 501758, size=976269314, Id= 5
/dev/sda4 : start= 0, size= 0, Id= 0
/dev/sda6 : start= 501760, size= 13672448, Id=fd
/dev/sda5 : start= 14174208, size= 1492992, Id=82
/dev/sda7 : start= 15669248, size=961101824, Id=fd
#####################################################################

Then put it in the /dev/sdb disk:
#####################################################################
root@ts209:~# sfdisk /dev/sdb < partitions.sfdisk-hack
Checking that no-one is using this disk right now …
OK

Disk /dev/sdb: 60801 cylinders, 255 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Old situation:
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/sdb1 * 0+ 31- 31- 248832 83 Linux
/dev/sdb2 0 – 0 0 0 Empty
/dev/sdb3 31+ 60801- 60770- 488134657 5 Extended
/dev/sdb4 0 – 0 0 0 Empty
/dev/sdb5 31+ 882- 852- 6836224 fd Linux raid autodetect
/dev/sdb6 882+ 975- 93- 746495+ 82 Linux swap / Solaris
/dev/sdb7 975+ 60801- 59826- 480550912 fd Linux raid autodetect
New situation:
Units = sectors of 512 bytes, counting from 0

Device Boot Start End #sectors Id System
/dev/sdb1 * 2048 499711 497664 83 Linux
/dev/sdb2 0 – 0 0 Empty
/dev/sdb3 501758 976771071 976269314 5 Extended
/dev/sdb4 0 – 0 0 Empty
/dev/sdb5 501760 14174207 13672448 fd Linux raid autodetect
/dev/sdb6 14174209 15667199 1492991 82 Linux swap / Solaris
/dev/sdb7 15669248 976771071 961101824 fd Linux raid autodetect
Warning: partition 1 does not end at a cylinder boundary
Warning: partition 3 does not start at a cylinder boundary
Warning: partition 3 does not end at a cylinder boundary
Warning: partition 5 does not end at a cylinder boundary
Warning: partition [6] does not start at a cylinder boundary
Warning: partition [6] does not end at a cylinder boundary
Warning: partition 6 does not end at a cylinder boundary
Warning: partition [7] does not start at a cylinder boundary
Warning: partition [7] does not end at a cylinder boundary
Warning: partition 7 does not end at a cylinder boundary
Successfully wrote the new partition table

Re-reading the partition table …

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
#####################################################################

And we got:
#####################################################################
root@ts209:~# sfdisk -d /dev/sdb
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
# partition table of /dev/sdb
unit: sectors

/dev/sdb1 : start= 2048, size= 497664, Id=83, bootable
/dev/sdb2 : start= 0, size= 0, Id= 0
/dev/sdb3 : start= 501758, size=976269314, Id= 5
/dev/sdb4 : start= 0, size= 0, Id= 0
/dev/sdb5 : start= 501760, size= 13672448, Id=fd
/dev/sdb6 : start= 14174209, size= 1492991, Id=82
/dev/sdb7 : start= 15669248, size=961101824, Id=fd
#####################################################################

Warning: This doesn't have the same schema that our original:
* sba6 is equivalent to sda5
* sdb5 is equivalent to sda6

Is not perfect but better that nothing :P

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s