Home / LVM / Redhat Linux – LVM Volumes Re-layout

Redhat Linux – LVM Volumes Re-layout

In Linux, Logical volume’s layouts need to be changed according to the importance of data and performance of the volume. For example,If the current volume layout is  mirrored and  that volume’s data doesn’t update very frequently then daily backup may enough for the applications in case of disk failure.In these cases, you may get a request to remove the mirror to save the storage space.In some cases, you need to mirror the existing linear volume to provide data redundancy to the filesystem. You can’t convert the existing linear  volume or mirror volume to stripped volume due to LVM’s limitations.


Here we will see that how we can convert the logical volumes from one layout to another layout using LVM command.

How to remove the mirror for existing mirrored logical volume ? (Mirror to Linear)
Mirrored volume can be converted as linear volume using “lvconvert” command on the fly. Here we will see with UnixArena’s typical LAB example. 
 1.Collect the existing volume details which you want to convert.

[root@mylinz ~]# df -h /vol1
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/uavg-mvol1 97M  5.6M   87M   7% /vol1
[root@mylinz ~]#
[root@mylinz ~]# lvs -a -o +devices |grep mvol1
  mvol1    uavg      mwi-ao 100.00m  100.00 mvol1_mimage_0(0),mvol1_mimage_1(0)
  [mvol1_mimage_0] uavg      iwi-ao 100.00m        /dev/sdd1(0)
  [mvol1_mimage_1] uavg      iwi-ao 100.00m        /dev/sde(0)
[root@mylinz ~]#


2.Covert the volume from mirror to linear using “lvconvert” command.

[root@mylinz ~]# lvconvert -m 0 /dev/uavg/mvol1
  Logical volume mvol1 converted.
[root@mylinz ~]# lvs -a -o +devices |grep mvol1
  mvol1   uavg      -wi-ao 100.00m                 /dev/sdd1(0)
[root@mylinz ~]# df -h /vol1
Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/uavg-mvol1   97M  5.6M   87M   7% /vol1
[root@mylinz ~]#

We have successfully converted the logical volume to linear.

How to convert the linear volume to mirrored volume ? or How to mirror the exiting volume ? (Linear to Mirror)
The existing volume can be converted mirrored volume on fly using “lvconvert” command.

[root@mylinz ~]# lvconvert -m 1 /dev/uavg/mvol1
  uavg/mvol1: Converted: 0.0%
  uavg/mvol1: Converted: 100.0%
You have new mail in /var/spool/mail/root
[root@mylinz ~]#
[root@mylinz ~]# lvs -a -o +devices |grep mvol1
  mvol1 uavg mwi-ao 100.00m mvol1_mlog 100.00 mvol1_mimage_0(0),mvol1_mimage_1(0)
  [mvol1_mimage_0] uavg      iwi-ao 100.00m          /dev/sdd1(0)
  [mvol1_mimage_1] uavg      iwi-ao 100.00m          /dev/sde(0)
  [mvol1_mlog]     uavg      lwi-ao   4.00m          /dev/sdf(0)
[root@mylinz ~]#

If you want to specify the disk for mirror,you can give the disk names(/dev/sde & /dev/sdf) in the end of the command.Mirror volume require dedicated log device. If you want to eliminate log device,Go through this article.
Note:If you use –corelog, logs will be kept in memory instead of dedicated disk.

How to convert the linear volume to striped volume ? (Linear to stripped)
At this time, there are no LVM tools to assist with converting a linear/normal LVM logical volume to a striped LVM logical volume from Redhat.
A manual process to achieve a striped logical volume when starting with a linear/normal logical volume,
1.Either copy, stage or backup the data somewhere that it can be accessed later.
2.Create a new LVM striped Logical Volume.
3.Copy/Rsync/restore the data to the new LVM striped LV. If required, logical volumes can be renamed with the lvrename command. 

Root cause:
LVM tools currently do not have the capability to move existing extents, then convert a linear LV to a striped LV. At this time there are no known plans to add this feature.
Note:All the above notes from Redhat.

How to convert stripped logical volume to linear logical volume ? (Stripped to Linear)
1.List the logical volume which you want to convert.

[root@mylinz ~]# lvs -a -o +devices |grep lvol
  lvol0   uavg      -wi-a- 104.00m                  /dev/sdd1(0),/dev/sde(0)
[root@mylinz ~]#


2.Mirror the logical volume lvol0

[root@mylinz ~]# lvconvert -m 1 --corelog /dev/uavg/lvol0
  uavg/lvol0: Converted: 12.5%
  uavg/lvol0: Converted: 100.0%
[root@mylinz ~]#


3.Check the volume details.

[root@mylinz ~]# lvs -a -o +devices |grep lvol
  lvol0   uavg      mwi-a- 32.00m  100.00  lvol0_mimage_0(0),lvol0_mimage_1(0)
  [lvol0_mimage_0] uavg      iwi-ao 32.00m     /dev/sdd1(0),/dev/sde(0)
  [lvol0_mimage_1] uavg      iwi-ao 32.00m     /dev/sdf(0)
[root@mylinz ~]#


4.Now let’s remove the mirror which is using disks /dev/sdd1 & /dev/sde (which was part of stripped).

[root@mylinz ~]# lvconvert -m 0 /dev/uavg/lvol0 /dev/sdd1 /dev/sde
  LV uavg/lvol0_mimage_0 in use: not deactivating
[root@mylinz ~]#


5.We are getting some error or warning from the above command output. Let see what happened to devices.

[root@mylinz ~]# lvs -a -o +devices |grep lvol
  lvol0          uavg      -wi--- 32.00m          /dev/sdf(0)
  lvol0_mimage_0 uavg      -wi-a- 32.00m          /dev/sdd1(0),/dev/sde(0)
  lvol0_mimage_1 uavg      vwi-a- 32.00m
[root@mylinz ~]#


6.lovl0 is on /dev/sdf. So we are good to remove mimage_0 & mimage_1 which are not in use currently.

[root@mylinz ~]# lvremove /dev/uavg/lvol0_mimage_0
Do you really want to remove active logical volume lvol0_mimage_0? [y/n]: y
  Logical volume "lvol0_mimage_0" successfully removed
[root@mylinz ~]# lvremove /dev/uavg/lvol0_mimage_1
Do you really want to remove active logical volume lvol0_mimage_1? [y/n]: y
  Logical volume "lvol0_mimage_1" successfully removed
[root@mylinz ~]# lvs -a -o +devices |grep lvol
  lvol0   uavg      -wi--- 32.00m            /dev/sdf(0)
[root@mylinz ~]#

We have successfully converted the stripped volume to linear volume using above steps.
For your information,the above steps covered “conversion of stripped volume to mirror volume” . Bravo!!!

Thank you for visiting UnixArena. Hope you liked it .

VMTURBO-CLOUD-CAPACITY

Leave a Reply

Your email address will not be published. Required fields are marked *