LVM Raid 5 on Ubuntu Server 16.04
Background
A while ago we got a new server here at work and I needed to configure it in a very specific way. We wanted an mdadm RAID 1 for boot, and a LVM RAID 5 for the rest of the space. Configuring the mdadm RAID 1 is pretty easy, it’s supported by the 16.04 installer and I didn’t have too much trouble getting it set up. The LVM RAID 5 on the other hand is normally configured after install. I didn’t want to mess with doing it after install, so after some tinkering and hacking I was able to configure the LVM RAID 5 during the install. Let’s take a look.
Configuring the RAID 5
You’re going to want to follow the installer until you get to the portion where you configure disks. If you want any part of the disk(s) to not be included in the RAID then you will want to configure that first. You will need a boot partition outside the RAID at the very least as I had trouble getting grub to see the LVM RAID. For my install it was a mdadm RAID 1.
Once the boot partition has been figured out the drives for the RAID 5 need to be partitioned. For each drive be sure to select the options “Physical Volume for LVM.” After they are all partitioned and formatted, select “Configure the Logical Volume Manager” from the top. If it asks you to write the partitions, choose “yes.”
Now we’re going to crate a volume group. Select “Create Volume Group” from the configuration screen. Give the volume group some kind of name, I named mine “vga” for “volume group a” but you could choose something more descriptive as you see fit. Select wich drives are part of this volume group and add them. I was working with 3 drives and they were sda5, sdb5, sdc5.
Alright, everything has been pretty standard so far, we have a volume group and our drives are all assigned to it. Now is where the install starts to get a little tricky.
We need to get into a console to issue some commands to finish the configuration. To do this press Alt+F2. You may have to press enter once to get the prompt to appear.
Just like if you were going to configure the RAID on the command line after install, we’re going to use the lvcreate command to create the RAID 5. The following command created my RAID volume, but some names and sizes my be different basd on your configuration:
$ lvcreate --type raid5 -i 3 -L 920G -n lva1 vga"
This says: create a logical volume of the type RAID 5. The volume is made up of 3 disks and the volume size is 920 gigs. The volume is named “lva1” and is assigned to vgb (the volume group I created before). It took me a bit of trial and error to fall onto 920 gigs, but if you’re guessing, start high and work backward, so you use as much space as possible.
Return to the installer by pressing Alt+F1. It’s going to look like we left it
and that is because it hasn’t recognized that we created a logical volume.
After all we didnt tell the installer that it was created.
Select “Configure the Logical Volume Manager” at the top, and agree to write partitions if it asks. Then leave the LVM manager. The screen with all the existing drives should be showing, but it probably looks really screwy because the installer doesn’t know how to deal with it. Find the name we gave our logical volume (lva) and set its mount point to / (or wherever you wanted to put it) and then continue the installation as normal.
There you go, now that you have configured LVM RAID 5 duing the install and are ready to move on to configuring the system to do whatever it is you wanted it to do.