At this point we could format the /dev/md3 partition with some filesystem and start using it. But that's the old way of doing it. What we want to do is run LVM2 on top of the RAID5 partition so we can better utilize the space provided by the /dev/md3 partition, allowing us to dynamically create, resize and remove volumes in the space provided.
Create the LVM2 partitions
In order to use LVM2 we first have to create a LVM2 Physical Volume:
So, we see here that the three 100MB loopback files have been combined to a 200MB RAID5 LVM2 Physical Volume (3 disks - 1 parity = 2 disks * 100 MB = 200MB usable space)
Next we will create a LVM2 Volume Group:
From the vgdisplay command we should note the Free PE size value. PE stands for Physical Extends and it the minimum amount of storage unit that we can use to create our final LVM2 volumes. Basically we have 49 PE to allocate as we wish for LVM2 volumes. Each PE is 196MB / 49 = 4MB of size.
Let's create a LVM2 Logical Volume with 20 PE (20 * 4MBs = 80MB):
Finally, the LVM2 volume has been created. Let's see what's left from the lvm-group Volume Group:
OK. The allocated PE are 20 and we have another 29 unallocated.
Create the mountable volume
The newly created LVM2 volume is unformatted:
Now let's mount it:
So, now we finally have a 80MB volume that is sitting atop a RAID5 partition.
Let's put some files in the this volume so we can test if the tests we will run later on will make us lose our data.
As long as the **test.txt** file is there through all our following tests, then our data is safe.
LVM2 Manipulation
Let's play with the 49 available PE given to us from the lvm-group Volume Group.
Add more volumes
Create another LVM2 Logical volume:
Now we have another volume with 10 PE (40MB).
Resize volumes
We have myVolume with 20 PE and myVolume2 with 10 PE. We should have 19 PE still unallocated.
Let's increase the size of myVolume by 10 PE:
Do we still have our files?
So far so good.
Remove volumes
We have another volume, myVolume2 that we created for fun for 10 PE (40 MB). Let's remove it and reclaim the space:
So, now we have 19 free PE. The allocated 30 are from myVolume (20 initial + 10 after the resize)