- I wanted to build a NFS cum CIFS (samba / smb) server for my home lab. To protect my my data against a disk failure I decided to use RAID1. I also wanted to use LVM on top of my RAID group so that it gives me flexibility in configuring and managing storage for my shares.
Hardware config: Intel Atom D410PT, 4GB RAM, 2 x 1TB disks, 1Gbps Realtek NIC.
After installing debian (squeeze) with the appropriate packages (raidtools etc), here are the actual steps for configuring RAID1 with LVM.
- We will first create GPT partition table on both our member disks (sda & sbb). We are using GPT so that we don’t have any problems upgrading to larger disks in future. Read here for more information on GPT.
Start the Parted Utility.
Now on parted shell, select appropriate disk.
- Create a GPT label on the disk
- We will start GPT partition skipping the first 1MB space and end the partition 1MB before the disk end. Thus auto-aligning the disk partition.
mkpart primary 1 -1
- Verify the GPT partition that we created:
- And quit!
- Repeat the activity for the other disk as well.
- Now that we have prepared our disks, lets create a RAID group using the said disks. The commands mentioned are for creating a RAID1 (mirror) group.
mdadm --create --verbose /dev/md0 --assume-clean --level=1 --raid-devices=2 /dev/sd[ab]1
- Scrub your disks of any stale RAID config information from the member disks.
mdadm --zero-superblock /dev/sd[ab]1
- Now verify the RAID group status.
mdadm --detail /dev/md0
- PS: If your need to stop of delete the RAID group, use the following command:
mdadm -S /dev/md1
- Prepare the /etc/mdadm/mdadm.conf add the following line at the top of the config file
DEVICE /dev/sda* /dev/sdb*
- Update the /etc/mdadm/mdadm.conf with the output of following command
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
- We finished creating a RAID group. Let us now create a LVM volume using the mirror RAID group.- Initialize the meta-device for use by LVM
- Verify the physical volume
- Create a volume group lvm-mirror
vgcreate lvm-mirror /dev/md0
-Verify the details of the created volume group
- Create a logical volume lvm0: 93% of total space in volume group lvm-mirror
lvcreate -l 93%VG -n lvm0 lvm-mirror
- Create a logical volume lvm1: 1% of total space in volume group lvm-mirror
lvcreate -l 1%VG -n lvm1 lvm-mirror
That’s it. Create a filesystem on the LVM devices lvm0 & lvm1, mount them and use them just like any other mounted filesystem.