Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Mar 2013 12:06:19 -0700
From:      Cody Ritts <cr@caltel.com>
To:        freebsd-fs@freebsd.org
Subject:   Re: Aligning MBR for ZFS boot help
Message-ID:  <513CD9AB.5080903@caltel.com>
In-Reply-To: <alpine.BSF.2.00.1303101006490.5989@wonkity.com>
References:  <513C1629.50501@caltel.com> <alpine.BSF.2.00.1303101006490.5989@wonkity.com>

next in thread | previous in thread | raw e-mail | index | archive | help
So, aligning to 63MB was still tricky.  I found your thread, but I could 
not find step by step how to calculate the offset.

So to put a close to this thread (hopefully), here is how I calculated 
my MBR alignment.

The MBR seems to force partitions to start on a track

There are 63 sectors/track

Rule of thumb for SSD Erase Blocks is align to 1MB (2048s)

I can start a partition on every 63rd sector:
63,126,189,252... etc

63 and 2048 have no common multiples, so
63x2048 = 129024

> root@:/root # gpart add -b 129024 -t freebsd ada0
> ada0s1 added
> root@:/root # gpart show ada0
> =>       63  125045361  ada0  MBR  (59G)
>          63     128961        - free -  (63M)
>      129024  124916400     1  freebsd  (59G)

YAY, my partition now starts at track 2048.


1MB for SSDs is a rule of thumb and most erase blocks are 128 256 or 
512. (so I have read on the internet).

Odds are, my SSD has an erase block of 512K or less, so, I can choose a 
smaller offset:

512K = 1024 sectors
1024*63 = 64512
> root@:/root # gpart add -b 64512 -t freebsd ada0
> ada0s1 added
> root@:/root # gpart show ada0
> =>       63  125045361  ada0  MBR  (59G)
>          63      64449        - free -  (31M)
>       64512  124980912     1  freebsd  (59G)


Anyway, that is good enough for me.
In the end, here are my working commands to create an aligned MBR 
partition ready for zpool creation and boot.
> gpart create -s mbr ada0
> gpart add -b 64512 -t freebsd ada0
> gpart create -s bsd ada0s1
> gpart add -s 52833M -t freebsd-zfs  ada0s1
> gpart add -t freebsd-swap ada0s1
> gpart set -a active -i 1 ada0
> gpart bootcode -b /boot/mbr ada0
> dd if=/boot/zfsboot of=/dev/ada0s1 count=1
> dd if=/boot/zfsboot of=/dev/ada0s1a skip=1 seek=1024

Also as related bonus, if you are reading about alignment, here is how 
to get 4k blocks for your zpool on an SSD or AF/4K hard drive.
> glabel label zfs  /dev/ada0s1a
> gnop create -S 4096 /dev/label/zfs
> zpool create -R /mnt tank /dev/label/zfs.nop
> zpool export tank
> gnop destroy /dev/label/zfs.nop
> zpool import -R /mnt -o cachefile=/tmp/zpool.cache system
> zdb -U /tmp/zpool.cache | grep ashift
>    ashift: 12
   2^12 = 4096


Thanks,

Cody



On 3/10/13 9:22 AM, Warren Block wrote:
> On Sat, 9 Mar 2013, Cody Ritts wrote:
>
>> Poking around on the internet, it looks like gpart is possibly
>> enforcing geometry boundaries?
>
> Not gpart, but the kernel.  At present, I don't know of any way to use
> FreeBSD for creating MBR slices aligned to anything other than 63
> blocks.  FreeBSD partitions can be aligned inside a slice with an
> offset.  Putting ZFS on one of those partitions may be the easiest way
> to do this.  Put the slice at block 2016, then align the first FreeBSD
> partition inside that slice to 1M and it should land at block 2048.
>
> Another option is to create the MBR with aligned slices using another
> operating system, one that allows deviation from the MBR standard.
> Ronald Guilmette recently showed an interesting approach of starting the
> slice at 63M, the least common multiple of 63 and 1M.
>
> If the BIOS does not like GPT, check for BIOS updates.  And make sure
> the vendor knows about the problem.
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?513CD9AB.5080903>