Create software RAID and volume groups

Background: I installed two 120 marketing "gigabyte" (120 000 000 000 bytes, more or less -- really 111 GB) hard drives that I didn't configure real intelligently when I first set them up. They had a single 111 GB partition each, and the partitions were both part of a single (111 GB) RAID group.

After I used this configuration for a while, I realized that not everything I had on these disks needed to be RAID-protected -- there are some things that I can live without in the case of a disk failure. So, the project was to break up these disks into important (/vault) and less-important (/expendable) sections. I was able to accomplish this without using any external backup device -- just the 2 disks. I learned a bit about Linux software RAID tools and the logical volume manager (LVM) in the process.

Detailed steps:

Original: RAID group (/dev/md0)- 111 GB /dev/hdb1 - 111 GB /dev/hdd1 - 111 GB

Break RAID group
 * 1) mdadm /dev/md0 -f /dev/hdb1
 * 2) mdadm /dev/md0 -r /dev/hdb1

Using fdisk, delete /dev/hdb1 and create two new partitions: /dev/hdb1 - 47 GB /dev/hdb2 - 64 GB

Create a new RAID group with only /dev/hdb1 as a member:
 * 1) mdadm --create /dev/hdb1 --level=1 --raid-devices=1 --force /dev/hdb1
 * 2) mkfs.ext3 -T news /dev/md1
 * 3) mount /dev/md1 /vault

Create a volume group (currently with only one physical volume) on the other partition: Total PE 16408
 * 1) pvcreate /dev/hdb2
 * 2) vgcreate VolGroup01 /dev/hdb2
 * 3) vgchange -a y VolGroup01
 * 4) pvdisplay /dev/hdb2 | grep "Total PE"
 * 1) lvcreate -l 16408 VolGroup01 -n LogVol01
 * 2) mkfs.ext3 -T news /dev/VolGroup01/LogVol01
 * 3) mount /dev/VolGroup01/LogVol01 /expendable

Copy important stuff off of old RAID group to new /vault:
 * 1) cd /vault
 * 2) tar cf - -C  | tar xvf -

Copy less important stuff to new /expendable:
 * 1) cd /expendable
 * 2) tar cf - -C  | tar xvf -

At this point, everything lives on /dev/hdb. Now use fdisk to delete /dev/hdd1 and create new /dev/hdd1 and /dev/hdd2, with the same capacity as hdb1 and hdb2 respectively.

Add /dev/hdd1 to the RAID group: (this makes hdd1 a spare volume) (and then watch /proc/mdstat to monitor the progress of synchronization)
 * 1) mdadm /dev/md1 --add /dev/hdd1
 * 1) mdadm --grow /dev/md1 --raid-devices 2

Add /dev/hdd2 to VolGroup01:
 * 1) pvcreate /dev/hdd2
 * 2) vgextend VolGroup01 /dev/hdd2

Save volume group configuration to /etc/mdadm.conf: (per the mdadm man page -- check /etc/mdadm.conf afterward to delete any extraneous lines)
 * 1) echo "DEVICE /dev/hdb1 /dev/hdd1" > /etc/mdadm.conf
 * 2) mdadm --detail --scan >>mdadm.conf

Extend logical volume LogVol01 onto the new physical volume /dev/hdd2: Total PE  16408
 * 1) pvdisplay /dev/hdd2 | grep "Total PE"
 * 1) lvextend -l +16408 /dev/VolGroup01/LogVol01

and finally, extend the filesystem to match the new size of LogVol01: (this step is required before resize2fs, and it takes a few minutes) (which is now twice as big as before)
 * 1) umount /expendable
 * 2) e2fsck -f /dev/VolGroup01/LogVol01
 * 1) resize2fs /dev/VolGroup01/LogVol01
 * 2) mount /expendable

Add /vault and /expendable to /etc/fstab, but comment them out, and reboot. If you can successfully mount both after the reboot, uncomment them and reboot again.

= See also =
 * softwAre RAID