Growing RAID array

Submitted by Tha-Fox on 2013-07-12

It's sad but true that the need for hard disk capacity grows at least as fast as the disk sizes, maybe even faster. I've personally experienced this with my new camera that produces photos that are about four times the size of the older photos. Recently when I checked the free space status my /home was 94% full and most of the space was taken by photos. Then I decided that it was time for me to learn growing RAID array.

When checking for instructions I came across this excellent guide: https://raid.wiki.kernel.org/index.php/Growing Following it I verified the current status. In the beginning I have three RAID arrays consisting of four identical partitions from four disks. Original disks were 160 GB while the new ones were 500 GB.

    [root(a)host ~]cat /proc/mdstat
    Personalities : [raid1] [raid6] [raid5] [raid4]
    md2 : active raid1 sdc2[4] sdb2[1] sda2[0] sdd2[5]
          2096116 blocks super 1.2 [4/4] [UUUU]
     
    md1 : active raid1 sdd1[3] sdc1[2] sdb1[1] sda1[0]
          1048564 blocks super 1.0 [4/4] [UUUU]
     
    md3 : active raid5 sda3[0] sdc3[2] sdb3[1] sdd3[4]
          456125952 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
     
    unused devices: <none>

    [root(a)host ~]# lsblk                                                                                                                                                                            
     

Because all the four drives in my setup were similar, I had to find the serial numbers in order to separate them from each other. This can be done with hdparm.

    [root(a)host ~]# hdparm -I /dev/sda | head -n 6
     
    /dev/sda:
     
    ATA device, with non-removable media
            Model Number:       SAMSUNG HD161HJ                         
            Serial Number:      S0V3J90QB30563  
     
    After finding out all the serial numbers I removed the first disk from the array. As I have three devices in my array, I have to remove the disk from all the three devices.
     
    mdadm -f /dev/md1 /dev/sda1
    mdadm -f /dev/md2 /dev/sda2
    mdadm -f /dev/md3 /dev/sda3
    mdadm -r /dev/md1 /dev/sda1
    mdadm -r /dev/md2 /dev/sda2
    mdadm -r /dev/md3 /dev/sda3

Then it's time to shut down the computer and do the manual work. After I had switched the disk I got the error telling me to "insert boot media". I realized I had the sda disk first in the boot order. I changed the boot order so that it would use any of the other three disks to boot up. I was able to boot and checked the status to see if the new disk would be there.

    [root(a)host ~]# lsblk
    NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
    sda       8:0    0 465,8G  0 disk  
    sdb       8:16   0 149,1G  0 disk  
    ├─sdb1    8:17   0     1G  0 part  
    │ └─md1   9:1    0  1024M  0 raid1 /boot
    ├─sdb2    8:18   0     2G  0 part  
    │ └─md2   9:2    0     2G  0 raid1 [SWAP]
    └─sdb3    8:19   0   145G  0 part  
      └─md3   9:3    0   435G  0 raid5 /
    sdc       8:32   0 149,1G  0 disk  
    ├─sdc1    8:33   0     1G  0 part  
    │ └─md1   9:1    0  1024M  0 raid1 /boot
    ├─sdc2    8:34   0     2G  0 part  
    │ └─md2   9:2    0     2G  0 raid1 [SWAP]
    └─sdc3    8:35   0   145G  0 part  
      └─md3   9:3    0   435G  0 raid5 /
    sdd       8:48   0 149,1G  0 disk  
    ├─sdd1    8:49   0     1G  0 part  
    │ └─md1   9:1    0  1024M  0 raid1 /boot
    ├─sdd2    8:50   0     2G  0 part  
    │ └─md2   9:2    0     2G  0 raid1 [SWAP]
    └─sdd3    8:51   0   145G  0 part  
      └─md3   9:3    0   435G  0 raid5 /

I saw that the new disk was named sda. First I removed disk cache in order to prevent dataloss in case of a disk failure.

    hdparm -W 0 /dev/sda

Then I copied the partition table from one of the original disk to the new disk and got the following error.

    sgdisk --backup=table /dev/sdb
    sgdisk --load-backup=table /dev/sda
     
    Creating new GPT entries.
    Warning! Current disk size doesn't match that of the backup!
    Adjusting sizes to match, but subsequent problems are possible!
    The operation has completed successfully.

Now we have the partition table but I wanted to grow the third partition in order to get more free space.

    gdisk /dev/sda
    p (Prints the partitions. There should be the old ones copied from one of the older disks.)
    d (Remove older partitions.)
    n (To create a new partition. I went with the defaults until I had to choose the size.)
    +462G (The new size for the partition is 462 GB. I left some unallocated space in the end in order to avoid probelms with rounding errors in disk sizes and such.)
    fd00 (Type to Linux RAID. NB! This seems to be deprecated feature so you do the better choice.)
    w (Writes / saves the changes.)

Since I'm using Syslinux as a bootloader, I have to set an attribute to make the first partition bootable. Let's check that the change was successful right after it.

    sgdisk /dev/sda --attributes=1:set:2
    sgdisk /dev/sda --attributes=1:show

Then we add the new disk to array. This has also be done in three steps since we have three partitions used in three devices.

    mdadm --add /dev/md1 /dev/sda1
    mdadm --add /dev/md2 /dev/sda2
    mdadm --add /dev/md3 /dev/sda3

After that we just repeat this procedure to three other disks. Now that we have one new disk we can use as a source for copying partition table, we don't have to set the partition bootable or adjust the size of the third partition.

When all the disks have been switched we grow the third device which is the one we want to grow.

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

If you use separate /boot then remember that the array synchronization does not copy MBR. So in my case I have to install Syslinux directly to each disk.

The final step is to grow the filesystem. On some filesystems this can be done online. I did it online but then again I had taken backups before starting the whole thing (I bet you did too, right?).

    resize2fs /dev/md3

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.