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)?
I just had to replace the mirror in one of my arrays today, and I opted to just fdisk the replacement instead of using sfdisk. Since I know the partition sizes (its just one, in my case) and I went with a bigger drive for the replacement.
Original is RAID1 of a pair of ST31500341AS, and replacement disk is an ST2000DL003.
So, what I did was:
mdadm /dev/md6 --fail /dev/sde1
mdadm /dev/md6 --remove /dev/sde1
fdisk /dev/sde
This results in new partition with start 2048 and end
3907029167 - for 1953513560 blocks (or 244189195 in 4k blocks)3907028904 - for 1953513428 blocks (244189178 in 4k blocks). The old partition was start 63 and end 2930272064 with 1465136001 blocks. I think lvm takes care of being aligned with the space, so it should all be good.Forgot that I can't go all the way to the end of the disk, otherwise mdadm will switch to using the whole disk rather than the partition on reboot. LVM seems to tolerate this shift, but putting a filesystem directly onto the MD didn't. Recommendation was to shorten the partition by at least 256 sectors, so I did (3907029167-256)/8*8 in
bc
to get 3907028904. Resulting partition is mod 8 == 0, and short by 263 sectors. This problem got me when I did this for another array :(mdadm /dev/md6 --add /dev/sde1
watch the array rebuild. Seems to be rebuilding at a pretty good speed, seems faster than it was with the old drive.
and then remove and readd the other side, so that the superblocks will match.
I'll post my solution, with which I'm profoundly unhappy:
sfdisk -d /dev/good_disk > /root/part.txt
vi /root/part.txt
Increase partition start numbers until they're all multiples of 8 (8 sectors of 512 bytes = 4K).
Increase the size of the extended partition until it covers the entire new disk (which is 1 TB, while the old disk was 500 GB -- when the other disk dies and is replaced, I'll be able to create a new RAID array in the leftover free space.)
sfdisk /dev/new_disk < /root/part.txt -L
(the-L
makes it accept partitions not aligned to cylinder boundaries, otherwise sfdisk aborts without changing anything).I don't like it because it's error-prone and tedious.
As you said, you can allign it to multiples of 8 and you can do it error prone with GNU parted. I will assume /dev/sda is the old good disk and /dev/sdb will be the new one with 4k sector size.
Write down partition sizes. And round them up to 8. We'll use rounded numbers here.
and so on
If you have more than 4 partitions, you will have to set the fourth partition as "extended" and the remaining partitions define as "logical".
Mark you raid partitions with label raid
and so on