GPT and disk alignment

Andrey V. Elsukov bu7cher at yandex.ru
Thu Jun 9 09:44:46 UTC 2011


On 08.06.2011 7:27, Robert Simmons wrote:
> Do all HDDs that have 4KB per LBA present themselves to the OS as
> having 512 bytes per LBA?

Recently I added automatic alignment feature to gpart(8) in head/.
I plan to merge it to stable/8 in the next week. Also there were some
changes in ada(4) driver and now you can add quirk for your drive to
let system know about your 4k drive.

The easiest way to know is your partition aligned or not - use diskinfo(8).
Example:
# diskinfo -v ada0p3
ada0p3
        512             # sectorsize
        75731098112     # mediasize in bytes (70G)
        147912301       # mediasize in sectors
        4096            # stripesize
        1024            # stripeoffset
        146738          # Cylinders according to firmware.
        16              # Heads according to firmware.
        63              # Sectors according to firmware.
        S0DEJ1NL817767  # Disk ident.

If `echo $stripeoffset % 4096 | bc` is not zero - your partition
is not aligned (where $stripeoffset is value from diskinfo(4) output).

About gpart(8). The current implementation of some partitioning schemes does not
allow to use any offset values for partitions (MBR, EBR, VTOC8). But GPT does allow.
So examples for GPT, to align new partition you can use this command:

# gpart add -t freebsd-zfs -s 10G -a 4k ada0

and gpart will try to align it to 4k boundaries.

About ada(4) quirks. You can add to your loader.conf this line:

kern.cam.ada.0.quirks="1"

After reboot your disk will report about 4k stripesize:
# geom disk list ada0
Geom name: ada0
Providers:
1. Name: ada0
   Mediasize: 80026361856 (74G)
   Sectorsize: 512
   Stripesize: 4096
   Stripeoffset: 0
   Mode: r2w2e4
   descr: SAMSUNG HD080HJ/P
   ident: S0DEJ1NL817767
   fwsectors: 63
   fwheads: 16

And gpart(8) will use this information for automatic alignment.
But this will work only in 9.0-CURRENT.

-- 
WBR, Andrey V. Elsukov

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20110609/c7d8f94d/signature.pgp


More information about the freebsd-fs mailing list