Adding a RAID array

The home server (a Tranquil PC BBS2 as I wrote about before) started life with a 2 disk 250G RAID array and soon saw an additional 2 disk 1Tb array added. It’s done us well and just sits there purring away under the stairs serving files to the rest of the house. It’s done the job excellently but over the last few years we’ve been eating through the storage space available. I’ve been conscious that the amounts of data involved are non-trivial and so while there was enough space on the 1Tb array to move all the data from the smaller 250Gb onto it I decided it was time to think about an upgrade.

I bought 2 2Tb drives and copied the data from the small array onto the larger one (there was only around 100G of data). Removing the old drives and inserting the new ones proved to be exceptionally straightforward thanks to the design of the BBS2. The screwless drive enclosures are great.

When the machine was rebooted I found the disks available as /dev/sdd and /dev/sde. What follows is what I *should* have done, but it took me a few attempts to get it done in this order thanks to missing a vital step :-( Thankfully until the drive was happy following reboots I didn’t copy any data to it :-)

Before starting I should say that the BBS is running Ubuntu 10.04 Server edition.

Prepare for Disk Change
Before shutting down to replace the disks I needed to prevent the system trying to use the 250G array when starting. (If you don’t then it generates errors and stops the boot requiring console access.) I did this by

  1. commenting out the /dev/md0 entry in /etc/mdadm/mdadm.conf
  2. commenting out the entry for it’s mount point in /etc/fstab

Once these changes had been made, I shutdown the system

sudo shutdown -p now

Disk Setup

  1. sudo fdisk /dev/sdd
    Create a new primary partition using the entire disk
  2. sudo fdisk /dev/sde
    Create a new primary partition using the entire disk
  3. sudo fdisk -l
    Check the 2 disks (sdd and sde) show the same partition details

At this point a check of /dev shows the expected sdd, sdd1, sde and sde1 listings.

Create the Array
I use /dev/md0 and /dev/md1 for the first 2 arrays, so decided to use /dev/md2 for this array.
mdadm --create --verbose /dev/md2 --level=1 --raid-devices=2 /dev/sdd1 /dev/sde1

This resulted in

mdadm: size set to 1953513472K
mdadm: array /dev/md2 started

To follow progress I watched the output from /proc/mdstat using

watch cat /proc/mdstat

The output looked like this

md2 : active raid1 sde1[1] sdd1[0]
1953513472 blocks [2/2] [UU]
[>....................] resync = 0.0% (875136/1953513472) finish=855.2min speed=38049K/sec

It took slightly less time than initial predictions, but I left it running overnight!

Once it has finished /dev/md2 will exist and be available for formatting, but as I had experienced problems I decided to be cautious and ensure the array was usable through a reboot before formatting it, which meant I needed to add the details to /etc/mdadm/mdadm.conf (yes this was what I forgot to do when I experienced issues).

Add the array details to mdadm.conf
To create the lines needed there is a nice shortcut command
sudo mdadm --detail --scan
This will create output similar to this

ARRAY /dev/md1 level=raid1 num-devices=2 metadata=00.90 UUID=xxxxxxxx:xxxxxxxx:xxxxxxxx:xxxxxxxx
ARRAY /dev/md2 level=raid1 num-devices=2 metadata=00.90 UUID=xxxxxxxx:xxxxxxxx:xxxxxxxx:xxxxxxxx

To add the lines to mdadm.conf I simply did
sudo mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Of course nothing in life is as simple as it first appears, so the file needs to be edited :-(

  1. I removed the duplicate line for /dev/md1
  2. The metadata value doesn’t seem to be recognised as ‘00.90‘ but is happy with ‘0.90‘ so I removed a leading zero.

After saving the file it was time to reboot the machine and make sure that all worked as expected.
sudo shutdown -r now

After restart a quick look at /proc/mdstat showed all was well

cat /proc/mdstat

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sdd[0] sde[1]
1953513472 blocks [2/2] [UU]

md1 : active raid1 sdc1[1] sdb1[0]
976759936 blocks [2/2] [UU]

unused devices:

Formatting the new disk
I formatted the new disk as ext4 using

sudo mkfs.ext4 /dev/md2

After this had completed I needed to add the mountpoint and an entry to /etc/fstab

sudo mkdir /storage/2

To add the entry to fstab I generally use UUID’s, so I needed to find the UUID for the new disk.
ls -l /dev/disk/by-uuid

lrwxrwxrwx 1 root root 9 2012-04-25 15:05 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -> ../../md2

The fstab entry then looked like

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /storage/2 ext4 relatime,errors=remount-ro 1 2

To test that all was working as expected, I simply did

sudo mount -a

No errors were shown and a quick check showed the disk mounted and the sizes as expected.

df -H

Filesystem Size Used Avail Use% Mounted on

/dev/md2 2.0T 205M 1.9T 1% /storage/2

Before copying any data across I decided to make sure that a reboot wasn’t going to cause trouble and so once more I restarted the machine

sudo shutdown -r now

Everything worked and all expected devices were available, mounted where I expected them to be.

It’s taken me a little longer than I expected to get things fully setup, but as last time I did it I didn’t bother noting what I did that’s not a huge surprise. The links below were helpful in figuring out what was needed :-)