Tuesday, 8 January 2013

How to creating LVM mirroring ?


How to creating LVM mirroring ?

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.
 

3 comments:

  1. Good article shankar.

    Just want to add for information -

    You can do online mirroring (LVs) without un-mounting the filesystems incase if you want to migrate your data/volumes on other disks.

    Upto pvcreate command, above steps will be the same. After that you've add the PVs in the VG (where you've have the volumes which need to be migrated) using vgextend command. Once it is added to the VG, you just need to execute below commands.

    Example:
    VG Name: testvg
    Volume Name: testlv
    existing pv/disk name: /dev/sdb1 (100GB)
    New PV/disk Name: /dev/sdc1 (100GB)
    Note: New disk could be bigger than the original disk.

    To create mirror the existing volume on new disk -

    # lvconvert -m 1 /dev/mapper/testvg-testlv /dev/sdc1

    check the progress with lvs command. once it is completed -

    # lvconvert -m 0 /dev/mapper/testvg-testlv /dev/sdb1

    Now, you can remove the old PV/disk from the VG. Cheers !!!

    ReplyDelete