Regénérer une table de partitions3 min read

Symptômes: carte SD noname (d’un ami) qui

  • cesse subitement de fonctionner pendant l’écriture ou la lecture d’un fichier
  • se fait soudainement remonter en lecture seule par Linux
  • n’est plus reconnue (ne se mount plus du tout) si on l’éjecte et la réinjecte

Bon, l’idéal est de faire un backup pendant qu’elle est montée read-only et qu’en en a encore la chance, mais sinon, si on se retrouve comme dans ma situation avec des partitions intactes (vues par gparted et palimpset), ben c’est peut-être une table de partitions bousillée (du moins c’est mon hypothèse).
J’ai utilisé export LANG=C, puis fdisk pour voir ce qui se passait:
jeff@kagami:~$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 33.6 GB, 33553907712 bytes
4 heads, 16 sectors/track, 1023984 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk identifier: 0x73696420
This doesn't look like a partition table
Probably you selected the wrong device.
Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   ?    30254481    97205095  2142419640+  45  Unknown
Partition 1 does not end on cylinder boundary.
/dev/mmcblk0p2   ?    28955778    58172676   934940722+  65  Novell Netware 386
Partition 2 does not end on cylinder boundary.
/dev/mmcblk0p3   ?    26593410    52133516   817283378   20  Unknown
Partition 3 does not end on cylinder boundary.
/dev/mmcblk0p4   ?    45088769    45089595       26464    d  Unknown
Partition 4 does not end on cylinder boundary.
Partition table entries are not in disk order

Houlà. Après avoir cherché “does not end on cylinder boundary.” sur Google, j’ai fini par tomber sur un commentaire dans un post obscur de forum, qui indiquait une procédure intéressante. J’ai fait comme il a suggéré, et… ça a marché.
jeff@kagami:~$ sudo fdisk /dev/mmcblk0
The number of cylinders for this disk is set to 1023984.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): x
Expert command (m for help): f
Done.
Expert command (m for help): v
Partition 1 does not end on cylinder boundary.
Partition 1: head 113 greater than maximum 4
Partition 1: sector 111 greater than maximum 16
Partition 2 does not end on cylinder boundary.
Partition 2: head 116 greater than maximum 4
Partition 2: sector 115 greater than maximum 16
Warning: partition 1 overlaps partition 2.
Partition 3 does not end on cylinder boundary.
Partition 3: head 115 greater than maximum 4
Partition 3: sector 114 greater than maximum 16
Warning: partition 1 overlaps partition 3.
Warning: partition 2 overlaps partition 3.
Partition 4 does not end on cylinder boundary.
Partition 4: head 11 greater than maximum 4
Partition 4: sector 0 greater than maximum 16
Warning: partition 1 overlaps partition 4.
Warning: partition 2 overlaps partition 4.
Warning: partition 3 overlaps partition 4.
Total allocated sectors 3118783728 greater than the maximum 65534976
Expert command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
jeff@kagami:~$

Légende des commandes interactives:

  • x  = expert mode
  • f = fix partition order
  • v = verify partition
  • w = to write partition table to disk

Et bam. La carte SD s’est remise à fonctionner normalement, et à être montée en écriture lors du branchement. Bon, j’ai quand même pris soin d’indiquer à Vince que cette carte SD noname est très douteuse et qu’il faut pas trop s’y fier maintenant…


Comments

2 responses to “Regénérer une table de partitions3 min read

  1. Sous Debian (et probablement sur d’autres distribs) tu as un utilitaire du nom de gpart qui « devine » la table de partition de tes disques après un souci. Je l’ai déjà utilisé plusieurs fois suite à des déplacements ou des redimensionnements de partitions foireux.

  2. J’aurais plutôt créé une nouvelle tables de partitions personnellement…