Hello everybody!
Watch this video to find out how to create a software LVM RAID on Linux, and how to recover
data from an LV RAID 5 system if you removed it accidentally, or if several disks failed.
lvm RAID is a method to create a logical volume (LV for short) which uses several physical
disks to improve performance or fault tolerance.
Within LVM, physical disks (abbreviated as PV, physical volumes) belong to one volume
group (abbreviated as VG).
Although it is much safer to use MD RAID, if you really need to migrate from conventional
disks to a RAID system without having to change their file systems, this method can be very
useful.
Allocating information with blocks of logical volume data on physical disks is determined
by a specific RAID type.
Watch a special video to learn more about various array types, - I’ll give the link
in the description as always.
LVM RAID technology uses Device Mapper (DM) and Multiple Device (MD) drivers from Linux
kernel.
DM is used to create and manage visible LVM devices, while MD is used to allocate data
onto physical devices.
LVM creates hidden logical volumes (dm devices), kind of placed between the visible volumes
(known as LV, logical volumes) and physical devices.
In a few seconds, I’ll show you how to create a RAID 5 system with 5 hard disks combined
into a single group of logical volumes.
How to format disks and create a virtual group for LV RAID
Use the command lvcreate to create an LV RAID.
If there is no LVM (Logical Volume Manager) tool on your computer yet, install it first
- check one of our previous videos for details.
Install the manager tool with the command: Sudo apt install lvm2.
Use the superuser account to avoid having to enter the password all the time.
Sudo -i Now format the disks with the help of the
disk utility or the terminal.
Just specify the file system and format the disks.
In the terminal, use the fdisk command.
Fdisk /dev/sdb Before you continue, make sure you have selected
the right disk, because this operation erases all data from the disk.
Type n to create a new volume, press p to set it as primary, 1 – the first partition,
then hit Enter twice.
Now let’s get the volume ready to be used with LVM.
Type t – to change the volume type, and then 8e – to assign LVM type.
Check the volume properties by pressing p; after the operation is successful, a new volume
with the name sdb1 appears; press w to record the changes.
In the same way, format all the disks which are not formatted yet.
Now create a physical LVM volume on the partition you have just created, by entering the command
pvcreate: pvcreate /dev/sdb1, and repeat it for each
of the disks: pvcreate /dev/sdс1, pvcreate /dev/sdd1
Combine the disks into a group with the command vgcreate.
vgcreate vg1 /dev/sdb1 dev/sdc1 dev/sdd1
How to create a software LVM RAID 5 To create a software RAID 5 in the LVM virtual
group, type the following command - lvcreate.
lvcreate -n lvr5 --type raid5 -L 10G -i 4 vg1
Where the -n assigns a name to the volume, the --type raid5 specifies the array type,
the -L stands for the size of the logical volume - it is 10 GB in this case, and the
-i indicates the number of devices to be used for data storage.
It doesn’t include an additional device to store parity blocks, though.
The number you give should be 2 or more, because the minimum requirement for this array type
is three disks.
The vg1 part indicates from which volume - or which group, in our case - the space should
be taken.
That’s all, the RAID system has been created, and it needs to be formatted and mounted so
you can start using it.
Format it in ext4. mkfs -t ext4 /dev/vg1/lvr5, file system Ext4,
name of the group and volume name.
Now mount it, mkdir /mnt/lvr5,
mount -t ext4 /dev/vg1/lvr5 /mnt/lvr5, - that’s all, the volume is mounted.
How to check the status of an LVM RAID Run the following command to check the LVM
RAID status: lvs -a -o name,copy_percent,devices vg1
On the screen, you will see the ifnormation on how many devices it includes and what group
they belong to.
How to recover data from LVM RAID 5 If you accidentally removed important information
from an LV RAID system, you can still restore it with the help of Hetman Partition Recovery.
This utility supports data recovery from almost all existing RAID types, and the lost information
will be back in a moment.
At the moment, there is no version of Hetman RAID Recovery for Linux, but it does support
the file systems used in Windows, MacOS, Linux and Unix; the program will fix any errors
in the logical structure of the hard disk and recover all of its contents.
You can run this tool in Linux with the help of a virtual machine, install Windows as the
second operating system on your computer, or connect the disk to a Windows computer.
As you can see, the program has automatically found and identified properties of the LVM
RAID and now displays all the available information about the array.
Right-click on the disk and open its properties to see more details.
In the RAID tab, you can see what disks it includes, and view their IDs, block size and
order.
This information will come in handy when you are going to build an array manually in the
RAID constructor.
That is why it is important to memorize the RAID settings in some way while you are creating
it.
To recover your data, start with running Fast scan - right-click on the disk, Open, Fast
scan -
and when the scan is over, the program will display the results in the right side of the
window.
Removed elements are marked with a red cross.
If the Fast scan doesn’t find the data you need, then use Full analysis.
The next step is to select the files you want to recover, click Recovery, select where you
want to save them, and click Recovery again.
When the process is over, you will find the recovered files in the folder you have selected.
How to recover data from an LV RAID with two non-operable disks
Even with two disks out of order, the program detects the RAID type automatically, and displays
all the information available about this array.
After the Fast scan, it managed to find a part of the data, most of it being damaged,
so let’t run Full analysis to discover more.
As a result, we can find more data wich is still intact.
Now select the files you want to restore, click Recovery, specify the directory where
you’d like to save the data, and click Recovery again.
When the process is over, you will find the recovered files in the folder you have chosen.
If the program couldn’t detect your RAID automatically, use the RAID Constructor.
This is when the more information you have on your array, the better.
Its type, order of blocks, block size, number of bytes in a sector, the disks it included
and their order.
Conclusion LVM is one of the many Linux technologies
to give you more flexibility in managing disk space.
When combined with the RAID technology, it offers good protection against data loss and
an easy way to store, manage and share data.
That is all for now!
Hopefully, this video was useful.
Remember to click the Like button and subscribe to our channel.
Push the bell button to receive notifications and never miss new videos.
Leave comments to ask questions.
Thank you for watching.
Good luck.