Creating properly aligned partitions on a replacement disk

Posted by Marius Gedminas on Ask Ubuntu See other posts from Ask Ubuntu or by Marius Gedminas
Published on 2012-05-24T13:56:19Z Indexed on 2012/09/23 15:49 UTC
Read the original article Hit count: 371

Filed under:
|
|

I've a typical small office server with two hard disks configured for RAID-1 (mirroring). Each disk has several partitions: one for swap, the others paired in several /dev/mdX arrays.

Every couple of years one of the disks dies and is replaced. The replacement typically goes something like this:

# copy partition table from the remaining good disk to the empty replacement disk
# (instead of /dev/good_disk and /dev/new_disk I use /dev/sda and /dev/sdb, as appropriate)
sfdisk -d /dev/good_disk | sfdisk /dev/new_disk

# install boot loader
grub-install /dev/new_disk

# create swap partition reusing the same UUID, so I don't need to edit /etc/fstab
mkswap /dev/new_disk1 -U xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

# hot-add the new partitions to my RAID arrays
mdadm /dev/md0 -a /dev/new_disk2
mdadm /dev/md1 -a /dev/new_disk5
mdadm /dev/md2 -a /dev/new_disk6
mdadm /dev/md3 -a /dev/new_disk7
mdadm /dev/md4 -a /dev/new_disk8

The disks were originally partitioned with cfdisk back in 2009, and so the partition table is aligned traditionally to cylinder boundaries (255 heads * 63 sectors). This is not the optimum configuration for new 4K-sector drives.

My question is: how can I create a set of partitions for the new disk and ensure they're properly aligned, and have correct sizes for my RAID arrays (rounding up is acceptable, I suppose, but rounding down is definitely not)?

© Ask Ubuntu or respective owner

Related posts about command-line

Related posts about partitioning