Aligning MBR for ZFS boot help

Bruce Evans brde at optusnet.com.au
Thu Mar 14 09:41:34 UTC 2013


On Wed, 13 Mar 2013, Cody Ritts wrote:

> So, if I now want to create an aligned single partition, here are the steps I 
> think I should be taking:
>
> Sectors should be < 64
> Heads should be  < 256
> for OLD OLD stuff, cylinders should be < 1024

No.

Sectors _must_ be < 64
Heads _must_ be < 257
Heads should be < 256
for OLD OLD stuff, cylinders should be < 1024

> if you want boundaries on a power of 2, those the number of sectors and heads 
> should also be a power of 2.
>
> So, would all of these be potential valid values?
>
> s32  h128
> 512*32*128 = 2097152B = 2MB cylinder
> s32  h64
> 512*32*64  = 1048576B = 1MB cylinder
> s16  h128
> 512*16*128 = 1048576B = 1MB cylinder
> s4  h8
       h4
> 512*4*4   = 8192B  = 8K cylinder

Yes, provided the BIOS agrees.  If the BIOS config says that CHS is
something or other, better use or change that.  Also, s4 h8 would
probably cause problems with older BIOSes if they actually use CHS,
by causing cylinder numbers to exceed 64K.  64K cylinders of size 8KB
is just 512MB.  BIOSes might use 16-bit cylinder numbers for translating
from CHS to linear even if they don't really use CHS.

> I am assuming that once I know my cylinder size, I just divide the total size 
> of my hard drive to come up with cylinder count?

Usually I don't bother changing the cylinder count when I change the number
of heads and sectors, since I know that it is not really used by fdisk
(except possibly for default partition sizes which I never use).

> s4  h8
> 64023257088 / 8192 = 7815339c
> (8k is the largest power of 2 that the drive will evenly divide into)
>
> s32  h64
> 64023257088 / 1048576 = 61057.3359375
> Round down to 61057.
> (does the cylinder need to end on the end of the disk?)

If the sector count were used, then it should be set to the rounded
down value.  It is usually safe to make the last partition end at the
of the disk and not at the end of the fake cylinder given by rounding.
I sometimes use the part beyond the end of the fake cylinder and for
a normal partition and sometimes leave it free.

> So, here is what i calculated:
> c61057 h64 s32
>
> I want an offset of 2M, file system should be reduced to 61055M
>  (61055 * 1024 * 1024)/512 = 125040640s)
>
> Here are the commands that I ran:
>
>> cat << EOF > command
>> g c61057 h64 s32
>> p 1 0xa5 4096 125040640
>> a 1
>> EOF
>> root@:/root # fdisk -f command ada0
>> ******* Working on device /dev/ada0 *******
>> fdisk: WARNING line 1: number of cylinders (61057) may be out-of-range
>>     (must be within 1-1024 for normal BIOS operation, unless the entire 
>> disk
>>     is dedicated to FreeBSD)
>> root@:/root # fdisk -p ada0
>> # /dev/ada0
>> g c124053 h16 s63
>> p 1 0xa5 4096 125040640
>> a 1
> note, it auto goes back when exporting

Seems reasonable, but I didn't check the details.  Anything that avoids
the message about the automatic broken adjustment is probably OK.

>> root@:/root # gpart show ada0
>> =>       63  125045361  ada0  MBR  (59G)
>>          63       4033        - free -  (2M)
>>        4096  125040640     1  freebsd  [active]  (59G)
>>   125044736        688        - free -  (344k)
>> root@:/root # gpart delete -i 1 ada0
>> root@:/root # gpart add -t freebsd -b 4096 -s 125040640 ada0
>> ada0s1 added
>> root@:/root # gpart show ada0
>> =>       63  125045361  ada0  MBR  (59G)
>>          63       4095        - free -  (2M)
>>        4158  125040573     1  freebsd  (59G)
>>   125044731        693        - free -  (346k)
> gpart does not care

I don't know anything about gpart, and if it always does the wrong adjustment
then I don't want to know.

>> root@:/root # fdisk -f command ada0
>> ******* Working on device /dev/ada0 *******
>> fdisk: WARNING line 1: number of cylinders (61057) may be out-of-range
>>     (must be within 1-1024 for normal BIOS operation, unless the entire 
>> disk
>>     is dedicated to FreeBSD)
>> root@:/root # fdisk ada0
>> ******* Working on device /dev/ada0 *******
>> parameters extracted from in-core disklabel are:
>> cylinders=124053 heads=16 sectors/track=63 (1008 blks/cyl)
>> 
>> Figures below won't work with BIOS for partitions not in cyl 1
>> parameters to be used for BIOS calculations are:
>> cylinders=124053 heads=16 sectors/track=63 (1008 blks/cyl)

It regressed to the broken default as usual.  This is dangerous when
modifying partition tables that have a geometry differing from the
default.  You can sill edit everything without changing the geometry
if you are careful.

>> Media sector size is 512
>> Warning: BIOS sector numbering starts with sector 1
>> Information from DOS bootblock is:
>> The data for partition 1 is:
>> sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
>>     start 4096, size 125040640 (61055 Meg), flag 80 (active)
>> 	beg: cyl 2/ head 0/ sector 1;
>> 	end: cyl 640/ head 63/ sector 32

E.g., suppose you just want to change the sysid here.  Type it in.
Accept the defaults for the start and size so that these don't
change.  Then fdisk will default to making a mess of the CHS
values (if the default is wrong).  This can be recovered from
by typing in all the old values.

>> The data for partition 2 is:
>> <UNUSED>
>> The data for partition 3 is:
>> <UNUSED>
>> The data for partition 4 is:
>> <UNUSED>
>
> So, setting the geom simply does this:
>>> sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
>>>     start 4096, size 125040640 (61055 Meg), flag 80 (active)
>>> 	beg: cyl 2/ head 0/ sector 1;
>>> 	end: cyl 640/ head 63/ sector 32
>
> I cannot set geom in my bios, nor does not show me what it thinks geom is. 
> Obviously anything that only supports 1024 cylinders will not think it is 
> very funny.

Probabablyy many newer BIOSes do this.

> I feel like I am missing some part of this puzzle, or is that all there is to 
> this to correct geom for proper alignment on an MBR?

I don't like the looks of gpart, but it has a -a option for alignment.

> So, by setting those CHS values I am:
>  making the partition table more compatible with other operating systems and 
> BIOSes?
>  and giving some utilities the CHS stuff they need to function right?

It's not completely clear that S=32 H=64 is portable, but it is what most
old SCSI BIOSes used.

Also, if the disk already has some partitions with a certain geometry, use
the same geometry for other partitions and don't use fdisk's defaults if
they differ.

Bruce


More information about the freebsd-fs mailing list