Other Alignment question

circus78

Active Member

Thanks: 6
Messages: 201

#1
Hi,
probably this is going to be a very newbie question :)
I wondering why in gpart show output I often see "40" as starting point:

Code:
# gpart show
=>     40  8388528  ada0  GPT  (4.0G)
       40     1024     1  freebsd-boot  (512K)
     1064  7965696     2  freebsd-ufs  (3.8G)
  7966760   419840     3  freebsd-swap  (205M)
  8386600     1968        - free -  (984K)
I am aware of "4K alignment" issue, but why not less (or 0)?
I mean:

Code:
40 (blocks) x 512B (block's size) = 20480B = 20kB
Surely 20 is multiple of 4.
Why not starting at 32 blocks, for example?
Code:
32 (blocks) x 512B (block's size) = 16384B = 16kB
Thank you very much
 

ralphbsz

Daemon

Thanks: 766
Messages: 1,289

#3
What is in sector 0? How big is the GPT itself? Where is it stored? You can find the answers to these questions on Wiki.

And what is the hardware alignment of the 4K physical blocks? Try using "camcontrol identify" on your disk.

(Warning: I didn't give you the answer; I gave you the tools to figure out the answer by yourself.)
 
OP
OP
C

circus78

Active Member

Thanks: 6
Messages: 201

#5
Hi, I ask confirm: are these 2 server 4K-aligned? I think not..

Server #1

Code:
# gpart show
=>       34  167772093  da0  GPT  (80G)
         34        128    1  freebsd-boot  (64K)
        162  159383424    2  freebsd-ufs  (76G)
  159383586    8388540    3  freebsd-swap  (4.0G)
  167772126          1       - free -  (512B)


# diskinfo -v da0
da0
        512             # sectorsize
        85899345920     # mediasize in bytes (80G)
        167772160       # mediasize in sectors
        0               # stripesize
        0               # stripeoffset
        10443           # Cylinders according to firmware.
        255             # Heads according to firmware.
        63              # Sectors according to firmware.
                        # Disk ident.
        Not_Zoned       # Zone Mode
Server #2

Code:
# gpart show
=>       34  167772093  da0  GPT  (80G)
         34       1024    1  freebsd-boot  (512K)
       1058  159382528    2  freebsd-ufs  (76G)
  159383586    8388540    3  freebsd-swap  (4.0G)
  167772126          1       - free -  (512B)

# diskinfo -v da0
da0
        512             # sectorsize
        85899345920     # mediasize in bytes (80G)
        167772160       # mediasize in sectors
        0               # stripesize
        0               # stripeoffset
        10443           # Cylinders according to firmware.
        255             # Heads according to firmware.
        63              # Sectors according to firmware.
                        # Disk ident.
        Not_Zoned       # Zone Mode
Thank you
 

swegen

Member

Thanks: 51
Messages: 75

#6
Those servers are not 4k aligned, but with those older 80G disks it does not matter anyway as the physical sector size is 512 bytes.

Generally, it is best practice to create partitions so that both the starting sector and the size is divisible by 8.

With SSDs the safest alignment is divisible by 2048 sectors (1 MiB) because of varying erase block size between different manufacturers.
 

ralphbsz

Daemon

Thanks: 766
Messages: 1,289

#7
I now use 1MiB alignment on absolutely everything. Makes thinking and calculating easier. The only thing one has to be careful about (and gpart supposedly knows how to handle it): There are some 512e disks (meaning 4k physical blocks, 512 byte emulated) where the first block is undersized, to better fit ancient Windows partition tables. There is a disk inquiry parameter to describe it though, and modern partitioning software should handle it automatically.
 
OP
OP
C

circus78

Active Member

Thanks: 6
Messages: 201

#8
Those servers are not 4k aligned, but with those older 80G disks it does not matter anyway as the physical sector size is 512 bytes.

Generally, it is best practice to create partitions so that both the starting sector and the size is divisible by 8.

With SSDs the safest alignment is divisible by 2048 sectors (1 MiB) because of varying erase block size between different manufacturers.
Hi swegen, actually those are VMware virtual machine. They reside on a Dell storage with SAS disks.
Should I check hardware information of these disks in order to be sure that VMs are "4K-aligned"?

What is "erase block"?
Thank you very much
 
OP
OP
C

circus78

Active Member

Thanks: 6
Messages: 201

#9
Anyway, let's say one discover that his alignment is not correct.
Should I reinstall OS, or is it possible to use some tools like GParted?
 

ralphbsz

Daemon

Thanks: 766
Messages: 1,289

#11
Anyway, let's say one discover that his alignment is not correct.
Should I reinstall OS, or is it possible to use some tools like GParted?
That's a difficult situation. The answer will be depend on how much valuable data is on the machine, and how complex the installation is. Clearly, you can use gpart to destroy the partitions one at a time, and recreate them with the correct alignment. However, I don't know a way to keep a file system around while its underlying partition is being "moved" = destroyed and recreated. I fear you would have to drain all the file systems on your partitions of data, one at a time, then move the data back. Depending on how your machine is partitioned, this may not even be possible. If you have only a tiny boot partition, swap partition, and then a single giant root file system partition, there is no place you can move the data to, unless you get another disk of about the same size. In that case, it would probably be easier to move all your personal data to a small device (most people have very little data in their home directory, and it usually fits easily onto a USB stick, or can be copied to the cloud), then reinstall.

On the other hand, if you have many partitions on your disk, and you have invested a lot of time and effort into the installation itself, then it might be possible (and a good idea) to really delete your partitions and file systems one at a time. This will be a lot of work, and error-prone.
 
Top