{"id":713,"date":"2012-07-13T15:49:20","date_gmt":"2012-07-13T07:49:20","guid":{"rendered":"http:\/\/rmohan.com\/?p=713"},"modified":"2014-05-29T11:21:26","modified_gmt":"2014-05-29T03:21:26","slug":"lvm-in-linux","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=713","title":{"rendered":"LVM in linux"},"content":{"rendered":"<p>LVM in linux<\/p>\n<div><\/div>\n<div id=\"post-body-2011085337493143908\">\n<div dir=\"ltr\">Logical Volume Management[LVM]<\/p>\n<div align=\"LEFT\">LVM\u00a0is a\u00a0logical volume manager\u00a0for the\u00a0Linux kernel; it manages disk drives and similar mass-storage devices, in particular large ones. The term &#8220;volume&#8221; refers to a disk drive or partition.<br \/>\nEvery system contains\u00a0<strong>Physical Volums[PV]<\/strong>. Such as hard disks, partitions or external storages. Volume management treats\u00a0<strong>PV<\/strong>s as sequences of chunks called\u00a0<strong>Physical<\/strong><strong>\u00a0Extents<\/strong><strong>\u00a0(PEs)<\/strong>. There is an another concept also.\u00a0<strong>Logical Extents(LE)<\/strong>. Each\u00a0<strong>LE\u00a0<\/strong>maps one-to-one\u00a0<strong>PE<\/strong>. The system pools\u00a0<strong>LE<\/strong>s into a\u00a0<strong>Volume Group (VG)<\/strong>. We can extend this\u00a0<strong>VG<\/strong>\u00a0by adding a group of\u00a0<strong>Logical extents<\/strong>\u00a0to it from anywhere at anytime.<\/div>\n<div align=\"LEFT\"><strong>Uses of LVM:<\/strong><\/p>\n<ol>\n<li>Extending the partitions online<\/li>\n<li>Grouping of hard disks<\/li>\n<li>Reducing the partitions \/ hard dsik size (offline)<\/li>\n<li>Increasing the performance<\/li>\n<li>Taking Backup (SNAPSHOT)<\/li>\n<\/ol>\n<\/div>\n<div align=\"LEFT\"><strong>Example:<\/strong><\/div>\n<div align=\"LEFT\">Here we are going to discuss a\u00a0<strong>Volume Group(VG)<\/strong>\u00a0created from 3<strong>Physical Voumes(PV)<\/strong>. And in that\u00a0<strong>VG<\/strong>\u00a0we&#8217;ll create two\u00a0<strong>Logival Volumes(LV)\u00a0<\/strong>And mount it to\u00a0<strong>\/linux1<\/strong>\u00a0and\u00a0<strong>\/linux2\u00a0<\/strong>respectively.<\/div>\n<div align=\"LEFT\">Now first of all in our example, we have 3 partitions. In real industry it may be 3 different hard disks.<\/div>\n<div align=\"LEFT\">Let it be (1)\u00a0<strong>\/dev\/sda5<\/strong>\u00a0(2)\u00a0<strong>\/dev\/sda6<\/strong>\u00a0(3)\u00a0<strong>\/dev\/sda7\u00a0<\/strong>each of size<strong>300Mb<\/strong>.<\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# fdisk -l<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 429 465 297171 8e Linux LVM<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 466 502 297171 8e Linux LVM<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 503 539 297171 8e Linux LVM<\/strong><\/div>\n<div align=\"LEFT\"><strong><br \/>\n<\/strong><br \/>\n<strong>Steps:<\/strong><\/div>\n<div align=\"LEFT\">First we will convert this partions(hard disks) into\u00a0<strong>Physical Volumes(PV).<\/strong>Then we&#8217;ll create a\u00a0<strong>Volume Group (VG)\u00a0<\/strong>from those\u00a0<strong>PV s.<\/strong>\u00a0Then inside that\u00a0<strong>VG,\u00a0<\/strong>We&#8217;ll create two\u00a0<strong>Logical Volumes (LV)\u00a0<\/strong>and we&#8217;ll mount those for use.<\/div>\n<div align=\"LEFT\"><strong><span style=\"text-decoration: underline;\">Step1: Creating Physical Volume(PV)s.<\/span><\/strong><\/div>\n<div align=\"LEFT\">Partitions or disks can be converted into\u00a0<strong>PV s<\/strong>\u00a0using the following Command.<\/div>\n<div align=\"LEFT\"><strong>#pvcreate PARTITION_NAMES<\/strong><\/div>\n<div align=\"LEFT\"><strong>#pvcreate \/dev\/sda5 \/dev\/sda6 \/dev\/sda7<\/strong><\/div>\n<div align=\"LEFT\">or as below<\/div>\n<div align=\"LEFT\"><strong>#pvcreate \/dev\/sda{5,6,7}<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvcreate \/dev\/sda5 \/dev\/sda6 \/dev\/sda7<\/strong><\/div>\n<div align=\"LEFT\"><strong>Physical volume &#8220;\/dev\/sda5&#8221; successfully created<\/strong><\/div>\n<div align=\"LEFT\"><strong>Physical volume &#8220;\/dev\/sda6&#8221; successfully created<\/strong><\/div>\n<div align=\"LEFT\"><strong>Physical volume &#8220;\/dev\/sda7&#8221; successfully created<\/strong><\/div>\n<div align=\"LEFT\"><strong>\u00a0<\/strong><\/div>\n<div align=\"LEFT\"><strong>Monitoring or verifying the PV s:<\/strong><\/div>\n<div align=\"LEFT\">You can verify the\u00a0<strong>PV s<\/strong>\u00a0using following commands,<\/div>\n<div align=\"LEFT\"><strong>#pvscan<\/strong><\/div>\n<div align=\"LEFT\"><strong>#pvdisplay<\/strong><\/div>\n<div align=\"LEFT\"><strong>#pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 lvm2 &#8212; 290.21M 290.21M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 lvm2 &#8212; 290.21M 290.21M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 lvm2 &#8212; 290.21M 290.21M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><span style=\"text-decoration: underline;\"><strong>Step2: Creating Volume Group(VG):<\/strong><\/span><\/div>\n<div align=\"LEFT\">The\u00a0<strong>Physical Volumes\u00a0<\/strong>are grouped into one to make it a\u00a0<strong>Volume Group(VG).\u00a0<\/strong>It can be done using the following command.<\/div>\n<div align=\"LEFT\"><strong>#vgcreate VG_NAME PV_NAMES<\/strong><\/div>\n<div align=\"LEFT\"><strong>#vgcreate oracle \/dev\/sda5 \/dev\/sda6 \/dev\/sda7<\/strong><\/div>\n<div align=\"LEFT\">or as below<\/div>\n<div align=\"LEFT\"><strong>#vgcreate oracle \/dev\/sda{5,6,7}<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">It will have a appoximate size of\u00a0<strong>900(300+300+300).<\/strong>\u00a0Some part will for writing headers LE and making LE-PE mapping.<\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgcreate oracle \/dev\/sda5 \/dev\/sda6 \/dev\/sda7<\/strong><\/div>\n<div align=\"LEFT\"><strong>Volume group &#8220;oracle&#8221; successfully created<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgs<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV #LV #SN Attr VSize VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>oracle 3 0 0 wz&#8211;n- 864.00M 864.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>\u00a0<\/strong><\/div>\n<div align=\"LEFT\"><strong>Monitoring or verifying the VG s:<\/strong><\/div>\n<div align=\"LEFT\">You can verify the\u00a0<strong>VG s<\/strong>\u00a0using following commands,<\/div>\n<div align=\"LEFT\"><strong>#vgscan<\/strong><\/div>\n<div align=\"LEFT\"><strong>#vgdisplay<\/strong><\/div>\n<div align=\"LEFT\"><strong>#vgs<\/strong><\/div>\n<div align=\"LEFT\">Output of #vgs is shown above the picture.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><span style=\"text-decoration: underline;\"><strong>Step3: Creating Logical Volumes In Volume Group:<\/strong><\/span><\/div>\n<div align=\"LEFT\">Now we got a volume group &#8220;<strong>Oracle<\/strong>&#8221; of size as the total size of all individual disks\/partitions. Now we can create\u00a0<strong>Logical Volumes\u00a0<\/strong>or usable partitions inside it. We will create two logical Volumes\u00a0<strong>lvm1<\/strong>\u00a0and\u00a0<strong>lvm2<\/strong>\u00a0of size\u00a0<strong>100Mb<\/strong>\u00a0each.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">The lvm1 and lvm2 can be created using the following commands.<\/div>\n<div align=\"LEFT\"><strong>#lvcreate -L SIZE -n LV_NAME VG_NAME<\/strong><\/div>\n<div align=\"LEFT\"><strong>#lvcreate -L 100M -n lvm1 oracle<\/strong><\/div>\n<div align=\"LEFT\"><strong>#lvcreate -L 100M -n lvm1 oracle<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvcreate -L 100M -n lvm1 oracle<\/strong><\/div>\n<div align=\"LEFT\"><strong>Logical volume &#8220;lvm1&#8221; created<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvcreate -L 100M -n lvm2 oracle<\/strong><\/div>\n<div align=\"LEFT\"><strong>Logical volume &#8220;lvm2&#8221; created<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>\u00a0<\/strong><\/div>\n<div align=\"LEFT\"><strong>Monitoring or verifying the LV s:<\/strong><\/div>\n<div align=\"LEFT\">You can verify the\u00a0<strong>LV s<\/strong>\u00a0using following commands,<\/div>\n<div align=\"LEFT\"><strong>#lvscan<\/strong><\/div>\n<div align=\"LEFT\"><strong>#lvdisplay<\/strong><\/div>\n<div align=\"LEFT\"><strong>#lvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm1 oracle -wi-a- 100.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm2 oracle -wi-a- 100.00M<\/strong><\/div>\n<div align=\"LEFT\">The Logical Voumes lvm1 and lvm2 should be formatted(making filesystem in those) before mounting it. Then only you can use those partitions.<\/div>\n<div align=\"LEFT\">Here formatting in ext3:<\/div>\n<div align=\"LEFT\"><strong>#mkfs.ext3 \/dev\/oracle\/lvm1<\/strong><\/div>\n<div align=\"LEFT\"><strong>#mkfs.ext3 \/dev\/oracle\/lvm2<\/strong><\/div>\n<div align=\"LEFT\">Making Mount Points:<\/div>\n<div align=\"LEFT\"><strong>#mkdir \/linux1<\/strong><\/div>\n<div align=\"LEFT\"><strong>#mkdir \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Mounting (Temporary):<\/div>\n<div align=\"LEFT\"><strong>#mount \/dev\/oracle\/lvm1 \/linux1<\/strong><\/div>\n<div align=\"LEFT\"><strong>#mount \/dev\/oracle\/lvm2 \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><strong>\u00a0\u00a0<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# mount<\/strong><\/div>\n<div align=\"LEFT\"><strong>[Output truncated]<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm1 on \/linux1 type ext3 (rw)<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm2 on \/linux2 type ext3 (rw)<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><span style=\"text-decoration: underline;\"><strong>Extending a Logical Volume (Online):<\/strong><\/span><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Now We have a Volume group &#8220;oracle&#8221; of size about 900Mb. And two Logical vloumes lvm1 and lvm2 mounted on \/linux1 and \/linux2 respectively. Each having 100Mb size. Now we&#8217;ll extend the size of lvm1 by 100Mb.<\/div>\n<div align=\"LEFT\">Extending size of a LV can be done online, That is by keeping them mounted. It can be achived by executing following command.<\/div>\n<div align=\"LEFT\"><strong>#lvextend -L +SIZE THE_PATH_OF_LV<\/strong><\/div>\n<div align=\"LEFT\"><strong>#lvextend -L +100M \/dev\/oracle\/lvm1<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Before:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm1 oracle -wi-ao\u00a0100.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm2 oracle -wi-ao 100.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Executing:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvextend -L +100M \/dev\/oracle\/lvm1<\/strong><\/div>\n<div align=\"LEFT\"><strong>Extending logical volume lvm1 to 200.00 MB<\/strong><\/div>\n<div align=\"LEFT\"><strong>Logical volume lvm1 successfully resized<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>After:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm1 oracle -wi-ao\u00a0200.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm2 oracle -wi-ao 100.00M<\/strong><\/div>\n<div align=\"LEFT\">After executing above commands you can verify the changed size by any of following commands<\/div>\n<div align=\"LEFT\"><strong>#lvs, #lvdisplay, #lvscan<\/strong><\/div>\n<div align=\"LEFT\">But if you check<\/div>\n<div align=\"LEFT\"><strong>#df -hT<\/strong><\/div>\n<div align=\"LEFT\">it will be showing the old size only. Because the filesystem is updated the changed in Logical Volume. It can be updated by following command.<\/div>\n<div align=\"LEFT\"><strong>#resize2fs \/dev\/oracle\/lvm1<\/strong><\/div>\n<div align=\"LEFT\"><strong>NOTE: In case of extending the LV is resized first and the filesystem after that. But in case of shrinking a LV, filesystem is shrinked first followed by the shrink in LV.<\/strong><\/div>\n<div align=\"LEFT\"><strong>Before:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# df -hT<\/strong><\/div>\n<div align=\"LEFT\"><strong>Filesystem Type Size Used Avail Use% Mounted on<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm1<\/strong><\/div>\n<div align=\"LEFT\"><strong>ext3\u00a097M\u00a05.6M\u00a087M 7% \/linux1<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm2<\/strong><\/div>\n<div align=\"LEFT\"><strong>ext3 97M 5.6M 87M 7% \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Executing:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# resize2fs \/dev\/oracle\/lvm1<\/strong><\/div>\n<div align=\"LEFT\"><strong>resize2fs 1.39 (29-May-2006)<\/strong><\/div>\n<div align=\"LEFT\"><strong>Filesystem at \/dev\/oracle\/lvm1 is mounted on \/linux1; on-line resizing required<\/strong><\/div>\n<div align=\"LEFT\"><strong>Performing an on-line resize of \/dev\/oracle\/lvm1 to 204800 (1k) blocks.<\/strong><\/div>\n<div align=\"LEFT\"><strong>The filesystem on \/dev\/oracle\/lvm1 is now 204800 blocks long.<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>After:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# df -hT<\/strong><\/div>\n<div align=\"LEFT\"><strong>Filesystem Type Size Used Avail Use% Mounted on<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm1<\/strong><\/div>\n<div align=\"LEFT\"><strong>ext3\u00a0194M\u00a05.6M\u00a0179M 4% \/linux1<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm2<\/strong><\/div>\n<div align=\"LEFT\"><strong>ext3 97M 5.6M 87M 7% \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Shrinking a Logical Volume (Offline):<\/strong><\/div>\n<div align=\"LEFT\">As we extended the size of Logical Volume, we can reduce the size also. But in later case, it can be done only offline. That is the LV should be unmounted for reducing its size.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>For Shrinking a Volume:<\/strong><\/p>\n<ol>\n<li>Filesystem must be reduced first<\/li>\n<li>Requires a filesystem check and cannot be performed online<\/li>\n<li>#lvreduce can then reduce the volume<\/li>\n<\/ol>\n<\/div>\n<div align=\"LEFT\">Now We have a Volume group &#8220;oracle&#8221; of size about 900Mb. And two Logical vloumes lvm1 and lvm2 mounted on \/linux1 and \/linux2 respectively. Size of lvm1 is 200Mb and size of lvm2 is 100Mb. Now we&#8217;ll reduce the size of lvm2 by 40Mb.<\/div>\n<div align=\"LEFT\">Current status:<\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm1 oracle -wi-ao 200.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm2 oracle -wi-ao 100.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Step1: Unmont the volume:<\/strong><\/div>\n<div align=\"LEFT\"><strong>#umount \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Step2: Checking the filesystem:<\/strong><\/div>\n<div align=\"LEFT\"><strong>#e2fsck -f LV_Path<\/strong><\/div>\n<div align=\"LEFT\"><strong>#fsck -f \/dev\/oracle\/lvm2<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# e2fsck -f \/dev\/oracle\/lvm2<\/strong><\/div>\n<div align=\"LEFT\"><strong>e2fsck 1.39 (29-May-2006)<\/strong><\/div>\n<div align=\"LEFT\"><strong>Pass 1: Checking inodes, blocks, and sizes<\/strong><\/div>\n<div align=\"LEFT\"><strong>Pass 2: Checking directory structure<\/strong><\/div>\n<div align=\"LEFT\"><strong>Pass 3: Checking directory connectivity<\/strong><\/div>\n<div align=\"LEFT\"><strong>Pass 4: Checking reference counts<\/strong><\/div>\n<div align=\"LEFT\"><strong>Pass 5: Checking group summary information<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/oracle\/lvm2: 11\/25688 files (9.1% non-contiguous), 8914\/102400 blocks<\/strong><\/div>\n<div align=\"LEFT\">This is to make sure that the filesystem is in a consistent state.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Step3: Resizing the filesystem:<\/strong><\/div>\n<div align=\"LEFT\"><strong>#resize2fs LV_Path Final_size<\/strong><\/div>\n<div align=\"LEFT\"><strong>#resize2fs \/dev\/oracle\/lvm2 60M<\/strong><\/div>\n<div align=\"LEFT\">[Total size was 100Mb. Reduction 40Mb. So final size is 100-40=60]<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# resize2fs \/dev\/oracle\/lvm2 60M<\/strong><\/div>\n<div align=\"LEFT\"><strong>resize2fs 1.39 (29-May-2006)<\/strong><\/div>\n<div align=\"LEFT\"><strong>Resizing the filesystem on \/dev\/oracle\/lvm2 to 61440 (1k) blocks.<\/strong><\/div>\n<div align=\"LEFT\"><strong>The filesystem on \/dev\/oracle\/lvm2 is now 61440 blocks long.<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Step4: Now reduce the LV using #lvreduce<\/strong><\/div>\n<div align=\"LEFT\"><strong>#lvreduce -L Size LV_Path<\/strong><\/div>\n<div align=\"LEFT\"><strong>#lvreduce -L 60M \/dev\/oracle\/lvm2<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvreduce -L 60M \/dev\/oracle\/lvm2<\/strong><\/div>\n<div align=\"LEFT\"><strong>WARNING: Reducing active logical volume to 60.00 MB<\/strong><\/div>\n<div align=\"LEFT\"><strong>THIS MAY DESTROY YOUR DATA (filesystem etc.)<\/strong><\/div>\n<div align=\"LEFT\"><strong>Do you really want to reduce lvm2? [y\/n]: y<\/strong><\/div>\n<div align=\"LEFT\"><strong>Reducing logical volume lvm2 to 60.00 MB<\/strong><\/div>\n<div align=\"LEFT\"><strong>Logical volume lvm2 successfully resized<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Before Reducing:<\/strong><\/div>\n<div align=\"LEFT\"><strong>root@vm4 ~]# lvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm1 oracle -wi-ao 200.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm2 oracle -wi-ao\u00a0100.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>After Reducing:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# lvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm1 oracle -wi-ao 200.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>lvm2 oracle -wi-a-\u00a060.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>After mounting:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# df -hT<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm1\u00a0<\/strong><strong>ext3 194M 5.6M 179M 4% \/linux1<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/oracle-lvm2\u00a0<\/strong><strong>ext3\u00a059M\u00a05.3M 50M 10% \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Adding a Pysical Volume to a VG:<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Now we have a Volume Group &#8220;oracle&#8221; of size 900Mb. Suppose we used upto the maximum usable size. So we need to extend the size of the VG.<\/div>\n<div align=\"LEFT\">In this case we will create a new partition\/a new hard disk, and will make it a Physical Volume and add it to the Volume group.<\/div>\n<div align=\"LEFT\">Current status:<\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgs<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV\u00a0#LV #SN Attr VSize VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>oracle\u00a03\u00a02 0 wz&#8211;n- 864.00M 624.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Now we created one more partition with id LVM.<\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 429 465 297171 8e Linux LVM<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 466 502 297171 8e Linux LVM<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 503 539 297171 8e Linux LVM<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8 540 576 297171 8e Linux LVM<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Step1:<\/strong><\/div>\n<div align=\"LEFT\">First we have to convert it to physical volume.<\/div>\n<div align=\"LEFT\"><strong>#pvcreate \/dev\/sda8<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvcreate \/dev\/sda8<\/strong><\/div>\n<div align=\"LEFT\"><strong>Physical volume &#8220;\/dev\/sda8&#8221; successfully created<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Current status of all Physical Volumes:<\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 oracle lvm2 a- 288.00M 88.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 oracle lvm2 a- 288.00M 248.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 oracle lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8 lvm2 &#8212; 290.21M 290.21M<\/strong><\/div>\n<div align=\"LEFT\">See \/dev\/sda8 is not the part of the VG oracle<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Step2:<\/strong><\/div>\n<div align=\"LEFT\">Now we will add the PV \/dev\/sda8 to Volume Group &#8220;oracle&#8221;<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>#vgextend -v oracle \/dev\/sda8<\/strong><\/div>\n<div align=\"LEFT\">[ -v is for verbose. To see what is happening]<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgextend -v oracle \/dev\/sda8<\/strong><\/div>\n<div align=\"LEFT\"><strong>Checking for volume group &#8220;oracle&#8221;<\/strong><\/div>\n<div align=\"LEFT\"><strong>Archiving volume group &#8220;oracle&#8221; metadata (seqno 5).<\/strong><\/div>\n<div align=\"LEFT\"><strong>Wiping cache of LVM-capable devices<\/strong><\/div>\n<div align=\"LEFT\"><strong>Adding physical volume &#8216;\/dev\/sda8&#8217; to volume group &#8216;oracle&#8217;<\/strong><\/div>\n<div align=\"LEFT\"><strong>Volume group &#8220;oracle&#8221; will be extended by 1 new physical volumes<\/strong><\/div>\n<div align=\"LEFT\"><strong>Creating volume group backup &#8220;\/etc\/lvm\/backup\/oracle&#8221; (seqno 6).<\/strong><\/div>\n<div align=\"LEFT\"><strong>Volume group &#8220;oracle&#8221; successfully extended<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>After extending the VG with new Physical Volume:<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgs<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV\u00a0#LV #SN Attr Vsize VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>oracle\u00a04\u00a02 0 wz&#8211;n-\u00a01.12G 912.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 oracle lvm2 a- 288.00M 88.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 oracle lvm2 a- 288.00M 248.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 oracle lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8\u00a0oracle\u00a0lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Now \/dev\/sda8 became a part of VG oracle.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Removing a Pysical volume form a VG:<\/strong><\/div>\n<div align=\"LEFT\">Before removing a physical volume from a volume group, you can make sure that the physical volume is not used by any logical volumes by using the\u00a0<strong>#<\/strong><code><strong>pvdisplay<\/strong><\/code>\u00a0command. If the physical volume is still being used you will have to migrate the data to another physical volume using the<strong>#<\/strong><code><strong>pvmove<\/strong><\/code>\u00a0command. Then use the\u00a0<code>vgreduce<\/code>\u00a0command to remove the physical volume.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Current status of Pysical Volumes:<\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 oracle lvm2 a- 288.00M 88.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 oracle lvm2 a- 288.00M 248.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 oracle lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8 oracle lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\">In this example we will remove the Pysical Volume \/dev\/sda5 in which some Physical Extents are already used by some LV. So They need to be migrated.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">The status of \/dev\/sds5 is<\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvdisplay \/dev\/sda5<\/strong><\/div>\n<div align=\"LEFT\"><strong>&#8212; Physical volume &#8212;<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV Name \/dev\/sda5<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG Name oracle<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV Size 290.21 MB \/ not usable 2.21 MB<\/strong><\/div>\n<div align=\"LEFT\"><strong>Allocatable yes<\/strong><\/div>\n<div align=\"LEFT\"><strong>PE Size (KByte) 4096<\/strong><\/div>\n<div align=\"LEFT\"><strong>Total PE 72<\/strong><\/div>\n<div align=\"LEFT\"><strong>Free PE 22<\/strong><\/div>\n<div align=\"LEFT\"><strong>Allocated PE 50<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV UUID 9l5HlF-h8Of-2J6D-TDr4-BY34-cREh-7U5zxm<\/strong><\/div>\n<div align=\"LEFT\"><strong>Step1:<\/strong><\/div>\n<div align=\"LEFT\">Migrate the used Pes using<strong>\u00a0#pvmove<\/strong>\u00a0command<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvmove -v \/dev\/sda5<\/strong><\/div>\n<div align=\"LEFT\"><strong>Finding volume group &#8220;oracle&#8221;<\/strong><\/div>\n<div align=\"LEFT\"><strong>Archiving volume group &#8220;oracle&#8221; metadata (seqno 6).<\/strong><\/div>\n<div align=\"LEFT\"><strong>[output truncated]<\/strong><\/div>\n<div align=\"LEFT\"><strong>Creating volume group backup &#8220;\/etc\/lvm\/backup\/oracle&#8221; (seqno 9).<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Step2:<\/strong><\/div>\n<div align=\"LEFT\">Now reduce the Volume Group size by command\u00a0<strong>#vgreduce<\/strong><\/div>\n<div align=\"LEFT\"><strong>#vgreduce VG_name Removing_PV_Path<\/strong><\/div>\n<div align=\"LEFT\"><strong>#vgreduce oracle \/dev\/sda5<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgreduce oracle \/dev\/sda5<\/strong><\/div>\n<div align=\"LEFT\"><strong>Removed &#8220;\/dev\/sda5&#8221; from volume group &#8220;oracle&#8221;<\/strong><\/div>\n<div align=\"LEFT\"><strong>After Remvoing PV:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgs<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV\u00a0#LV #SN Attr\u00a0VSize\u00a0VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>oracle\u00a03\u00a02 0 wz&#8211;n-\u00a0864.00M\u00a0624.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 lvm2 &#8212; 290.21M 290.21M\u00a0\/Now not part of\u00a0oracle\u00a0VG<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 oracle lvm2 a- 288.00M 248.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 oracle lvm2 a- 288.00M 88.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8 oracle lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><span style=\"text-decoration: underline;\"><strong>Merging two Volume Groups:<\/strong><\/span><\/div>\n<div align=\"LEFT\">Two different Volume Groups can be merged to a single Volume Group.<\/div>\n<div align=\"LEFT\">Suppose we have two VGs &#8220;oracle&#8221; and &#8220;linux&#8221;.<\/div>\n<div align=\"LEFT\"><strong>Current status of VGs are:<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV #LV #SN Attr VSize VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>linux 1 0 0 wz&#8211;n- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>oracle 3 2 0 wz\u2014n- 864.00M 624.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\">Now we are going to merge &#8220;oracle&#8221; and &#8220;linux&#8221; to get a single VG linux.<\/div>\n<div align=\"LEFT\">We are using the command\u00a0<strong>#vgmerge<\/strong>\u00a0for this.<\/div>\n<div align=\"LEFT\"><strong>#vgmerge\u00a0<\/strong>merges two existing volume groups. The inactive SourceVolumeGroupName will be merged into the DestinationVolumeGroupName if physical extent sizes are equal and physical and logical volume summaries of both volume groups fit into DestinationVolumeGroupName&#8217;s limits.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>#vgmerge -v databases my_vg<\/strong><\/div>\n<div align=\"LEFT\">merges the inactive volume group named &#8220;my_vg&#8221; into the active or inactive volume group named &#8220;databases&#8221; giving verbose runtime information.<\/div>\n<div align=\"LEFT\"><strong>Step1:<\/strong><\/div>\n<div align=\"LEFT\">we are going to merge &#8220;oracle&#8221; and &#8220;linux&#8221; to get a single VG linux.<\/div>\n<div align=\"LEFT\">Make the source Volume Group inactive. In this case source is oracle.<\/div>\n<div align=\"LEFT\">#vgchange -a n oracle<\/div>\n<div align=\"LEFT\">umount the LV which uses the oracle VG then only u can inactivate it.<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# umount \/linux1<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# umount \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgchange -a n oracle<\/strong><\/div>\n<div align=\"LEFT\"><strong>0 logical volume(s) in volume group &#8220;oracle&#8221; now active<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>#vgmerge Destination Source<\/strong><\/div>\n<div align=\"LEFT\">we are going to merge &#8220;oracle&#8221; and &#8220;linux&#8221; to get a single VG linux. So<\/div>\n<div align=\"LEFT\">#vgmaerge -v linux oracle<\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgmerge -v linux oracle<\/strong><\/div>\n<div align=\"LEFT\"><strong>Checking for volume group &#8220;linux&#8221;<\/strong><\/div>\n<div align=\"LEFT\"><strong>Checking for volume group &#8220;oracle&#8221;<\/strong><\/div>\n<div align=\"LEFT\"><strong>Archiving volume group &#8220;oracle&#8221; metadata (seqno 10).<\/strong><\/div>\n<div align=\"LEFT\"><strong>Archiving volume group &#8220;linux&#8221; metadata (seqno 1).<\/strong><\/div>\n<div align=\"LEFT\"><strong>Writing out updated volume group<\/strong><\/div>\n<div align=\"LEFT\"><strong>Creating volume group backup &#8220;\/etc\/lvm\/backup\/linux&#8221; (seqno 2).<\/strong><\/div>\n<div align=\"LEFT\"><strong>Volume group &#8220;oracle&#8221; successfully merged into &#8220;linux&#8221;<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgs<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV #LV #SN Attr VSize VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>linux\u00a04\u00a02 0 wz&#8211;n- 1.12G\u00a0912.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgchange -a y linux<\/strong><\/div>\n<div align=\"LEFT\"><strong>2 logical volume(s) in volume group &#8220;linux&#8221; now active<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# mount \/dev\/linux\/lvm1 \/linux1<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# mount \/dev\/linux\/lvm2 \/linux2<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# mount<\/strong><\/div>\n<div align=\"LEFT\"><strong>[output truncated]<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/linux-lvm1 on \/linux1 type ext3 (rw)<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/mapper\/linux-lvm2 on \/linux2 type ext3 (rw)<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 lvm2 &#8212; 290.21M 290.21M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6\u00a0linux\u00a0lvm2 a- 288.00M 248.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7\u00a0linux\u00a0lvm2 a- 288.00M 88.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8\u00a0linux\u00a0lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda9\u00a0linux\u00a0lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><span style=\"text-decoration: underline;\"><strong>Spliting a Volume Group into two:<\/strong><\/span><\/div>\n<div align=\"LEFT\">We can split a Volume Group into two Volume Groups using the command<strong>\u00a0#vgsplit<\/strong><\/div>\n<div align=\"LEFT\">We have one VG\u00a0<strong>oracle<\/strong>\u00a0with 4 PVs. We will split that VG oracle to oracle and another VG\u00a0<strong>redhat<\/strong>. The PVs\u00a0<strong>\/dev\/sda8<\/strong>\u00a0and\u00a0<strong>\/dev\/sda9<\/strong>\u00a0will be moved to redhat.<\/div>\n<div align=\"LEFT\">The syntax is as follows:<\/div>\n<div align=\"LEFT\"><strong>#vgsplit EXISTING_VG NEW_VG PATH OF PVs_TO _BE_MOVED<\/strong><\/div>\n<div align=\"LEFT\"><strong>#vgsplit oracle redhat \/dev\/sda8 \/dev\/sda9<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgsplit linux redhat \/dev\/sda8 \/dev\/sda9<\/strong><\/div>\n<div align=\"LEFT\"><strong>New volume group &#8220;redhat&#8221; successfully split from &#8220;linux&#8221;<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>Before:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgs<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV #LV #SN Attr VSize VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>linux\u00a04\u00a02 0 wz&#8211;n- 1.12G 912.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 lvm2 &#8212; 290.21M 290.21M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 linux lvm2 a- 288.00M 248.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 linux lvm2 a- 288.00M 88.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8 linux\u00a0lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda9 linux<\/strong><strong>\u00a0lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>After:<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgs<\/strong><\/div>\n<div align=\"LEFT\"><strong>VG #PV #LV #SN Attr VSize VFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>linux 2 2 0 wz&#8211;n- 576.00M 336.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>redhat 2\u00a00 0 wz&#8211;n- 576.00M 576.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# pvs<\/strong><\/div>\n<div align=\"LEFT\"><strong>PV VG Fmt Attr PSize PFree<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda5 lvm2 &#8212; 290.21M 290.21M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda6 linux lvm2 a- 288.00M 248.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda7 linux lvm2 a- 288.00M 88.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda8 redhat\u00a0lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><strong>\/dev\/sda9 redhat\u00a0<\/strong><strong>lvm2 a- 288.00M 288.00M<\/strong><\/div>\n<div align=\"LEFT\"><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgchange -a y linux<\/strong><\/div>\n<div align=\"LEFT\"><strong>2 logical volume(s) in volume group &#8220;linux&#8221; now active<\/strong><\/div>\n<div align=\"LEFT\"><strong>[root@vm4 ~]# vgchange -a y redhat<\/strong><\/div>\n<div align=\"LEFT\">\n<div><strong>0 logical volume(s) in volume group &#8220;redhat&#8221; now active<\/strong><br \/>\n<strong><br \/>\n<\/strong><\/div>\n<div>\n<div>Creating SNAPSHOT (Backup):<\/div>\n<p>We can take the back up of any particular Logical Volumes. Snapshot will be stored in the Same<br \/>\nvolume group. Snapshot will take only 3-5% of the original size of Logical Volume.<br \/>\nThis is the current status of our machine:<\/p>\n<div>[root@vm4 ~]# lvs<\/div>\n<div>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/div>\n<div>lvm1 linux -wi-a- 200.00M<\/div>\n<div>lvm2 linux -wi-a- 40.00M<\/div>\n<div><\/div>\n<div>[root@vm4 ~]# vgs<\/div>\n<div>VG #PV #LV #SN Attr VSize VFree<\/div>\n<div>linux 2 2 0 wz&#8211;n- 576.00M 336.00M<\/div>\n<div>redhat 2 0 0 wz&#8211;n- 576.00M 576.00M<\/div>\n<div><\/div>\n<div>[root@vm4 ~]# pvs<\/div>\n<div>PV VG Fmt Attr PSize PFree<\/div>\n<div>\/dev\/sda5 lvm2 &#8212; 290.21M 290.21M<\/div>\n<div>\/dev\/sda6 linux lvm2 a- 288.00M 248.00M<\/div>\n<div>\/dev\/sda7 linux lvm2 a- 288.00M 88.00M<\/div>\n<div>\/dev\/sda8 redhat lvm2 a- 288.00M 288.00M<\/div>\n<div>\/dev\/sda9 redhat lvm2 a- 288.00M 288.00M<\/div>\n<div><\/div>\n<p>We have two Logical Volumes lvm1 and lvm2 mounted on \/linux1 and \/linux2 respectively.<br \/>\nWe&#8217;ll take the SNAPSHOT of the LV lvm1 which is mounted on \/linux1<br \/>\ncurrently there are following files in \/linux1 [ie in lvm1]<br \/>\n<strong>[root@vm4 ~]# cd \/linux1<\/strong><br \/>\n<strong>[root@vm4 linux1]# ls<\/strong><br \/>\n<strong>a b c lost+found<\/strong><br \/>\n<strong>Step1:<\/strong><br \/>\nSnapshot is actually a Logical Volume only. It will be saved in the same VG. We can create lvm<br \/>\nsnapshot using command #lvcreate with options for snapshot.<br \/>\n<strong>The syntax is as follows<\/strong><br \/>\n<strong>#lvcreate &#8211;size SIZE &#8211;snapshot &#8211;name Name_Of_Snapshot Path_of_the_LV<\/strong><br \/>\n<strong>[root@vm4 linux1]# lvcreate &#8211;size 10M &#8211;snapshot &#8211;name snap \/dev\/linux\/lvm1<\/strong><br \/>\n<strong>Rounding up size to full physical<\/strong><\/p>\n<p><strong>Logical volume &#8220;snap&#8221; created<\/strong><br \/>\n<strong><br \/>\n<\/strong><br \/>\n<strong>[root@vm4 linux1]# lvs<\/strong><br \/>\n<strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><br \/>\n<strong>lvm1 linux owi-ao 200.00M<\/strong><br \/>\n<strong>lvm2 linux -wi-ao 40.00M<\/strong><br \/>\n<strong>snap linux swi-a- 12.00M lvm1 0.10<\/strong><br \/>\n<strong><br \/>\n<\/strong><br \/>\n<strong>[root@vm4 linux1]# vgs<\/strong><br \/>\n<strong>VG #PV #LV #SN Attr VSize VFree<\/strong><br \/>\n<strong>linux 2 3 1 wz&#8211;n- 576.00M 324.00M<\/strong><br \/>\n<strong>redhat 2 0 0 wz&#8211;n- 576.00M 576.00M<\/strong><\/p>\n<\/div>\n<div>\n<div><\/div>\n<p>Now lets mount the Snapshpot and check whether it has everything from lvm1.<br \/>\nMounting snap to \/snapshot<br \/>\n<strong>[root@vm4 linux1]# mkdir \/snapshot<\/strong><br \/>\n<strong>[root@vm4 linux1]# mount \/dev\/linux\/snap \/snapshot<\/strong><br \/>\n<strong>[root@vm4 linux1]# cd \/snapshot<\/strong><br \/>\n<strong>[root@vm4 snapshot]# ls<\/strong><br \/>\n<strong>a b c lost+found<\/strong><br \/>\nIt has the same and all the contents of lvm1<\/p>\n<p>How to create mirrored lvm volumes:<br \/>\nWe can create mirrored lvm using the command #lvcreate with -m option.<br \/>\nThe syntax is as follows:<br \/>\n<strong>#lvcreate -L Size -m1 -n Name_LV Name_VG Mirror_1st_leg \u00a0 Mirror_2nd_leg \u00a0 Log_Device<\/strong><br \/>\n-m1 means its a mirrored one type. So it will have one original[1st leg] one mirror[2nd leg] and a<br \/>\nlogging device for sync.<br \/>\n<strong>#lvcreate -L 100M -m1 -n mlvm redhat \u00a0\/dev\/sda5 \u00a0\/dev\/sda6 \u00a0\/dev\/sda7<\/strong><br \/>\n<strong>[root@vm4 ~]# lvcreate -L 100M -m1 -n mlvm redhat \/dev\/sda5 \/dev\/sda6 \/dev\/sda7<\/strong><br \/>\n\/dev\/cdrom: open failed: Read-only file system<br \/>\nLogical volume &#8220;mlvm&#8221; created<br \/>\n<strong>[root@vm4 ~]# lvs<\/strong><br \/>\n<strong>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/strong><br \/>\n<strong>mlvm redhat mwi-a- 100.00M mlvm_mlog 100.00<\/strong><br \/>\n<strong><br \/>\n<\/strong><\/p>\n<p>How to create stripped lvm volumes:<br \/>\nWe can create lvms in stripped manner so that it will increase the performance. It can be done<br \/>\nusing the commad #lvcreate with -i option.<\/p>\n<div>The syntax is as follows:<\/div>\n<div>#lvcreate -L Size -i2 -n Name_LV Name_VG 1st _LV 2nd _LV<\/div>\n<div>[root@vm4 ~]# lvcreate -L 100M -i2 -n slvm redhat \/dev\/sda8 \/dev\/sda9<\/div>\n<div>Using default stripesize 64.00 KB<\/div>\n<div>\/dev\/cdrom: open failed: Read-only file system<\/div>\n<div>Rounding size (25 extents) up to stripe boundary size (26 extents)<\/div>\n<div>Logical volume &#8220;slvm&#8221; created<\/div>\n<div>[root@vm4 ~]# lvs<\/div>\n<div>LV VG Attr LSize Origin Snap% Move Log Copy% Convert<\/div>\n<div>slvm redhat -wi-a- 104.00M<\/div>\n<p>For extending a stripped lvm u need to extend the VG with two different PVs . Else it wont<br \/>\nwork.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>LVM in linux<\/p>\n<p> Logical Volume Management[LVM]<\/p>\n<p> LVM is a logical volume manager for the Linux kernel; it manages disk drives and similar mass-storage devices, in particular large ones. The term &#8220;volume&#8221; refers to a disk drive or partition. Every system contains Physical Volums[PV]. Such as hard disks, partitions or external storages. Volume management treats PVs [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/713"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=713"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/713\/revisions"}],"predecessor-version":[{"id":3079,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/713\/revisions\/3079"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}