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

15,636

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
Share:
15,636

Related videos on Youtube

Nick
Author by

Nick

Updated on September 17, 2022

Comments

  • Nick
    Nick over 1 year

    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>
    
    • Admin
      Admin over 13 years
      I'm having the same problems. I have just edited the /etc/mdadm.conf as specified. Had to edit it manually, as I couldn't get the echos to work, even with sudo, permission denied. I got the file built this time, but I'm suspecting I'm still going to have problems. Why the chown, and who should the owner be?
  • Nick
    Nick over 13 years
    Awesome, thank you! It's currently re-syncing and when it's done I'll reboot and make sure its all working right. Isn't there a command that makes "cat /proc/mdstat" refresh every 10 seconds or so?
  • Nick
    Nick over 13 years
    Oh, got it! "watch cat /proc/mdstat". Now I can watch paint dry. :)
  • Linker3000
    Linker3000 over 13 years
    Glad its working. You can speed up the sync operation: echo 100000 >/proc/sys/dev/raid/speed_limit_min and then echo 200000 >/proc/sys/dev/raid/speed_limit_max. This will max-out the sync speed at the expense of everything else running on the system
  • Nick
    Nick over 13 years
    OK, something still not quite right. It finished syncing and I rebooted, but it doesn't mount at bootup. I get an error screen that says that "/home/myname/files" could not be mounted. And I have to press "s" to skip it and try the next one. I've added more info to the bottom of my original post.
  • Linker3000
    Linker3000 over 13 years
    I have added a revised mdadm.conf to my answer - pop it in place of the one on your system.
  • Nick
    Nick over 13 years
    EDIT: Actually, the file should be /etc/mdadm/mdadm.conf. That's why it wasn't working. It seems to be starting the array and mounting at boot now. I just need to figure out how to change the permissions on it.
  • Nick
    Nick over 13 years
    Done! chown -R did it. Thanks for all your help!
  • Linker3000
    Linker3000 over 13 years
    You're welcome - glad it's all working. Thanks for spotting the issue with the .conf file - I've edited the original answer.