# Install the packages we need for RAID and LVM:
- apt-get install gparted mdadm mutt lvm2
Configure mail to be "Local Only"
- 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.
- Click the green check mark to apply.
- 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.
- 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 _______________________________________
-
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
- 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
- cp /etc/mdadm.conf /etc/mdadm.conf.orig
- echo "DEVICE /dev/sdax /dev/sday" > /etc/mdadm.conf
- mdadm --detail --scan >> /etc/mdadm.conf
- cat /etc/mdadm.conf
# Create the physical volumes, volume group and logical volume
- pvcreate /dev/md0
- vgcreate DATA /dev/md0
- vgdisplay DATA
- lvcreate -l 50%FREE -n data1 DATA # Create volume using 50% of free space
- lvdisplay /dev/DATA/data1
- mkdir /data1
- mkfs -t ext4 /dev/DATA/data1
- mount /dev/DATA/data1 /data1
- df -h /data1 | tee /tmp/df # save output from df
- echo "Still here"> /data1/test
# Resize the logical volume to use 100% of the available space
- umount /data1
- lvresize -l 100%FREE /dev/DATA/data1
# Resize the partition to use all space
- e2fsck -f /dev/DATA/data1
- resize2fs /dev/DATA/data1
- mount /dev/DATA/data1 /data1
- cat /data1/test
- mdadm /dev/md0 -f /dev/sdax
# Check the RAID status window - the failed drive is marked with (F)
- mdadm /dev/md0 -r /dev/sdax
# Check the RAID status window - the failed drive is no longer part of the RAID
- cat /data1/test
# Does the test file still exits?
- mdadm /dev/md0 -a /dev/sdax
# Check the RAID status window - watch the drive recover
- mutt -f /var/mail/root # Check mail for root - you should have a failure email
# Add the logical volume to fstab:
- cp /etc/fstab /etc/fstab.save
- echo "/dev/DATA/data1 /data1 ext4 noauto 0 2" >> /etc/fstab
# Create the script to submit to Web Campus
- script raid.txt
- cat /proc/mdstat
- vgdisplay
- lvdisplay
- cat /tmp/df
- df -h /data1
- tail -1 /etc/fstab
- cat /data1/test
- exit
# Reboot and make sure the RAID and LVM still work
- reboot
- mount /dev/DATA/data1 /data1
- cat /data1/test
# Optional: Remove the LVM and RAID
- umount /data1
- lvremove /dev/DATA/data1
- vgremove DATA
- pvremove /dev/sdax
- pvremove /dev/sday
- mv /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf.save
- apt-get remove mdadm
- vim /etc/fstab # remove logical volume /dev/DATA/data1
- reboot