Check if partitions are aligned properly for performance?

16,455

Starting partedwith the --align optimal option tells the program to align to multiples of the device's physical block size to ensure best performance.

The --align option has other types available as well.

See man parted for more information.

Share:
16,455

Related videos on Youtube

its_me
Author by

its_me

Updated on September 18, 2022

Comments

  • its_me
    its_me over 1 year

    I just created a GPT disk label for the entire space on my hard disk (/dev/sda) like so:

    # parted
    
    (parted) select /dev/sda
    (parted) mklabel gpt
    Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
    Yes/No? Y
    (parted) mkpart primary 0% 100%
    Warning: The resulting partition is not properly aligned for best performance.
    Ignore/Cancel? I
    (parted) quit
    

    Upon further reading now, I realized that 'ignoring' was probably a bad idea w.r.t performance.

    But...

    # parted
    
    (parted) print
    Model: ATA ST33000650NS (scsi)
    Disk /dev/sda: 3001GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start   End     Size    File system  Name  Flags
     5      1049kB  2097kB  1049kB                     bios_grub
     1      2097kB  8592MB  8590MB                     raid
     2      8592MB  9129MB  537MB                      raid
     3      9129MB  43.5GB  34.4GB                     raid
     4      43.5GB  3001GB  2957GB                     raid
    
    (parted) align-check optimal 1
    1 aligned
    (parted) align-check optimal 2
    2 aligned
    (parted) align-check optimal 3
    3 aligned
    (parted) align-check optimal 4
    4 aligned
    (parted) align-check optimal 5
    5 aligned
    (parted)
    

    So parted has aligned the partitions by itself? align-check optimal * says so.

    1. If that's not the case, how do I check if the disk's partitions need to be re-aligned for performance? And how do i go about doing that?

    2. If that's indeed the case, mkpart primary 0% 100% actually automates the process of aligning partitions in all cases? Any edge cases where it wouldn't?

    • Tom Hunt
      Tom Hunt over 8 years
      Modern disks are best aligned to a 4k boundary, IIRC, and many tools will align to 1M by default in order to allow more easily for abstractions like LUKS/mdraid/LVM. I'm not wholly familiar with parted output, but it does appear that the partitions there are misaligned at 4k. Meanwhile, the only way to realign the partitions is to delete and recreate them.
    • Tom Hunt
      Tom Hunt over 8 years
      I've only ever done this with fdisk or gdisk. They both handle alignment automatically by default, and it'll be aligned correctly so long as you specify partition lengths in large units (gigabytes, usually). I have no idea how to do it with parted.
    • its_me
      its_me over 8 years
      @TomHunt I think parted does it automatically too. I've added details in my question to show the same.
  • Daniel F
    Daniel F about 3 years
    What I don't understand is why, if I then use mkpart primary 0% 100%, the partition starts at 33.6 MB. That is a lot more than multiples of 512B ( Sector size (logical/physical): 512B/512B with Partition Table msdos )