{"id":1784,"date":"2018-10-27T03:47:22","date_gmt":"2018-10-27T03:47:22","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1784"},"modified":"2018-10-27T04:14:07","modified_gmt":"2018-10-27T04:14:07","slug":"how-to-use-lvm-to-create-a-new-logical-volume","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/27\/how-to-use-lvm-to-create-a-new-logical-volume\/","title":{"rendered":"How To Use LVM To Create A New Logical Volume"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxadmin.io\/wp-content\/uploads\/2017\/05\/lvdisplay.png\" alt=\"Create a LVM Volume\" width=\"667\" height=\"235\" \/><\/p>\n<h2>What is LVM<\/h2>\n<p>Logical Volume Managment (LVM) is an abstraction layer between physical devices and the file systems which they create. This can make disk management easier by adding abilities to shrink or expand filesystems by just adding additional physical devices no longer being limited to a single physical device as the volume can span over multiple physical devices.<\/p>\n<h4>Terminology:<\/h4>\n<p>Physical Volume (PV) \u2013 This is the physical device to be used with LVM<br \/>\nVolume Group (VG) \u2013 A storage pool made up of PGs<br \/>\nLogical Volume(LV) \u2013 A logical volume is a portion of a volume group, this is the usable space to the file system<\/p>\n<h3>Find And Create The Physical Volume<\/h3>\n<p>First make sure you have the right disk. In this example we are going to use \/dev\/vdd (a virtual disk on a KVM virtual machine)<\/p>\n<p># fdisk -l \/dev\/vdd<\/p>\n<p>Disk \/dev\/vdd: 8589 MB, 8589934592 bytes, 16777216 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: 0x000b9af0<\/p>\n<p>Device Boot Start End Blocks Id System<br \/>\n\/dev\/vdd1 2048 16777215 8387584 83 Linux<\/p>\n<p>Next use parted to create partition.<\/p>\n<p># parted \/dev\/vdd<\/p>\n<p>(parted) mklabel<br \/>\nNew disk label type? msdos<br \/>\nWarning: The existing disk label on \/dev\/vdd will be destroyed and all data on this disk will be lost. Do you want to continue?<br \/>\nYes\/No? Yes<br \/>\n(parted) mkpart<br \/>\nPartition type? primary\/extended? primary<br \/>\nFile system type? [ext2]? xfs<br \/>\nStart? 0%<br \/>\nEnd? 100%<\/p>\n<p>To use the entire disk, you will want to enter 0% to start and 100% to end. Then enter \u2018print\u2019 to verify the partition details<\/p>\n<p>(parted) print<br \/>\nModel: Virtio Block Device (virtblk)<br \/>\nDisk \/dev\/vdd: 8.00GiB<br \/>\nSector size (logical\/physical): 512B\/512B<br \/>\nPartition Table: msdos<br \/>\nDisk Flags:<\/p>\n<p>Number Start End Size Type File system Flags<br \/>\n1 0.00GiB 8.00GiB 8.00GiB primary xfs<\/p>\n<p>Go ahead and quit out of parted. You will now want to use pvcreate to create the physical volume<\/p>\n<p>pvcreate \/dev\/vdd1<br \/>\nWARNING: xfs signature detected on \/dev\/vdd1 at offset 0. Wipe it? [y\/n]: y<br \/>\nWiping xfs signature on \/dev\/vdd1.<br \/>\nPhysical volume &#8220;\/dev\/vdd1&#8221; successfully created.<\/p>\n<h3>Create The LVM Volume Group<\/h3>\n<p>You will use vgcreate to create the volume group. The syntax is <em>vgcreate &lt;volume-group-name&gt; &lt;partition&gt;<\/em>. The volume group name can be whatever you want.<\/p>\n<p># vgcreate vg02 \/dev\/vdd1<br \/>\nVolume group &#8220;vg02&#8221; successfully created<\/p>\n<p>Then do a vgdisplay to find the amount of Physical extents in the disk:<\/p>\n<p># vgdisplay vg02<br \/>\n&#8212; Volume group &#8212;<br \/>\nVG Name vg02<br \/>\nSystem ID<br \/>\nFormat lvm2<br \/>\nMetadata Areas 1<br \/>\nMetadata Sequence No 2<br \/>\nVG Access read\/write<br \/>\nVG Status resizable<br \/>\nMAX LV 0<br \/>\nCur LV 1<br \/>\nOpen LV 1<br \/>\nMax PV 0<br \/>\nCur PV 1<br \/>\nAct PV 1<br \/>\nVG Size 8.00 GiB<br \/>\nPE Size 4.00 MiB<br \/>\nTotal PE 2047<br \/>\nAlloc PE \/ Size 2047 \/ 8.00 GiB<br \/>\nFree PE \/ Size 0 \/ 0<br \/>\nVG UUID NHX1cN-9Ujw-dnXf-hSfo-srIc-6do6-mFnCba<\/p>\n<h3>Create The LVM Logical Volume<\/h3>\n<p>You will then use lvcreate to create the logical volume based on the number of physical extents found in vgdisplay. The -n flag allows you to name the volume, this is again whatever you would like to describe the logical volume.<\/p>\n<p># lvcreate -l 2047 vg02 -n logvol1<br \/>\nLogical volume &#8220;logvol1&#8221; created.<\/p>\n<p>After it has been created, perform a lvdisplay to verify.<\/p>\n<p># lvdisplay<\/p>\n<p>&#8212; Logical volume &#8212;<br \/>\nLV Path \/dev\/vg02\/logvol1<br \/>\nLV Name logvol1<br \/>\nVG Name vg02<br \/>\nLV UUID eZCOf2-9adr-KIMx-LxZi-hDDi-ss1L-8LMfnK<br \/>\nLV Write Access read\/write<br \/>\nLV Creation host, time centos7-vm1, 2017-05-15 21:28:15 -0400<br \/>\nLV Status available<br \/>\n# open 0<br \/>\nLV Size 8.00 GiB<br \/>\nCurrent LE 2047<br \/>\nSegments 1<br \/>\nAllocation inherit<br \/>\nRead ahead sectors auto<br \/>\n&#8211; currently set to 8192<br \/>\nBlock device 253:2<\/p>\n<h3>Format the LVM logical volume<\/h3>\n<p>In this example, we are going to format the logical volume as xfs using mkfs.xfs so it can be mounted<\/p>\n<p>mkfs.xfs \/dev\/vg02\/logvol1<br \/>\nmeta-data=\/dev\/vg02\/logvol1 isize=512 agcount=4, agsize=524032 blks<br \/>\n= sectsz=512 attr=2, projid32bit=1<br \/>\n= crc=1 finobt=0, sparse=0<br \/>\ndata = bsize=4096 blocks=2096128, imaxpct=25<br \/>\n= sunit=0 swidth=0 blks<br \/>\nnaming =version 2 bsize=4096 ascii-ci=0 ftype=1<br \/>\nlog =internal log bsize=4096 blocks=2560, version=2<br \/>\n= sectsz=512 sunit=0 blks, lazy-count=1<br \/>\nrealtime =none extsz=4096 blocks=0, rtextents=0<\/p>\n<p>Once that has been completed it can now be mounted and added to \/etc\/fstab to persist during reboots.<\/p>\n<p>May 15, 2017LinuxAdmin.io<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/use-lvm-to-create-a-new-logical-volume\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is LVM Logical Volume Managment (LVM) is an abstraction layer between physical devices and the file systems which they create. This can make disk management easier by adding abilities to shrink or expand filesystems by just adding additional physical devices no longer being limited to a single physical device as the volume can span &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/27\/how-to-use-lvm-to-create-a-new-logical-volume\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Use LVM To Create A New Logical Volume&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1784","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1784"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1784\/revisions"}],"predecessor-version":[{"id":1822,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1784\/revisions\/1822"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}