Fdisk, dd, and the Rapsberry pi

ddfdiskmbrpartitionraspberry pi

I was trying to wipe my 4GB SD card which acts as the hard drive for the Raspberry Pi, so I went into Mac OS X Disk Utility* and Erased the entire disk, and specified that the whole disk be one big FAT-32 partition.

The output of fdisk /dev/disk2:

Disk: /dev/disk2    geometry: 975/128/63 [7866368 sectors]
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: 0B 1023 254  63 - 1023 254  63 [      8192 -    7858176] Win95 FAT-32
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused

My question is, why does the first partition start at 8192 sectors, and not right after the boot sector?

*Forgive me. My fdisk abilities are not exactly guru-level.

Best Answer

This is related to the underlying physical sectors of the SD card. In short: The first "block" is optimized to host the File Allocation Table, which describes the structure of a MS hard disk with 1 vfat partition.
This is an assumption that is not true, but a lot of devices, cameras, phones etc just use a vfat storage on a single partition. And the cards are made for this market. The other blocks are optimized for writing big, continuous files (pictures, video, etc).

SD cards use several types of logical blocks, the most important being the "erase block", which is the minimal amount of data that can be erased at once. To write anything on the card, the card controller (inside the SD) has to read a whole erase block first, then erase it, then write it with the updated content.
I have an old 4G card with a 1M block, most recent cards have a 4M block.

That's 8192 512-bytes sectors.

So you have to align your partition so that writing a file on the card doesn't end up in erasing 1 extra block. Otherwise you end up with a card that is slower to write to a noticiable point when eg you write some small files.
More info on lwn.net: Optimizing Linux with cheap flash drives

I don't know about Mac OS X Disk Utility. Maybe It's a safe default, or it performs some magic. see flashbench for more info on your card.

Related Question