Setting up RAID1 in Ubuntu

My Ubuntu server has been running for a few years with half a terabyte of photos, TV episodes, and MP3s served up by Samba and ProFTPD. When Glenn, a friend at work, let me know that Newegg had a coupon code bringing the low-power WD Green HDs of the 1TB variety under $80, I decided to buy a couple to upgrade storage and insure against disk failure for my precious audiobooks.
I love Newegg, but somehow neither drive would be recognized by hierax's BIOS nor my desktop's, so back they went. It cost me another $10 to send them back, but when I finally got a couple of good replacement drives, I setup the RAID1 array. It was a lot easier than I expected thanks to mdadm.
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
Installation of mdadm generates a basic config file, but creating a new array doesn't mean it'll be assembled on startup, so you need to add the array to mdadm.conf. The easy way to do this is to have mdadm output the appropriate line for the config.
sudo mdadm -Es >> /etc/mdadm/mdadm.conf
All was well with the world. I started copying everything from the old drives onto a single massive partition on the new array.
cd /ftproot/ab_fiction3/ && sudo tar -cf - . | (cd /ftptmp/ab_fiction/; sudo tar -xpvf -)
I don't know if it's necessary to use tar to copy files between filesystems, but I've been told it's safer than cp. In any event, it took several nights, but eventually I got everything onto the array, even the files from my external HD I'd been using for backups. I had decided to move it onto the server so that I could schedule both my and my wife's machines to backup over the network instead of moving the external HD around, but first I needed to reformat it to ext3.
Since I now had a couple of spare identical 200gb WD Caviar drives, I decided to use them in another RAID1 array for mp3s and family pictures that my wife and I could then share between us. This would free up space on both our data partitions, provide a single location for their storage, and implement redundancy for these very important files.
sudo mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdd1 /dev/sde1
Again I used tar to copy mp3s and pictures from my backup of the backup drive, and soon after decided it was high time to move the server back out of the office, and back into the crawlspace under the stairs. At this point all the drives I wanted to use were in the case and connected, so I could do the rest of the work over the network as I usually do. Success!
What I didn't realize at the time was that the physical partition of the RAID device gets smaller due to a second superblock added to the end, so the RAID device filesystem needs to be resized after creation. I'll describe this procedure with only minimal extraneous info in another post.

No comments:

Post a Comment