1

Knowing that my external 320 GB hard drive has some problem with the connector, whenever I intend to copy something to it I first create a backup of the MBR and the partition table this way (Ubuntu 9.04):

$ sudo dd if=/dev/sdc of=HDD_mbr_20100208 count=1 bs=512  
$ sudo cfdisk /dev/sdc

Then in cfdisk I choose the Print option and then the Raw option which saves the partition table in the very same format it would have been written to disk.

Now I need to recover what I have saved. The MBR part is really simple (just change the if and the of part in the first command), but there is no an obvious way to recover the partition table in cfdisk. Do you know how?

I would also appreciate any suggestion on a better way to save MBR, partition table and FATs (volume is FAT32 formatted).

Thanks in advance.

Sergio.

2 Answers 2

1

Depending on your partition layout, your MBR restoration (dd if=HDD_mbr_20100208 of=/dev/sdc...) may have already done it all. This is because the MBR and primary partition table is stored in the first 512-byte sector of the drive. For this to work, your drive:

  • must use MBR-style partitions,
  • must have no more than 4 primary partitions, AND
  • must have no extended or logical partitions.

If you have an extended partition and enclosed logical partitions, you may need to translate your cfdisk-created partition table backup. I don't know of any way to easily tell fdisk or cfdisk what new partition table to write -- sfdisk can do this easily, but the cfdisk raw format is not the same as what sfdisk reads and writes. You can probably translate one format to the other manually.

cfdisk's raw output is formatted in one of these two ways (source: man cfdisk):

The raw data format will print the sectors that would be written to disk if a write command is selected. First, the primary partition table is printed, followed by the partition tables associated with each logical partition. The data is printed in hex byte by byte with 16 bytes per line.

...

The partition table in raw format will print the partition table ordered by partition number. It will leave out all free and unusable space. The fields, from left to right, are the number of the partition, the flags (in hex), the starting head, sector and cylinder, the filesystem ID (in hex), the ending head, sector and cylinder, the starting sector in the partition and the number of sectors in the partition. The information in this table can be directly translated to the raw data format.

1
  • note: it's nearly guaranteed you're using MBR partitions, because the fdisk tools don't support GPT/GUID partitions. still, the restriction is important, so i want to be clear. Feb 9, 2010 at 0:32
0

For the backup part, here are some examples. I personally use sfdisk to backup/restore partition tables.

If you have destroyed the partition table, but did not overwrite the data, you can use TestDisk to try to restore the partition table.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .