Categories
Technical

Recovering a deleted MBR partition table (ext2/ext3)

This post is originally from April 2007 and never got published. Here’s hoping I’ll never have to use it again. ~paws

Take a deep breath and relax. This is not bad luck. This is God’s retribution for your failure to back up your data. You are a bad person and you deserve this. Fortunately, there is a way for you to spite the will of God and recover your data anyway. Unfortunately, acts of contempt in this class usually require nerves of steel, and this stunt is no exception. Here is what you do:
Make a partition that is at least as big as your first partition was. You can make it larger than the original partition by any amount. If you underestimate, there will be much wailing and gnashing of teeth.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-23361, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-22800, default 22800): 13032

Command (m for help): w

Run dumpe2fs on the first partition and grep out the block count
Example:

% dumpe2fs /dev/sda1 | grep “Block count:”
Block count: 41270953

If you are uncertain about this value, repeat Step 1 with a bigger partition size. If the block count changes, then you underestimated the size of the original partition when you made your first guess. Repeat Step 1 until you get a stable block count.

Remove the partition you just created
Command (m for help): d
Partition number (1-4): 1

Make a new partition with the exact size you got from the block count. Since you cannot enter block size in fdisk, you need to figure out how many cylinders to request. Here is the formula:

(number of needed cylinders) = (number of blocks) / (block size)

(block size) = (unit size) / 1024

(unit size) = (number of heads) * (number of sectors/cylinder) * (number of bytes/sector)

Consider the following example, where a hard drive has been partitioned into four primary partitions of 1, 2, 4, and 8 cylinders.
disk /dev/sda: 16 heads, 63 sectors, 23361 cylinders
Units = cylinders of 1008 * 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 2 976+ 83 Linux
/dev/sda2 3 5 1512 83 Linux
/dev/sda3 6 10 2520 83 Linux
/dev/sda4 11 19 4536 83 Linux
fdisk provides the configuration information I need in the head of the output.

The unit size is 516096 ( 16 heads * 63 sectors/cyl * 512 bytes/sector ).

The block size is 504 ( 516096 / 1024 ).

The number of needed cylinders for the second partition is therefore 3 ( 1512 blocks / 504 ).

The partition table shows that this is indeed the case: the first cylinder is 3, the second 4, and the last is 5, for a total of three cylinders.

The number of needed cylinders for the third partition is calculated similarly: 2520 blocks / 504 = 5, which corresponds to 10 – 6 (plus one, since we are counting the 6th through the 10th cylinders inclusively).

Notice that this calculation does not work for the first partition because the block count is wrong ( 976 instead of 1008 ). The plus sign indicates that not all the blocks are included in the fdisk value. When you try the calculation ( 976 / 504 ) you get 1.937. Knowing that the number of cylinders must be an integer, you can simply round up.

Run e2fsck on it to verify that you can read the new partition.

Repeat Steps 1-5 on remaining partitions.

Remount your partitions. Amazingly, all of your data will be there.

Credit for thinking of this strategy goes to Mike Vevea, jedi sys admin and MGH’s finest.

Categories
General

Fixing Disk Utility image restore

For some reason, restoring a DMG image to a block device has been an atypically frustrating experience under Mac OS X (since Leopard – 2007). Apple Disk Utility comes back with user unfriendly errors citing an ‘invalid argument’. It insists on doing some silly ‘image scan’ which never actually works, thereby blocking any successful image restore. Delving deeper I thought it was likely some other component utilized by Disk Utility was failing and I found what it was.

It turns out that Disk Utility employs Apple’s ASR utility, stored at

/usr/sbin/asr

To learn more you can run ‘asr’ by itself in Terminal. While

man asr

shows a lot more, I’ll save you from reading that (this man page has even got a History section).

Simply restore without an image scan:

$ sudo asr -noverify -source source -target target
Categories
General

AT&T spoils the party, again

In June 2008, AT&T spoiled the iPhone party by increasing the monthly data rate from $25 to $30 per month. In addition, text messaging, a service of minimal cost to providers was a minimum of $5 a month for 200 texts, with the only higher option $15 a month for 1000.

June 2009: AT&T spoils the iPhone party again by foregoing a subsidized upgrade path for current iPhone 3G owners. Awesome, thanks AT&T.

Categories
General

Free things to do in NYC

Fashion Institute of Technology
7th Ave at 27 St.
212-668-6624 

Forbes Magazine Galleries
62 5th Ave at 12th St. (toys)
212-206-5548

Sony Wonder Tech Lab
Sony Plaza Arcade
56th St. and Madison
212-833-5414

American Museum of Natural History
(Suggested $7.50 donation for students)
Central Park West @ 79th St.

Metropolitan Museum of Art
(Suggested  $5 donation for students)
1000 5th Avenue

Categories
Humor

Unabated bashery of ‘bated’ naysayers

Cruel Clever Cat

Sally, having swallowed cheese,
Directs down holes the scented breeze,
Enticing thus with baited breath
Nice mice to an untimely death.

~Geoffrey Taylor

Despite being one of the text-messaging generation, I am irked when I see ‘baited’ over ‘bated’. It’s almost as bad as the wanton exchange of ‘effect’ over ‘affect.’