SSD partition realignment

If you want a great value host in the UK, OVH is pretty good. Their SSD based machines are hard to beat on price. Sure, the service sucks, but you get what you pay for.

There’s a bug with their auto installer, it automatically partitions the whole disk even if you leave a chunk free to reduce write amplification. By default we’re setup with software RAID. This allows for the on-the-fly repartitioning of the disks to align them with the 4k pages on the disk. The OVH auto installer leaves them out of alignment, bad.

Here’s a step by step, please be sure you understand before attempting to run these commands, or you could easily destroy all your data.

Assuming you have a few logical volumes (say 80Gs worth) on a 120G disk with a 10G root partition, leaving in theory 30G free. First, reduce the physical volume to 83G (just a little over 80G to be on the safe side), next reduce the raid partition to 85G (again, a little over, better safe than sorry). Then take one drive out of the raid array, delete the partition, create a new properly aligned partition, add it back to the raid array. Now let it resync and repeat for the second drive. Finally, resize up the raid partition and the physical volume.

This assumes /dev/sda|b3 is an extended partition containing 1 logical partition /dev/sda|b5 which is in raid partition /dev/md5.

Make a copy of your partition tables, raid layout, etc, before you start. Backup.

# Resize the physical volume and raid array
pvresize --setphysicalvolumesize 83G /dev/md5
mdadm --grow /dev/md5 --size 89216000

# Take this partition out of the RAID array
mdadm --manage /dev/md5 --fail /dev/sda5
mdadm --manage /dev/md5 --remove /dev/sda5
mdadm --zero-superblock /dev/sda5

# Remove the partition
parted /dev/sda rm 5
parted /dev/sda rm 3

# Moved everything down the drive to align properly with 512k rows
parted /dev/sda mkpart extended 23068672s 209715200s
parted /dev/sda mkpart logical 23072768s 209715200s
parted /dev/sda set 5 raid on

# Add the partition back into the RAID array
mdadm -a /dev/md5 /dev/sda5

# Let the resync finish, then repeat for the other drive

# Resize the raid and lvm back to the full size of the new partition
mdadm --grow /dev/md5 --size=max
pvresize /dev/md5

Advertisements