CS447/647

LVM and RAID Hands-On Assignment

You'll need to be root or use sudo to run many of these commands:
    # Install the packages we need for RAID and LVM:

  1. apt-get install gparted mdadm mutt lvm2
    Configure mail to be "Local Only"
  2. Start GParted: System -> Administration -> GParted
    If you don't have Unallocated Space at the end of your disk, reduce the size of the last partition by 2GB. You'll have to run GParted from the Ubuntu Live CD if your last partition is in use. GParted will not let you resize a partition that is mounted and you can't unmount a partition that's in use.
  3. Click the green check mark to apply.
  4. Create two new unformatted partitions out of the Unallocated Space that are fairly small - about 1GB (1024 MB)
    If you keep them small the RAID operations below will be much faster.
  5. Click the green check mark to apply.

    Write down the two unformatted partitions you just created in the space below. Be sure to substitute your partitions for /dev/sdax and /dev/sday in all the commands below:
    Your /dev/sdax _______________________________________
    Your /dev/sday _______________________________________

  6. Open a few new terminal windows:
    In one run: sudo bash # Use this window to run your commands
    In another run: watch "df -ht ext4; cat /proc/mdstat"
    I refer to this window as your RAID status window below
    Type ^C to stop the watch command

    # Create the RAID

  7. mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdax /dev/sday

    # Save the RAID configuration so it will be there after a reboot

  8. cp /etc/mdadm.conf /etc/mdadm.conf.orig
  9. echo "DEVICE /dev/sdax /dev/sday" > /etc/mdadm.conf
  10. mdadm --detail --scan >> /etc/mdadm.conf
  11. cat /etc/mdadm.conf

    # Create the physical volumes, volume group and logical volume

  12. pvcreate /dev/md0
  13. vgcreate DATA /dev/md0
  14. vgdisplay DATA
  15. lvcreate -l 50%FREE -n data1 DATA # Create volume using 50% of free space
  16. lvdisplay /dev/DATA/data1
  17. mkdir /data1
  18. mkfs -t ext4 /dev/DATA/data1
  19. mount /dev/DATA/data1 /data1
  20. df -h /data1 | tee /tmp/df # save output from df
  21. echo "Still here"> /data1/test

    # Resize the logical volume to use 100% of the available space

  22. umount /data1
  23. lvresize -l 100%FREE /dev/DATA/data1

    # Resize the partition to use all space

  24. e2fsck -f /dev/DATA/data1
  25. resize2fs /dev/DATA/data1
  26. mount /dev/DATA/data1 /data1
  27. cat /data1/test

  28. mdadm /dev/md0 -f /dev/sdax
    # Check the RAID status window - the failed drive is marked with (F)
  29. mdadm /dev/md0 -r /dev/sdax
    # Check the RAID status window - the failed drive is no longer part of the RAID
  30. cat /data1/test
    # Does the test file still exits?
  31. mdadm /dev/md0 -a /dev/sdax
    # Check the RAID status window - watch the drive recover
  32. mutt -f /var/mail/root # Check mail for root - you should have a failure email

    # Add the logical volume to fstab:

  33. cp /etc/fstab /etc/fstab.save
  34. echo "/dev/DATA/data1 /data1 ext4 noauto 0 2" >> /etc/fstab

    # Create the script to submit to Web Campus

  35. script raid.txt
  36. cat /proc/mdstat
  37. vgdisplay
  38. lvdisplay
  39. cat /tmp/df
  40. df -h /data1
  41. tail -1 /etc/fstab
  42. cat /data1/test
  43. exit

    # Reboot and make sure the RAID and LVM still work

  44. reboot
  45. mount /dev/DATA/data1 /data1
  46. cat /data1/test

    # Optional: Remove the LVM and RAID

  47. umount /data1
  48. lvremove /dev/DATA/data1
  49. vgremove DATA
  50. pvremove /dev/sdax
  51. pvremove /dev/sday
  52. mv /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf.save
  53. apt-get remove mdadm
  54. vim /etc/fstab # remove logical volume /dev/DATA/data1
  55. reboot


Last Updated: Tue Feb 21 11:58:04 PST 2012