UFS How to correctly align the SSD?

I'm having a lot of trouble understanding and calculating the alignment.

OBJECTIVE: Know how to calculate the alignment for my HD, So I can align my HDs on my Laptop, 2 Nvme and 1 SSD, They are different brands and different sizes

Problem 1: How do I create a partition table with 4096 byte sectors?
I only know this command to create partition table: gpart create -s GPT ada0
And it always creates with 512 byte sectors. Informed by the command: diskinfo -v /dev/ada0

Created a 200GB SSD in virtualbox, with the above command
Code:
40 419430320 ada0 GPT (200G)
40 419430320 - free - (200G)
512             # sectorsize

Problem 2: Which sector do I start in? So that my HD uses blocks of 4096 instead of 512? What is the correct formula to make this calculation?
My HDs have initial sectors 34, 40.
Those with initial sector 34 start in 2048
Those with an initial sector of 40 start at 40.
 
How do I create a partition table with 4096 byte sectors?
Partitions are aligned on 4K sectors, it's the filesystem that sets the size of sectors within that partition.

What is the correct formula to make this calculation?
A 'block' is 512 bytes. So 40 blocks is 40x512b = 20K (20K is neatly divisible by 4K)

34 blocks is 34x512 = 17408 = 17K; doesn't line up with 4K, so this would be bad on a 4K disk.

That initial 34 or 40 blocks is to leave room for the master boot record and partition table. That difference is probably MBR vs GPT. GPT needs more space for the tables. More importantly is the block at which the partition itself starts. 40 is fine (lines up with 4K but not 8K), 2048 is even better, it lines up with 4K, 8K, 16K, etc.
 
Partitions are aligned on 4K sectors, it's the filesystem that sets the size of sectors within that partition.


A 'block' is 512 bytes. So 40 blocks is 40x512b = 20K (20K is neatly divisible by 4K)

34 blocks is 34x512 = 17408 = 17K; doesn't line up with 4K, so this would be bad on a 4K disk.

That initial 34 or 40 blocks is to leave room for the master boot record and partition table. That difference is probably MBR vs GPT. GPT needs more space for the tables. More importantly is the block at which the partition itself starts. 40 is fine (lines up with 4K but not 8K), 2048 is even better, it lines up with 4K, 8K, 16K, etc.

I really liked your answer! You gave an even more complete answer, which I needed, because even though I'm talking about 4k, what I really want is how to do better and include 8k, 16k, etc... For me it's even better.

I was even more satisfied, because your answer matches the current partitioning of my physical disks, Which helps me understand why the programs partitioned differently, and which initially left me confused thinking there was something very wrong
Code:
# gpart show
=>        34  3907029101  nda0  GPT  (1.8T)
          34        2014        - free -  (1.0M)
        2048  3907026944     1  linux-data  (1.8T)
  3907028992         143        - free -  (72K)

=>        40  1000215136  nda1  GPT  (477G)
          40      532480     1  efi  (260M)
      532520    62382080     2  freebsd-ufs  (30G)
    62914600   209715200     3  freebsd-swap  (100G)
   272629800   727585376     4  freebsd-ufs  (347G)

=>        34  2000409197  ada0  GPT  (954G)
          34        2014        - free -  (1.0M)
        2048     1048576     1  efi  (512M)
     1050624    62914560     2  linux-data  (30G)
    63965184  1936443392     3  linux-data  (923G)
  2000408576         655        - free -  (328K)

Thank you very much
 
gpart(8) should default to 4K alignment by default nowadays. You can always add -a to force a certain alignment.

Code:
               -a alignment  If specified, then the gpart utility tries to
                             align start offset and partition size to be
                             multiple of alignment value.
 
I think now (FreeBSD 14.0-RELEASE-p5), you have to do nothing. Everything is aligned according to the drive as given by it's info. 512bytes or 4K as optimal.
There is "sysutils/lsblk"
Or try:
Code:
geom disk list | egrep -i "name|size"

But i'm uncertain about sectorsize & stripesize. Maybe someone can enlighten me.
 
Back
Top