How can I add a RAID 1 array in Ubuntu 10.04?

I have an existing Ubuntu 10.04 desktop system setup and running on a hard drive (drive A).

I'd like to add two more hard drives (drives B and C, same size) to the system and mount them as a RAID 1 array.

How do I do that?

I know how to create RAID arrays during the installation, but I don't want to reinstall my system, and I shouldn't have to since my system files will stay on their own drive separate from the RAID array.

I've physically added both drives to the system, and formatted them as EXT3 with gparted.

Ubuntu's disk utility has a "create raid" option, but it won't let me select any of my drives (it thinks they're all full).

I don't mind using mdadm, but I've found several guides that are old, and give conflicting advice. Some say I have to edit an /etc/raidtab file, some say this is done automatically.

What's the current (Ubuntu 10.04) preferred way of adding a RAID 1 to an existing system?

It should turn into a raid at boot, and mount itself in /home/myname/files/.

Extra Info:

/etc/mdadm.conf

DEVICE partitions
ARRAY /dev/md0 level=raid1 num-devices=2 metadata=00.90 UUID=4fd3b193:c6c09dea:46ed9f91:db68f1c3

/etc/fstab

/dev/md0 /home/myname/files auto defaults 0 0

cat /proc/mdstat (after reboot)

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md_d0 : inactive sdb1[1](S)
      1953511936 blocks

unused devices: <none>

Solution 1:

OK,

All the command line stuff - assuming the new drives are /dev/sdb and /dev/sdc - check and make a note of the drives you want to work on. Double check this - you don't want to do anything with your OS disk!!!

All done as root (sudo -i) ...

1) Use fdisk to delete the new partitions as we need them setup differently - for each drive:

 fdisk /dev/sdx (eg: fdisk /dev/sdb)
  • d (delete) the current partition - follow the prompts
  • n (new partition) and create a primary partition the full size of the drive
  • t (type) and set the partition type to fd (linux raid autodetect)
  • w (write) your changes and exit

fdisk help here: http://tldp.org/HOWTO/Partition/fdisk_partitioning.html

2) Create your new RAID array - we'll assume /dev/md0 (the first RAID array)

  mdadm --create /dev/md0 --chunk=128 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1 

3) Format your new array:

  mkfs -t ext3 /dev/md0    

(or use ext4 if you want)

4) You need to create /etc/mdadm/mdadm.conf or your array disappears when you restart the server!

echo "DEVICE partitions" > /etc/mdadm/mdadm.conf
mdadm --detail --scan >> /etc/mdadm/mdadm.conf 

Once you have created this file, view/edit it to make sure that the 'DEVICE partitions' wording is on a line of its own. If the array doesn't start up automatically on reboot, see the more comprehensive .conf file at the end of this answer.

5) Make sure the mount target folder exists:

mkdir /home/myname/files/

6) Add mount to /etc/fstab - add this line at the end

/dev/md0  /home/myname/files  auto   defaults  0 0

You can check that your new RAID array is running and doing its first time sync with this command:

cat /proc/mdstat

EDIT:

Further to the array disappearing on reboot - try the following madam.conf, which includes the line you posted for your array:

# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default, scan all partitions (/proc/partitions) for MD superblocks.
# alternatively, specify devices to scan, using wildcards if desired.
DEVICE partitions

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts
MAILADDR root

# definitions of existing MD arrays
ARRAY /dev/md0 level=raid1 num-devices=2 metadata=00.90 UUID=4fd3b193:c6c09dea:46ed9f91:db68f1c3