Non-destructively resizing a Linux md RAID1 array

When we recently set up a new Linux web host, I had to configure two 4TB disks into a RAID1 (mirrored) array.

I created whole-disk partitions on the two disks using fdisk, created the array with mdadm, created an ext filesystem on it, and mounted it. Job done, right?

Unfortunately, some time later we noticed the filesystem was only 2TB, not 4TB as we’d expected. This turned out to be caused by a limit on the size of the old-school PCDOS partitions fdisk can create. The fix was to use parted and GPT partitions instead.

I wondered whether it was possible to do this without destroying the array… long story short: it is. (I did back up the data first as a precaution.)

The plan:

  • remove one disk from the array
  • repartition it with parted
  • re-add it to the array
  • sync the array
  • remove the other disk from the array
  • repartition it with parted
  • re-add it to the array
  • sync the array
  • grow the ext filesystem to use the expanded space

Here are the commands, in this case for an md device /dev/md3 made up of /dev/sdc1 and /dev/sdd1:

Remove one disk from the array:

mdadm /dev/md3 --fail /dev/sdd1 --remove /dev/sdd1

Create a gpt partition using most of the disk (the page I copied this from said it would leave 1MB unused at either end):

parted --align optimal /dev/sdd
mklabel gpt
mkpart primary 1 -1

Re-add to the array:

mdadm --add /dev/md3 /dev/sdd1

(This caused a re-sync but it was very quick, which I found surprising; shouldn’t it have had to copy 2TB of stuff?)

Repeat the above for the other disk.

Grow the RAID array:

mdadm --grow /dev/md3 --size=3815318M

(I got to that figure by repeated grows in a binary-chopish fashion. parted reported the partition at 4001G, but passing this to the grow command yielded ‘no space left on device’.)

Finally, resize the filesystem:

resize2fs /dev/md3

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: