{"id":6103,"date":"2016-07-31T16:23:24","date_gmt":"2016-07-31T08:23:24","guid":{"rendered":"http:\/\/rmohan.com\/?p=6103"},"modified":"2016-07-31T16:23:24","modified_gmt":"2016-07-31T08:23:24","slug":"how-to-create-lvm-using-pvcreate-vgcreate-lvcreate-and-lvextend-commands","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6103","title":{"rendered":"HOW TO CREATE LVM USING PVCREATE, VGCREATE, LVCREATE, AND LVEXTEND COMMANDS"},"content":{"rendered":"<p><strong>HOW TO CREATE LVM USING PVCREATE, VGCREATE, LVCREATE, AND LVEXTEND COMMANDS<\/strong><\/p>\n<p>What is LVM?<\/p>\n<p>LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes. With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes.<\/p>\n<p>How to setup LVM in RHEL 7<\/p>\n<p>Once the physical disk space has been made available to the host, run the following command to identify the disk location:<\/p>\n<p>fdisk -l<\/p>\n<p>Disk \/dev\/sdb: 4294 MB, 4294967296 bytes, 8388608 sectors<br \/>\nUnits = sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisk label type: dos<br \/>\nDisk identifier: 0x5eee65f8<br \/>\nThe output of the above command identifies the location of the 4 GB disk as being located in \/dev\/sdb. The next step involves issuing the following command (replace \/dev\/sdv with the output you receive from the above command):<\/p>\n<p>[root@slave ~]# fdisk \/dev\/sdb<br \/>\nTyp Type n to create a new partition and press enter three times until you reach the Last sector prompt. Enter +4GB here and press enter. Type in w and press enter to make the changes live. Issuing partprobe makes the partition live without rebooting the host.<\/p>\n<p>[root@slave ~]# partprobe<br \/>\nThe next step involves creating a physical volume.<\/p>\n<p>[root@slave ~]# pvcreate \/dev\/sdb1<br \/>\n Physical volume &#8220;\/dev\/sdb1&#8221; successfully created<br \/>\nRun a pvscan to pickup the changes.<\/p>\n<p>[root@slave ~]# pvscan<br \/>\n  PV \/dev\/sda2   VG rhel   lvm2 [7.51 GiB \/ 0    free]<br \/>\n  Total: 1 [7.51 GiB] \/ in use: 1 [7.51 GiB] \/ in no VG: 0 [0   ]<br \/>\nWe now need to create a volume group.<\/p>\n<p>[root@slave ~]# vgcreate roldy \/dev\/sdb1<br \/>\n  Volume group &#8220;roldy&#8221; successfully created<br \/>\nInside of this volume group, we will now create a logical partition.<\/p>\n<p>[root@slave ~]# lvcreate roldy &#8211;name snookicoco \/dev\/sdb1 -L 200MB<br \/>\n  Logical volume &#8220;snookicoco&#8221; created<br \/>\nFormat the file system with xfs using the below command:<\/p>\n<p>[root@slave ~]# mkfs.xfs \/dev\/roldy\/snookicoco<br \/>\nmeta-data=\/dev\/roldy\/snookicoco  isize=256    agcount=4, agsize=12800 blks<br \/>\n         =                       sectsz=512   attr=2, projid32bit=1<br \/>\n         =                       crc=0<br \/>\ndata     =                       bsize=4096   blocks=51200, imaxpct=25<br \/>\n         =                       sunit=0      swidth=0 blks<br \/>\nnaming   =version 2              bsize=4096   ascii-ci=0 ftype=0<br \/>\nlog      =internal log           bsize=4096   blocks=853, version=2<br \/>\n         =                       sectsz=512   sunit=0 blks, lazy-count=1<br \/>\nrealtime =none                   extsz=4096   blocks=0, rtextents=0<br \/>\nCreate a folder on the host which will be mapped to this storage:<\/p>\n<p>[root@slave ~]# mkdir \/snookicoco<br \/>\nIn order to edit the fstab, we will need to obtain the UUID of the volume. The UUID can be easily obtained via the blkid command.<\/p>\n<p>[root@slave ~]# blkid<br \/>\n\/dev\/sda1: UUID=&#8221;46814065-a338-4860-a3f8-781b132987c6&#8243; TYPE=&#8221;xfs&#8221;<br \/>\n\/dev\/sda2: UUID=&#8221;3gzDCV-lPFf-8hKA-Kojk-XI01-T7SR-xfK8fd&#8221; TYPE=&#8221;LVM2_member&#8221;<br \/>\n\/dev\/sdb1: UUID=&#8221;QCrBPH-KPEw-PZ3c-xDs0-nUVE-esuL-AZorqV&#8221; TYPE=&#8221;LVM2_member&#8221;<br \/>\n\/dev\/mapper\/rhel-root: UUID=&#8221;dddea344-415f-4b2b-811f-8d7eac492f9e&#8221; TYPE=&#8221;xfs&#8221;<br \/>\n\/dev\/mapper\/rhel-swap: UUID=&#8221;e7128c41-27b0-45ad-8f20-ddf7ce444aa1&#8243; TYPE=&#8221;swap&#8221;<br \/>\n\/dev\/mapper\/roldy-snookicoco: UUID=&#8221;ae3cc85c-158f-4075-9025-5db0998c1d73&#8243; TYPE=&#8221;xfs&#8221;<br \/>\nIt\u2019s now time to mount the partition using the fstab.<\/p>\n<p>[root@slave ~]# vi \/etc\/fstab<br \/>\nCopy the UUID across to a new line in the fstab, add the local mount point and specify the file system as per the below entry:<\/p>\n<p># \/etc\/fstab<br \/>\n# Created by anaconda on Thu Sep 18 00:41:01 2014<br \/>\n#<br \/>\n# Accessible filesystems, by reference, are maintained under &#8216;\/dev\/disk&#8217;<br \/>\n# See man pages fstab(5), findfs(8), mount(8) and\/or blkid(8) for more info<br \/>\n#<br \/>\n\/dev\/mapper\/rhel-root   \/                       xfs     defaults        1 1<br \/>\nUUID=46814065-a338-4860-a3f8-781b132987c6 \/boot                   xfs     defaults        1 2<br \/>\n\/dev\/mapper\/rhel-swap   swap                    swap    defaults        0 0<br \/>\nUUID=&#8221;ae3cc85c-158f-4075-9025-5db0998c1d73&#8243; \/snookicoco xfs defaults 1 2<br \/>\n~<br \/>\n~<br \/>\nVerify that the mount point is now listed.<\/p>\n<p>[root@slave ~]# df -hk | grep snookicoco<br \/>\n\/dev\/mapper\/roldy-snookicoco    201388  10400    190988   6% \/snookicoco<br \/>\nHow to extend a logical volume<\/p>\n<p>Extending logical volumes is possible thanks to the lvextend utility.<\/p>\n<p>lvextend -L +500M \/dev\/coco\/chops<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HOW TO CREATE LVM USING PVCREATE, VGCREATE, LVCREATE, AND LVEXTEND COMMANDS<\/p>\n<p>What is LVM?<\/p>\n<p>LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes. With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes.<\/p>\n<p>How to setup LVM in [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6103"}],"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=6103"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6103\/revisions"}],"predecessor-version":[{"id":6104,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6103\/revisions\/6104"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}