LVM Mirroring: Protect your data from a disk failure !

 

This article explains how to protect your data from a disk failure with LVM Mirroring  (Logical Volume Manager).

Contents:

  • Logical Volume Manager?
  • LVM Mirroring
  • Let’s begin

 

1- Logical Volume Manager:

LVM is a software storage manager for a computer (Linux Kernel), it is integrated with the Device Mapper module and it is commonly used as a storage manager by default in most Linux distributions such as CentOS, RedHat, Fedora, etc..

This technology grouped several physical disks into a single volume group and this volume group can be divided to many logical volume.

With LVM, it is possible to create, resize and move a logical volume without the need to stop your operating system.

LVM

LVM

The LVM has other benefits such as the striping (increase read/write performance) and the mirroring (High Availability/Fault Tolerance of a physical disk) that are inherited from the storage technology RAID.

 

2- Mirroring :

The LVM can duplicate (Mirror) a logical volume on two different physicals volumes for the high availability of logical volumes/storage space. If a physical volume fails, the data is present on the second disk and it is still accessible.

 

LVM-Mirroring-Eng

Mirroring with LVM (High Availability)

 

3- Let’s begin:

  • Preparing a physical volume:

For the implementation of this method, I have two disks, each one has 1 GB size ( /dev/sdb, /dev/sdc).

I want to create for each disk a 8e partition type:

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.22.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x7a30efa1.
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 209711):
Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Note: Do the same for the second disk /dev/sdc

Verify the type of partitions:

# fdisk –l /dev/sdb
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcfa41577
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2097151 1047552 8e Linux LVM 

Note: Do the same for the second disk /dev/sdc to verify.

The pvcreate command creates a physical volume. One or many partitions  can be specified.

 # pvcreate /dev/sdb1 /dev/sdc1
  • Create a volume Group « vg1 »

The vgcreate command creates a Volume Group “vg1″ with two physical volumes.

# vgcreate vg1 /dev/sdb1 /dev/sdc1

The vgdisplay commande displays the details of a volume groupe:

# vgdisplay -v vg1
  • Create a logical volume:

The lvcreate commande is the responsable of creating one or many logiques volumes. The m parameter is to create a mirroir followed by the number of mirroir, the L parameter indicate the size and the n parameter for the nom of the logical volume:

# lvcreate -m 1 -L 500M -n lv_mirror vg1

The lvdisplay command is to consult the logical volume informations, the m parameter is to verify that the logical volume have a mirroir or not:

 # lvdisplay -m /dev/vg1/lv_mirror

The lvdisplay command is to consult the logical volume informations, the m parameter is to display the mapping of logical extents to physical volumes and physical extents, on this case we have two disks so the data is saved on the second disk.

 # pvdisplay -m /dev/sdb1 /dev/sdc1

When we have many disks more than two, the LVM have the possibility to precise on wicth disk make the mirror with the corelog parameter.

# lvcreate -m 1 -L 500M -n lv_mirror --corelog vg1 /dev/sdb1 /dev/sdc1

Note: If you have an old logical volume and you added a new disk, the LVM can make a mirror on your new disk.

The lv_old logical volume doesn’t have a mirroir, so with the lvconvert command you can make a mirror for your data.

 # lvconvert -m 1 /dev/vg1/lv_encien

Note:

You can create a logical volume with LVM:

# lvcreate -n lv_new -L 10M vg1

The logicals volumes are under /dev/mapper and /dev/vg1/:

# ls -l /dev/mapper/
# ls -l /dev/vg1/

The logical volume is a bloc type, to mount this partition you should create a system file with the mkfs command:

 # mkfs -t ext3 -L "LV_NEW" /dev/vg1/lv_new

Conclusion:

With LVM, we have the possibility to create a High avalability (Fault Tolerance) environment for your disk.

 

Bookmark the permalink.
Loading Facebook Comments ...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.