September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  
Software RAID: Creating a RAID array in Gentoo
Software RAID: Creating a RAID array in Gentoo

Today I was tasked with converting an existing Gentoo box into a Samba server. This box will be used to store and share documents, but it did not have enough storage for the task. So instead of just adding another drive, I added two drives with the intention of creating a Software RAID 1 array with the drives. This will help to protect the data from hardware issues, and combined with regular backups they should be fairly well protected from user error.

I chose to go Software rather then a hardware controller due to budget constraints. Since I have not created a Software RAID array before, I figured that I may as well document the process.

So first things first. I had to rebuild the kernel to add Multi-device support and block device support anyway, so I went ahead and grabbed the latest stable sources at the same time. This will bring me from 2.6.25 to 2.6.26. (not a large jump, but I prefer to stay current for security reasons. I always rename my kernels and add them to Grub so that I can boot back into the original kernel if there are problems.

Next I needed to install the mdadm tools. with gentoo this is a cake walk.
# emerge mdadm

I then added a primary partition to each new drive and made sure that I changed the partition Id to fd. It should look something like this when you are done.
/dev/sdb1 1 4462 35840983+ fd Linux raid autodetect

Before I could go further I had to create the metadevice nodes
# cd /dev && MAKEDEV md

Now it was time to create the array less one drive.
mdadm –create /dev/md0 –level=1 –raid-disks=2 missing /dev/sdc1
Make sure that the array was created.
# mdadm –detail /dev/md0

Time to tell mdadm utility what the RAID array looks like by writing the description to /etc/mdadm.conf and put a file system on the partitions.
# mdadm –detail –scan >> /etc/mdadm.conf
# mkfs.ext3 /dev/md0
# mkfs.ext3 /dev/sdb1

So far so good, lets see if it will mount, copy some files, and add the second drive.
# mkdir /mnt/md0
# mount /dev/md0 /mnt/md0
# cp -ax /home/* /mnt/md0/
# mdadm –add /dev/md0 /dev/sdb2
Adding the drive took a long time and I watched the progress like this:
# watch -n 1 “cat /proc/mdstat”

WoooHooo! So far so good!
Now lets see if I can mount my new array where it will live. I unmounted the array and added a definition for the new mount location in /etc/fstab:
/dev/md0 /home ext3 defaults 0 0

Finally verify that the array mounts correctly, add the mdadm monitor daemon that comes with Gentoo to the default runlevel, reboot to see if things are truly fine, and clean up the old home files.
# mount /home
# rc-update add mdadm default
# reboot

Once the system rebooted and I verified that the array was mounted as /home I was able to clean up the old files.
umount /home
rm -rf /home/*
mount /home

Now I have a RAID 1 array mounted as /home that I will use for the Samba server which I am installing next.

Share and Enjoy:
  • Facebook
  • Google Bookmarks
  • StumbleUpon

Leave a Reply