Create software RAID and volume groups

From LQWiki
Jump to navigation Jump to search

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

# mdadm /dev/md0 -f /dev/hdb1
# 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:

# mdadm --create /dev/hdb1 --level=1 --raid-devices=1 --force /dev/hdb1
# mkfs.ext3 -T news /dev/md1
# mount /dev/md1 /vault

Create a volume group (currently with only one physical volume) on the other partition:

# pvcreate /dev/hdb2
# vgcreate VolGroup01 /dev/hdb2
# vgchange -a y VolGroup01
# pvdisplay /dev/hdb2 | grep "Total PE"
Total PE  16408
# lvcreate -l 16408 VolGroup01 -n LogVol01
# mkfs.ext3 -T news /dev/VolGroup01/LogVol01
# mount /dev/VolGroup01/LogVol01 /expendable

Copy important stuff off of old RAID group to new /vault:

# cd /vault
# tar cf - -C <old place> <include list of old important stuff> | tar xvf -

Copy less important stuff to new /expendable:

# cd /expendable
# tar cf - -C <old place> <include list of old less-important stuff> | 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:

# mdadm /dev/md1 --add /dev/hdd1

(this makes hdd1 a spare volume)

# mdadm --grow /dev/md1 --raid-devices 2

(and then watch /proc/mdstat to monitor the progress of synchronization)

Add /dev/hdd2 to VolGroup01:

# pvcreate /dev/hdd2
# vgextend VolGroup01 /dev/hdd2

Save volume group configuration to /etc/mdadm.conf:

# echo "DEVICE /dev/hdb1 /dev/hdd1" > /etc/mdadm.conf
# mdadm --detail --scan >>mdadm.conf

(per the mdadm man page -- check /etc/mdadm.conf afterward to delete any extraneous lines)

Extend logical volume LogVol01 onto the new physical volume /dev/hdd2:

# pvdisplay /dev/hdd2 | grep "Total PE"
Total PE   16408
# lvextend -l +16408 /dev/VolGroup01/LogVol01

and finally, extend the filesystem to match the new size of LogVol01:

# umount /expendable
# e2fsck -f /dev/VolGroup01/LogVol01

(this step is required before resize2fs, and it takes a few minutes)

# resize2fs /dev/VolGroup01/LogVol01
# mount /expendable

(which is now twice as big as before)

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