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.


# 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

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?

  • 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 Dec 4 '15 at 16:23
  • @TomHunt I just deleted all the partitions, and created a GPT disk label all over again by running mklabel gpt. So keeping alignment in mind, how should I run mkpart now? – its_me Dec 4 '15 at 16:49
  • 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. – Tom Hunt Dec 4 '15 at 17:16
  • @TomHunt I think parted does it automatically too. I've added details in my question to show the same. – its_me Dec 4 '15 at 17:18

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.

| improve this answer | |

I just tested in a vm with centos 6.7:

# parted /dev/sdb 
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/sdb: unrecognised disk label                                  
(parted) mklabel gpt                                                      
(parted) mkpart primary 1m 100%
(parted) quit                                                             
Information: You may need to update /etc/fstab.                           

[root@localhost ~]# parted /dev/sdb print 
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1073MB  1072MB               primary

[root@localhost ~]# parted /dev/sdb "unit s print"
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 2097152s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End       Size      File system  Name     Flags
 1      2048s  2095103s  2093056s               primary

so there you are, properly aligned gpt partition.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.