How to align partitions for best performance using parted

2019-04-18 18:26:10
backgroud

as usual, Trying to create a 10TB partition using parted,I type command like

1
parted -s -a optimal /dev/sdb mklabel gpt -- mkpart primary xfs 1 -1

but parted always complains as follows

1
The resulting partition is not properly aligned for best performance

soulation

Add optimal_io_size to alignment_offset and divide the result by physical_block_size. In my case this was

1
2
3
4
5
6
7
8
# cat /sys/block/sdb/queue/optimal_io_size
1048576
# cat /sys/block/sdb/alignment_offset
0
(1048576 + 0) / 512 = 2048

#Your new parted command should look like
parted -s -a optimal /dev/sdb mklabel gpt -- mkpart primary xfs 4608s 100%

The trailing ‘s’ is important: it tells parted that you’re talking about sectors, not bytes or megabytes

finally,let check it,the partition will have been created with no warnings. You can check the alignment thusly (replacing ‘1’ with the partition number if necessary):

1
2
(parted) align-check optimal 1                                            
1 aligned