使用Parted在高级格式HDD上正确对齐分区
首先,我通过指定分区的开始和结束的百分比,使用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
请注意,此磁盘使用高级格式,但正确地将物理扇区大小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
- 为什么它在
2048s
开始分区而不是34s
,这是第一个可能的扇区 ? - 如果物理扇区大小为
4096B
并且逻辑(在Parted中指定的逻辑)扇区大小为512B
则4096B
不是正确对齐的起始扇区。 正确对齐的起始扇区是可被8
除的一个(因为物理扇区大小/逻辑扇区大小=8
)。 但这意味着40s
是第一个正确对齐的起始扇区,但它没有被使用。 为什么?
如果我们尝试在新的GPT分区表中创建一个从40s
开始的100MiB
容量的正确对齐分区:
# 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)
- 我们仍然收到
Warning: The resulting partition is not properly aligned for best performance.
警告,即使40s
和204840s(204839s
+ 1)都可以被8
分割。 为什么?
分手只是过于保守。 目前通常的做法是在1MiB(2048扇区)边界上对齐分区,因为这适用于高级格式磁盘,某些类型的需要对齐的RAID设置以及大多数SSD。 对于高级格式化磁盘,只要对齐为8的倍数,你就可以了,2048是8的倍数。丢失的磁盘空间很小 – 占总磁盘空间的0.0000336%,如果我做的话数学权利并没有错误输入任何东西。 所以不要担心; 只需使用1MiB对齐。