»

Nov 29 2010

Ubuntu raid 1 resize

Going from 2x320GB HDD Raid 1 to 2x500GB HDD Raid 1 on Ubuntu 10.10

   In this tutorial I’ll show you how I replaced my 2×320 HDD’s with 2×500 HDD’s. In my case the transition was simple because I only needed to resize one partition of the array (the last), leaving the first two untouched. My server setup looks like this :

  1. /dev/md0 – 500 MB for /boot
  2. /dev/md1 – 2 GB for swap
  3. /dev/md2 – 310 GB for /

I only needed to resize the / partition.

First make sure that your system can boot from either of 320 hdd’s.

Make sure your system is configured to boot if you have a degraded array :

1. edit this file /etc/initramfs-tools/conf.d/mdadm
2. change “BOOT_DEGRADED=false” to “BOOT_DEGRADED=true

* You also can use #dpkg-reconfigure mdadm rather than CLI!

Second, shutdown system, replace one of the 320 hdd’s with one 500 hdd.
Start the system, it should boot into degraded mode. If it doesn’t, either check BIOS to boot from the 320 hdd, or reattach the other 320 hdd drive , swap it with the first 320 hdd.
In my case the 500 GB Hdd is now /dev/sda and the 320 gb hdd is /dev/sdb.
Copy partition structure from sdb(320 GB hdd) to sda(500 GB hdd) :

sfdisk -d /dev/sdb | sfdisk /dev/sda

In my case I had to add –force to the command because “partition 1 does not end at a cylinder boundary”.
Now, the 500 GB hdd, has the same partition structure as the smaller 320 GB hdd, this means we have about ~ 160 GB of free space unused.

Enter cfdisk /dev/sda. Delete /dev/sda3 , to add the free space to it. Recreate /dev/sda3 , set type to fd – linux raid. Make sure that /dev/sda1 is marked as bootable.

Add /dev/sda1 to md0, /dev/sda2 to md1, /dev/sda3 to md2:

mdadm -–add /dev/md0 /dev/sda1
mdadm -–add /dev/md1 /dev/sda2
mdadm -–add /dev/md2 /dev/sda3

Linux will start syncing the partitions. Next install grub on dev/sda:

grub-install /dev/sda

Shutdown. Change the 320 hdd with the second 500 GB hdd.
Copy partition structure from sda to sdb (from first 500gb hdd to second 500gb hdd)

sfdisk -d /dev/sda | sfdisk /dev/sdb –force

Re-add sdb to md raid :

mdadm -–add /dev/md0 /dev/sdb1
mdadm -–add /dev/md1 /dev/sdb2
mdadm -–add /dev/md2 /dev/sdb3

Install grub on /dev/sdb :

grub-install /dev/sdb

Restart then grow the md2 array :

mdadm --grow /dev/md2 --size=max

Unmount /dev/md2 : umount /dev/md2

If it’s not working reboot then try to unmount it.

Run filesystem check :

e2fsck -f /dev/md2

Resize the filesystem :

resize2fs /dev/md2

Run filesystem check again :

e2fsck -f /dev/md2

Tested on Ubuntu Server 10.10 x64.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*