I have accidentally deleted two hfs+ partitions. I know start and end sectors of both of them. These partitions are 100% healthy. I can see them in Raise Data Recovery, but testdisk does not see them. How can I edit manually the mbr to restore these partitions from ubuntu or windows?

The "sfdisk -l" command in ubuntu terminal shows:

Disk /dev/sda: 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.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1         12+  12747-  12736- 102294528    7  HPFS/NTFS
/dev/sda2      12747+  48643-  35896- 288328704    f  W95 Ext'd (LBA)
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty
/dev/sda5      12748+  43870   31123- 249995466    7  HPFS/NTFS
/dev/sda6      43871+  48144-   4274-  34324480   83  Linux
/dev/sda7      48145+  48643-    499-   4001792   82  Linux swap / Solaris

Where sda3 and sda4 are these partitions.

link|improve this question
actually, the data presented here is a bit odd. Unless, ofcourse, the size of sda3 and sda4 is really less than 8MiB? – XXL Jan 9 at 21:39
sda3 and sda4 physically were located at the end of the disk. Something like this: sda1, sda2 start, sda 5, sda 6, sda 7, sda2 end, sda3, sda4. – nik Jan 11 at 14:29
feedback

3 Answers

up vote 0 down vote accepted

Perhaps, first try this:

apt-get install -y parted (in case of Debian-based distro)

partprobe

parted /dev/sda
u s (switches units to sectors)
p (prints partition table)
mkpart p start end (p - primary, this should be your sda3)
mkpart p start end (should be sda4)

I'd run partprobe again after that's done. If it does not work - then yeah, would need to edit the MBR manually, I guess.

Edit: one thing that occurred to me is that you might run into issues, when parted is complaining about injecting partitions with such "out of spec" boundaries.. Well, just delete everything starting from sda5 and recreate them the same way after the successful addition of sda3 & sda4.

link|improve this answer
Ok, that is my question, how do I edit it? From which tool? – nik Jan 9 at 20:26
So, what, parted did not work or.. ? – XXL Jan 9 at 21:02
@nik Parted is a partition table editor, it is the best tool for editing partitions. – Paul Jan 9 at 23:14
feedback

You can use sfdisk to add those empty partition, for example

sfdisk /dev/sda << EOF
0,381230,0c
381231,84481,0b
465712,,S
EOF

Each line has three values the start and the end sector and the third value is the partition type. To use this console mode you need to install a special package. But I don't know if this delete the partition content. I suggest to make a copy with dd.

link|improve this answer
feedback

I tried to make partitions with parted, but it makes hfs+ partitions of some linux type, anyway it is not the same partition type like the disk utility of os x makes. And the boot manager does not see them like mac partitions, but like linux partitions and does not boot from them. I have backed up the important data, but now I need to do a lot of work, to install all the stuff, that was installed.

link|improve this answer
You can deliberately specify the filesystem type with parted: mkpart p hfs+ start end. Or are we already on the same page and you specified that when creating, but it still turned out to be incompatible? This parameter is optional and by default type 83 is created (Linux). – XXL Jan 13 at 18:30
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.