Solved GPT fdisk (gdisk(8)) and gpart(8)

When gdisk(8) adds the first partition to a disk, it defaults to 1 M free space before the partition, for example:

Code:
root@mowa219-gjp4-8570p-freebsd:~ # gpart show da4
=>       34  976773101  da4  GPT  (466G)
         34       2014       - free -  (1.0M)
       2048  976771087    1  freebsd-ufs  (466G)

When gpart(8) adds the first partition to a disk, no such space:

Code:
root@mowa219-gjp4-8570p-freebsd:~ # gpart show da4
=>       40  976773088  da4  GPT  (466G)
         40  976773088    1  freebsd-ufs  (466G)

What's the likeliest explanation for having free space by default?

From various search results: my best guess is that it's precautionary, with an assumption that a disk might later require a BIOS boot partition.


Also, from GPT fdisk Partitioning Advice:


  • When launched on a disk with no partition table, the software sets a default alignment value of 2048 (1 MiB).

Code:
root@mowa219-gjp4-8570p-freebsd:~ # gpart show da4
gpart: No such geom: da4.
root@mowa219-gjp4-8570p-freebsd:~ # gpart create -s gpt da4
da4 created
root@mowa219-gjp4-8570p-freebsd:~ # gpart add -t freebsd-ufs -i 1 da4
da4p1 added
root@mowa219-gjp4-8570p-freebsd:~ # gpart show da4
=>       40  976773088  da4  GPT  (466G)
         40  976773088    1  freebsd-ufs  (466G)

root@mowa219-gjp4-8570p-freebsd:~ # gdisk /dev/da4
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): x

Expert command (? for help): z
About to wipe out GPT on /dev/da4. Proceed? (Y/N): y
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): y
root@mowa219-gjp4-8570p-freebsd:~ # gdisk /dev/da4
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): n
Partition number (1-128, default 1):
First sector (34-976773134, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-976773134, default = 976773134) or {+-}size{KMGTP}:
Current type is A503 (FreeBSD UFS)
Hex code or GUID (L to show codes, Enter = A503):
Changed type of partition to 'FreeBSD UFS'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/da4.
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
The operation has completed successfully.
root@mowa219-gjp4-8570p-freebsd:~ # gpart show da4
=>       34  976773101  da4  GPT  (466G)
         34       2014       - free -  (1.0M)
       2048  976771087    1  freebsd-ufs  (466G)

root@mowa219-gjp4-8570p-freebsd:~ # /usr/home/grahamperrin/dev/lsblk/lsblk
DEVICE         MAJ:MIN SIZE TYPE                                          LABEL MOUNT
ada0             0:121 932G GPT                                               - -
  ada0p1         0:123 260M efi                                    gpt/efiboot0 -
  <FREE>         -:-   1.0M -                                                 - -
  ada0p2         0:125  16G freebsd-swap                              gpt/swap0 SWAP
  ada0p2.eli     2:66   16G freebsd-swap                                      - SWAP
  ada0p3         0:127 915G freebsd-zfs                                gpt/zfs0 <ZFS>
  ada0p3.eli     0:135 915G zfs                                               - -
  <FREE>         -:-   708K -                                                 - -
da4              2:119 466G GPT                                               - -
  <FREE>         -:-   1.0M -                                                 - -
  da4p1          0:169 466G MBR                               gpt/FreeBSD%20UFS -
    <FREE>       -:-   466G -                                                 - -
da5              0:230 466G GPT                                               - -
  <FREE>         -:-   1.0M -                                                 - -
  da5p1          0:231 466G freebsd-zfs                           gpt/Transcend <ZFS>
da6              0:238  14G GPT                                               - -
  <FREE>         -:-   1.0M -                                                 - -
  da6p1          0:239  14G freebsd-zfs                     gpt/cache-transcend <ZFS>
da7              0:247  29G GPT                                               - -
  da7p1          0:248  29G freebsd-zfs                        gpt/cache-august <ZFS>
root@mowa219-gjp4-8570p-freebsd:~ # gpart show
=>        40  1953525088  ada0  GPT  (932G)
          40      532480     1  efi  (260M)
      532520        2008        - free -  (1.0M)
      534528    33554432     2  freebsd-swap  (16G)
    34088960  1919434752     3  freebsd-zfs  (915G)
  1953523712        1416        - free -  (708K)

=>       34  976773101  da5  GPT  (466G)
         34       2014       - free -  (1.0M)
       2048  976771087    1  freebsd-zfs  (466G)

=>      34  30310333  da6  GPT  (14G)
        34      2014       - free -  (1.0M)
      2048  30308319    1  freebsd-zfs  (14G)

=>      34  60437425  da7  GPT  (29G)
        34  60437425    1  freebsd-zfs  (29G)

=>       34  976773101  da4  GPT  (466G)
         34       2014       - free -  (1.0M)
       2048  976771087    1  freebsd-ufs  (466G)

=>       63  976771024  da4p1  MBR  (466G)
         63  976771024         - free -  (466G)

=>       63  976771024  gpt/FreeBSD%20UFS  MBR  (466G)
         63  976771024                     - free -  (466G)

root@mowa219-gjp4-8570p-freebsd:~ #
 
What's the likeliest explanation for having free space by default?
Partition alignment. The partition starts at 2048, which is exactly at a 1 MB boundary. That makes it fit neatly with 512B, 4KB and 8KB block sizes. And with plenty of gigabytes that 1 MB is only a small fraction of the total diskspace, you're not going to miss it.
 
Alignment can be a huge factor on performance. Get it wrong and you wind up having reads and writes across partitions.
Lots of smart folks say it's not a bad idea to always specify a 1M alignment when you create partitions in gpart.
 
Thank you both,

… specify a 1M alignment when you create partitions in gpart.

– from the manual page, I'd never have guessed :-/

I know, it's amongst the tips in the Handbook, under Installing FreeBSD, but hey …

1630336979071.png
 
  • Like
Reactions: mer
Back
Top