# Boot Partition



## tzoi516 (Oct 28, 2013)

Looking over a few gpart(8) examples I've noticed people using -b 34 and -b 64. Using gpart(8) over MBR, why not start at sector 1, or how does one determine the correct sector to start the boot partition at?


----------



## SirDice (Oct 28, 2013)

tzoi516 said:
			
		

> why not start at sector 1, or how does one determine the correct sector to start the boot partition at?


Because that's where the boot sector and the partition tables live. Starting at 34 will prevent tools like MS-DOS' FDISK.EXE from overwriting important bits.


----------



## tzoi516 (Oct 28, 2013)

Isn't all of that information at the beginning of the GPT boot track already? If so then why not sector 1, or does the first sector of the boot track contain just the metadata?


----------



## SirDice (Oct 28, 2013)

tzoi516 said:
			
		

> Isn't all of that information at the beginning of the GPT boot track already?


The disk is either MBR or GPT. GPT does create a "fake" MBR for backwards compatibility. 

Also note that a BIOS or UEFI has no idea how the disk is divided. So it starts looking at one certain point, reads the structures there and only then knows where the other partitions are.


----------



## kpa (Oct 28, 2013)

I think it's purely for compatibility reasons. Some older BIOSes might make some assumptions on how partitions are aligned and may not work if the partitions start at a "non-standard" offset.


----------



## wblock@ (Oct 28, 2013)

It's not clear what you are asking.  The GPT tables at the beginning and end of the disk are just partition tables.  By default, they are 34 blocks long, but can vary.  Those tables have no place to store boot code.  That space is provided by a freebsd-boot partition.

To repeat what I've suggested elsewhere:

Make the freebsd-boot partition 512K, the largest size allowed.  Why not?  Boot code has grown in the past, and because of the next step, that space will not be used anyway.  (The boot partition can be aligned to 4K blocks without penalty but also without any practical difference.  Might as well, to be consistent.)

Start the first data partition at 1M for compatibility with non-FreeBSD systems.


----------



## tzoi516 (Oct 28, 2013)

OK, I can understand backwards compatibility. Are the selected sectors fixed at 1-33, or is it a rule-of-thumb? I've seen people start it at 64.

My goal is to have the most optimum settings for a computer I'm setting up for myself, and a lot of auto options just don't seem to be efficient.


----------



## wblock@ (Oct 28, 2013)

`gpart add -t freebsd-boot -b 40 -s 512K da0`

40 is the first 4K-aligned block.  After a change in FreeBSD 9.1, the better version is:
`gpart add -t freebsd-boot -a 4k -s 512K da0`

What automatic options seem to be inefficient?


----------



## tzoi516 (Oct 28, 2013)

In testing different settings for finding the optimal way I want to lay the foundation for my storage I've come across many interpretations (from guided partitioning via `bsdinstall` to peoples' recommendations) of what should start where, size, etc, and, to me, that's not efficient - personal preference.

Thanks for the suggestions.


----------



## wblock@ (Oct 28, 2013)

Oh, and the GPT partition table is not a fixed size.  The default is 33 blocks, allowing up to 128 partitions.  See http://en.wikipedia.org/wiki/GUID_Partition_Table.


----------



## tzoi516 (Oct 28, 2013)

Ah, LBA 34 (512) and LBA 40 (4K). Great! Thanks.


----------



## wblock@ (Oct 28, 2013)

For the next available block, yes.  But there is no disadvantage to aligning to 4K on drives with 512-byte blocks.  Summary: align everything to 4K blocks, regardless of the drive.

The freebsd-boot partition does not have to be the first partition on the drive.


----------



## tzoi516 (Oct 28, 2013)

wblock@ said:
			
		

> But there is no disadvantage to aligning to 4K on drives with 512-byte blocks.  Summary: align everything to 4K blocks, regardless of the drive.


Wouldn't that be better on a 4K drive with 512e? I've read people on 512 drives having boot issues when aligning to 4K - my drive is 4K with 512e for BC, but I have an old Dell I've been keeping BS to 512.


----------



## wblock@ (Oct 28, 2013)

At present, I think all drives are 512e.  They report a block size of 512 bytes and a logical size of 4096 bytes.  When they start reporting honestly, expect breakage.

I have not encountered boot problems when aligning to 4K on 512-byte drives, but would be interested.


----------

