« HOWTO: Create a new RAID 1 (mirror)HOWTO:Get my USB Logitech Rumblepad working. »

HOWTO Expand a RAID 5 by replacing the disk with lager ones.

22/12/08

HOWTO Expand a RAID 5 by replacing the disk with lager ones.

You can increase the size of your RAID 5 disk array by swapping out each disk in turn with a larger disk. This takes time, a lot of time if you have many disks in your array.

Make a full backup of your data. NOW!!
It is also very important to note that during the process your data is at risk until the resync process has finished. You did complete a full backup didn't you!

The following will need to be repeated for each drive you have in your disk array. The steps can all be done on a running and mounted system if you use reiserfs.


Select the drive you are going to replace and run the following commands. These will firstly mark the drive as faulty so it is no longer used. The second will remove it from the array. You have to do this as you cannot simply remove a good disk from a RAID array.

sudo mdadm -f /dev/md0 /dev/sdd1
sudo mdadm -r /dev/md0 /dev/sdd1

I like to run the following in a separate window. The command displays and re-displays the contents of /proc/mdstat every 7 seconds and shows you the status.

watch -n7 cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]  md0 : active raid5 sdd1[3] sdb1[0] sdc1[1]
      10474112 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
      [=================>...]  recovery = 86.3% (4522932/5237056) finish=0.5min speed=22697K/sec
 
unused devices: <none>

You can now turn off your machine and swap out the old hard drive, adding the new larger one in its place. This drive needs to be partitioned before being added to the array. You must make the partition the full size of the disk or the size you want to use in the new RAID array. For example if the old drive was 250Mb and you are swapping in 1Gb drives you make the partition 1Gb not 250Mb.
You also need to set the partition type or ID to 0xDA - Non-fs data or 0xFD, Linux raid autodetect. I use 0xFD as that is what Ubuntu Linux uses if you install from scratch using RAID.

sudo fdisk /dev/sdd

To get a list of commands that fdisk accepts type 'm', just like the prompt says :)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the DOS compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
 
Command (m for help):

First check it is the right disk with 'p' print the partition table. There should be nothing displayed under the headings , if this was a brand new disk.

n add a new partition to add create the new partition I use a primary partition and set it to number 1. Then accept the defaults for the beginning and ending cylinder, to use the whole disk.

t change a partition's system id to set the id to '0xFD' you type just fd


and finally one last check all is well I print out what will be written with 'p' again.

Command (m for help): p
 
Disk /dev/sdd: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x94de950b
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         652     5237158+  fd  Linux RAID autodetect

Now we can add the new disk to the array with the following:

sudo mdadm --add /dev/md0 /dev/sdd1

You will see that after a few seconds your hard disks burst into life and stay active. The RAID array is being resynced and can take a few minutes to many hours. Time for a coffee :) Running the cat /proc/mdstat with watch at this point you will see the process run through until it is finished. Do not interrupt the process or it will start all over again. You can use your system while this is happening.

Repeat the above steps for all drives in your array before going on to the steps below.
 

So you have now replaced all your disks with larger drives. You can now grow the RAID array

sudo mdadm --grow /dev/md0 --size=max

The array now represents one disk using all of the new available space. If you check the disk usage with the 'df' command nothings has changed! What's up with this?


One last step you must resize the file system on the partition. I use reiserfs so this can be done on the fly while the system is still mounted.

sudo resize_reiserfs -f /dev/md0

Now when you check the disk usage you will see the correct size of the RAID array.


All done!

Pages: 1 · 2

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
What can birds and aeroplanes both do?
antispam test