Raid1 With Lvm From Scratch
linux technical data tutorialIn this manual will be created RAID1 with LVM. In this tutorial, disk are mounted in system as /dev/sdX and /dev/sdY
Prerequisites
- 2 empty HDDs with same capacity
- Kernel with LVM
- lvm2
- parted
Software
Install lvm2 package
Install parted
Disk partitions create
Create partitions on both disks with parted
Start parted for /dev/sdX disk
Set units to mib
Create GPT table on disk
Create primary partition, use all available space
Set partition name to raiddata0
Add lvm flag to new partition
Result should be:
Execute same parted commands for /dev/sdY
LVM
Next steps will be to create physical volumes on both disks, add both physical volume to same volume group and create logical volume with raid1 logic
Physical volume
Create physical LVM volumes on first disk on first partition
Create physical LVM volumes on second disk on first partition
Volume group
Include both physical volumes to one volume group with name *raid0vg0*
Now both disks in same volume group.
Logical Volume
Create logical volume with name *raid0lv0* on volume group *raid0vg0* with RAID1 logic, use all available space. --nosync means skip the initial synchronization for raid1 (because this is new raid without any data on it)
Now raid1 created on both disks /dev/sdX and /dev/sdY . Last step left - create FS and mount this FS on boot. see section below
EXT4 Filesystem (non encrypted)
Create filesystem on VolumeGroup *raid0vg0* on logical volume r*aid0lv0*
Done
Mount filesystem on boot
Run blkid to find UUID of ext4 filesystem on our LVM raid1
- UUID="10092fa9-43f5-421e-a0a1-ca96323c6388"* is id of our ext4 filesystem on raid1. Last thing is to add fs uuid to fstab
Create mountpoint /mnt/data
Add to fstab mounting
... UUID=10092fa9-43f5-421e-a0a1-ca96323c6388 /mnt/data ext4 defaults 0 2 ...
EXT4 Filesystem (encrypted with LUKS)
Create luks AES encrypted partition on top of Volume Group *raid0vg0* in Logical Volume *raid0lv0* (raid1)
Map encrypted luks disk as *raid0lv0encripted*
Create EXT4 filesystem in luks disk
Mount LUKS encrypted device on boot from LVM raid1
First, create directrory, that will contain keys for encrypting/decryption devices
Create 4k keyfile with name main
Add main keyfile to list of keys, that can decrypt disk (technically: add keyfile to LUKS slot)
Find id of LUKS device (should be same as LV raid0lv0)
In our case it is UUID="cd5740a1-b642-4359-a0b9-af84a8f01092"
Add to file /etc/conf.d/dmcrypt
Add dmcrypt to be started at boot
Create mountpoint /mnt/data
Find EXT4 filesystem UUID
In our case it is UUID="fc7ec587-35e4-4726-815d-e1693cd89b70"
Add to fstab mounting
... UUID=fc7ec587-35e4-4726-815d-e1693cd89b70 /mnt/data ext4 defaults 0 2 ...
Check LVM RAID1 status
To check lvm raid status for volume group raid0vg0
Performance tunnig
It is possible to tunne performance for raid1. By default, in raid1 all disk have same rangs for read/write. If one of disks are much slower then another, it possible to improve WRITE performance (with small penalty of read performance) for such scenario with disabling read from slowest drive.
In such scenario, slowest drive will only write data (without reading), and faster drive will read/write data.
root #lvchange --raidwritemostly /dev/sdb1 raid0vg0Logical volume raid0vg0/raid0lv0 changed.
Where /dev/sdb1 - physical drive in vg0 (slowest drive), raid0vg0 - volume group