What is LVM Mirroring ? Steps To Create LVM Mirror in Linux

| April 23, 2011

In the Computer world storage is most important. If data lost then every thing is lost to the organization or company. Initially data is stored in normal disks, it does not have flexibility to manage the data and it is very complicated to disaster recovery management. To achieve flexibility and goal of the disaster recovery management, RAID is introduced. Using RAID, redundancy can maintained but still does not have flexibility to manage filesystem and storage management. Logical Volume Manager provides higher level view of disk storage. Logical Volume Management is traditionally associated with large installation containing many disks and even very use full in small environment.

Logical Volume Manager have many features, like resizing volume groups online by absorbing new physical volumes(PV) or removing existing physical volume. Resize logical volumes (LV) online by adding or removing physical extents to the existing logical volume. Using LVM you can create read-only as well as read-write snapshots of logical volume. IT is possible to Stripe or Mirror whole or parts logical volumes across multiple PVs, like similar to RAID 0 or RAID 1. It is possible to move online logical volumes between PVs. The LVM will also work in a shared-storage cluster.

Here are the steps to creating LVM mirroring

Step 1. Create a two partition using fdisk command( you can use partition or whole disk). Before creating partition, make sure that, how many cylinders has been used and how many are free.

Example 1: Checking the free space to create partition.

[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 765 6144831 83 Linux
/dev/sda2 766 892 1020127+ 82 Linux swap / Solaris

Above command shows total cylinders 1305 and used cylinders are 892. It means still you have free cylinders, hence we can create partition.

Example: 2 Creating new 3 partition using fdisk.

[root@localhost ~]# fdisk /dev/sda
Press n
Press p
Press “Enter” for default starting cylinder”
Enter 100MB+
Now Change the partition type to 83 and finally reboot the system.
Similarly create one more partition of 100MB.
Note: Make sure that partition ID must be 8e, while creating partitions.

Step 2. Create Physical Volumes

Example: 3

[root@localhost ~]# pvcreate /dev/sda[5,6,7]
Physical volume “/dev/sda5″ successfully created
Physical volume “/dev/sda6″ successfully created
Physical volume “/dev/sda7″ successfully created

Above command will initialize partition as lvm partition. Note: Here LVM will assign PV UUID to the partition only.

Step 3. Create Volume Group

Example: 4

[root@localhost ~]# vgcreate datavg /dev/sda[5,6,7]
Volume group “datavg” successfully created

Above command will crate volume group by name datavg. LVM create VGDA(Volume Group Descriptor Area. The VGDA Contains information about Volume Group. LVM Create PE (Physical Extent)

Step 4. Creating Mirrored Logical Volumes.

[root@localhost ~]# lvcreate -L 50M -m1 -n mirrorlv datavg
Rounding up size to full physical extent 52.00 MB
Logical volume “mirrorlv” created

While creating mirrored volumes in particular volume group, you have to specify the number of copies of the data required, –m argument of the lvcreate command. For creating 1 mirror copy of data, you have to specify the –m1

In above command, we have created 50MB of size logical volume with 1 copy of data to be maintained.

Step 5. Creating File system.

[root@localhost ~]# mkfs /dev/datavg/mirrorlv
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
13328 inodes, 53248 blocks
2662 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=54525952
7 block groups
8192 blocks per group, 8192 fragments per group
1904 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#

Step 6. Mounting Filesystem.

Most commonly used method for mounting filesystem is either manually using mount command or by adding entries in /etd/fstab, so that filesystem mount during boot time.

Syntax:

Mount [option]

Example

[root@localhost ~]# mount /dev/datavg/mirrorlv /database

In above example, we have mounted /dev/datavg/mirrorlv logical volumes to /database directory. You can verify by executing following command.

Tags: , , ,

Category: Linux Administration

Comments are closed.