首先,我通过指定分区开始和结束的百分比,使用 parted 在新 GPT 表中创建一个正确对齐的分区:
# parted -a optimal /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Y
(parted) mkpart primary 0% 1%
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB primary
(parted) quit
Run Code Online (Sandbox Code Playgroud)
请注意,此磁盘正在使用高级格式,但正确地报告了4096B
Parted的物理扇区大小。我们再看一遍,以扇区为单位:
# parted -a optimal /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
1 2048s 4095s 2048s primary
(parted) quit
Run Code Online (Sandbox Code Playgroud)
2048s
而不是34s
第一个可能的扇区?34s
如果物理扇区大小为4096B
且逻辑(您在 Parted 中指定的)扇区大小为 ,则不是正确对齐的起始扇区512B
。正确对齐的起始扇区可以被8
(因为物理扇区大小 / 逻辑扇区大小 = 8
)整除。但这意味着40s
是第一个正确对齐的起始扇区,但尚未使用。为什么?如果我们尝试在新的 GPT 分区表中创建一个正确对齐的100MiB
容量40s
分区:
# parted -a optimal /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Y
(parted) mkpart primary 40s 204839s
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
(parted) unit MiB
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 2861588MiB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
1 0.02MiB 100MiB 100MiB fat32 primary
(parted)
(parted) unit s
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
1 40s 204839s 204800s fat32 primary
(parted)
Run Code Online (Sandbox Code Playgroud)
Warning: The resulting partition is not properly aligned for best performance.
警告,即使40s
和 204840s ( 204839s
+1) 都可以被 整除8
。为什么?Rod*_*ith 24
Parted 只是过于保守。现在通常的做法是在 1MiB(2048 扇区)边界上对齐分区,因为这适用于高级格式磁盘、需要对齐的某些类型的 RAID 设置以及大多数 SSD。对于高级格式磁盘,只要对齐是 8 的倍数,就可以了,而 2048 是 8 的倍数。丢失的磁盘空间微不足道——如果我这样做了,则占总磁盘空间的 0.0000336%数学正确,没有打错任何东西。所以不用担心;只需使用 1MiB 对齐。