In this guide, we’ll explore the methods applied to create a software LVM RAID in Linux. Also, we will show you a simple solution to recover any data lost from an LV RAID 5 system as a result of accidental removal or unexpected drive failure.
LVM RAID is a method to create a logical volume (LV) 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 (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. Check the video link below for some basic information about various types of disk arrays.
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.
Now let’s see how to create a RAID 5 system with 5 hard disks combined into a single group of logical volumes.
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. Follow the link below to check our special video for details.
Install the manager with the help of the command prompt tool in charge of interacting with the package management system. Type the following command: sudo apt install lvm2.
Perform all actions from the superuser account. For this purpose, type the command sudo -i. It will remove the requirement to enter the password every time.
After that, use the disk utility or Terminal to allocate the disk space. Just select the necessary file system type and start the process of formatting the drives.
With the Terminal, use a special system command fdisk /dev/sdb.
Before the format process starts, make sure you have chosen the right drive, because this operation will make all data on the selected drive disappear (the operating system will erase it.
Specify the format settings by typing the following attributes, one by one:
- n – to create a new partition,
- p – to set the partition value as primary,
- 1 – to assign a partition number. After that, press the Enter key twice to agree with the size of the first and the last sector.
Now let’s deal with LVM settings. Apply the following attributes, each in its own line:
- t – to start the process of modifying the type of the new partition,
- 8e – to set the value for LVM.
Make sure that the new partition is of the required type. In the command prompt, type the attribute p. The operating system will process your request and show the data in the form of a table. The device will be marked with the value sdb1 and have the system type Linux LVM. After that, record the changes with the attribute w. Repeat this procedure for all unformatted drives and allocate their disk space.
Our further actions will be intended to create a physical volume in the new partition. Type the command pvcreate /dev/sdb1.
Repeat the command for every drive, replacing the value sdb1 with the corresponding drive names (sdc1, sdd1, sde1, sdf1).
Now combine all the drives into one group. In the command prompt, type vgcreate, listing the created disks. In our example, the command looks like this: vgcreate vg1 /dev/sdb1 dev/sdc1 dev/sdd1 dev/sde1 dev/sdf1.
The attribute vg1 is the name of a new volume group.
The process of creating a software RAID 5 suggests running a simple command in the Terminal:
lvcreate -n lvr5 –type raid5 -L 10G -i 4 vg1
In our example, the command contains the following attributes:
- -n – to assign a name to the volume.
- –type raid5 – to set the array type.
- -L – to set a size limit for the logical volume (in our example, its size is 10 GB).
- -i – to indicate the number of devices involved to store user data. 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.
- vg1 – to tell the operating system where to take the required disk space from (specify a particular volume or an entire group). After the command is performed successfully, the process of rebuilding a RAID 5 system in an LVM virtual group is over. The last step is to format the array and mount it. For RAID 5, we select the ext4 format. Type the command:
mkfs -t ext4 /dev/vg1/lvr5
This command contains information on the file system we have selected – ext4, the group name – vg1, and the volume name lvr5.
Now mount the new disk array. Type the command mkdir /mnt/lvr5, and follow it with mount -t ext4 /dev/vg1/lvr5 /mnt/lvr5.
When these commands are performed, the selected volume will be mounted.
Run the following command to check the LVM RAID status:
lvs -a -o name,copy_percent,devices vg1
Here you can view the information that includes data on the devices and groups involved.
If you lost important data and it needs to be recovered, try a specialized recovery tool from Hetman Software. The product you need is Hetman RAID Recovery.
This software solution supports recovery of lost files from almost all known RAID types. The program lets you recover the lost data easily and quickly, and it doesn’t require special skills or professional background. Unfortunately, it is impossible to install this tool onto a Linux computer. However, it can identify and interact with all main file systems which are used in Linux, Unix, MacOS, and Windows. Also, the program can find and fix various software logical errors which enables it to recover as many user files as possible.
When it is mission-critical to use Hetman RAID Recovery in Linux, here are the three methods to choose from. Start a virtual machine; install Windows as your second operating system, or connect the faulty drives to the computer where Windows is installed as the primary operating system.
As you start it, the program automatically finds and identifies properties of the LVM RAID and displays all the available information about the array.
To learn more, right-click on the storage device and select Properties in the context menu. Otherwise, use the key shortcut Alt + Enter.
In the RAID tab of the Properties window you can see various information about this array. For example, view the disks that make it up, their serial numbers, size and block 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.
In the new recovery wizard window, check the option for Fast scan. After that, click Next. The program will analyze the storage device, identify lost data and display deleted files, labeling them with a red cross. After that, select the elements you want to recover. Click on the Recovery button.
Even with two drives down, Hetman RAID Recovery was able to identify the array type and provide all relevant information about it.
After a quick scan, all the discovered elements are displayed in a separate window. However, most of them are damaged.
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.