{"id":298,"date":"2018-08-12T05:40:03","date_gmt":"2018-08-12T02:40:03","guid":{"rendered":"http:\/\/kifarunix.com\/?p=298"},"modified":"2024-03-11T08:21:43","modified_gmt":"2024-03-11T05:21:43","slug":"how-to-create-lvm-logical-volumes-in-linux","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-create-lvm-logical-volumes-in-linux\/","title":{"rendered":"Create LVM Logical Volumes in Linux"},"content":{"rendered":"\n<p>In this tutorial, we are going to learn about how to create LVM logical volumes in Linux. LVM is a standard feature in most modern Linux distributions that allows you to create and manage logical volumes. In this tutorial, we will show you how to create and manage LVM logical volumes in Linux, using command-line tools. We will cover the basic concepts of LVM, including physical volumes, volume groups, and logical volumes, and demonstrate how to create filesystem on logical volumes in Linux.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#creating-lvm-logical-volumes-in-linux\">Creating LVM Logical Volumes in Linux<\/a><ul><li><a href=\"#lvm-architecture-overview\">LVM Architecture Overview<\/a><\/li><li><a href=\"#lvm-logical-volumes-components\">LVM Logical Volumes Components<\/a><\/li><li><a href=\"#creating-lvm-logical-volumes-in-linux-1\">Creating LVM Logical Volumes in Linux<\/a><ul><li><a href=\"#create-disk-partitions-to-be-used\">Create Disk Partitions to be Used<\/a><\/li><li><a href=\"#initialize-partitions-as-physical-volumes\">Initialize Partitions as Physical Volumes<\/a><\/li><li><a href=\"#create-volume-group\">Create Volume Group<\/a><\/li><li><a href=\"#create-logical-volume\">Create Logical Volume<\/a><\/li><li><a href=\"#create-logical-volume-filesystem\">Create Logical Volume Filesystem<\/a><\/li><\/ul><\/li><\/ul><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-lvm-logical-volumes-in-linux\">Creating LVM Logical Volumes in Linux<\/h2>\n\n\n\n<p>Before we dive deeper, let us have a look at LVM architecture.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"lvm-architecture-overview\">LVM Architecture Overview<\/h3>\n\n\n\n<p>The structure of an LVM disk environment is simply illustrated in the figure below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"377\" height=\"361\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/08\/lvm-arch.png\" alt=\"LVM architecture\" class=\"wp-image-9492\" title=\"\"><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"lvm-logical-volumes-components\">LVM Logical Volumes Components<\/h3>\n\n\n\n<p>The underlying structure of an LVM environment is a block device such as partition or a whole disk which is initialized a <strong><code><em>Physical Volume<\/em> (PV)<\/code><\/strong>. A single or multiple block devices can be grouped together to form a PV.<\/p>\n\n\n\n<p>The physical volumes can be combined into a <strong><code><em>Volume Group<\/em> (VG)<\/code><\/strong>. This creates a pool of disk space out of which <em><strong><code>LVM logical volumes<\/code> (LVs)<\/strong><\/em> can be allocated. A top logical volumes, regular file systems, such as ext4, xfs, etc. can then be created. This process is comparable to the how disks are divided into partitions.<\/p>\n\n\n\n<p>So, basically, LVM disk environment is made up of three components:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Physical Volume<\/strong><\/li>\n\n\n\n<li><strong>Volume Group<\/strong><\/li>\n\n\n\n<li><strong>Logical Volume<\/strong><\/li>\n<\/ul>\n\n\n\n<p>As depicted in the architecture above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-lvm-logical-volumes-in-linux-1\">Creating LVM Logical Volumes in Linux<\/h3>\n\n\n\n<p>In order to create LVM logical volumes, here is a basic four step procedure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#create-partition\">Create partitions to be used<\/a><\/li>\n\n\n\n<li><a href=\"#initialize-pv\">Initialize them as Physical Volumes<\/a><\/li>\n\n\n\n<li><a href=\"#create-vg\">Create a volume group<\/a><\/li>\n\n\n\n<li><a href=\"#create-lv\">Create a logical volume<\/a><\/li>\n\n\n\n<li><a href=\"#lv-filesystem\">Create a file system on a logical volume<\/a><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-disk-partitions-to-be-used\">Create Disk Partitions to be Used<\/h4>\n\n\n\n<p>So before you can create any logical volume, attach extra drives yo your system. In our case, we have two uninitialized disks, <strong>\/dev\/sdb1<\/strong> and <strong>\/dev\/sdc1 <\/strong>and we will be using both of them to create LVM logical volumes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"initialize-partitions-as-physical-volumes\">Initialize Partitions as Physical Volumes<\/h4>\n\n\n\n<p>First, let us initialize our disks as physical volume using the command, <strong>pvcreate<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>pvcreate \/dev\/sdb1 \/dev\/sdc1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Physical volume \"\/dev\/sdb1\" successfully created.\nPhysical volume \"\/dev\/sdc1\" successfully created.<\/code><\/pre>\n\n\n\n<p>To confirm this, you can run the command, pvs, to display information about physical volumes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>pvs<\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>\nPV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VG&nbsp;&nbsp;&nbsp;&nbsp; Fmt Attr PSize PFree\n\/dev\/sda2&nbsp;&nbsp;&nbsp;&nbsp; centos lvm2 a-- &lt;9.00g 0\n\/dev\/sdb1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lvm2 --- &lt;2.00g &lt;2.00g\n\/dev\/sdc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lvm2 --- &lt;2.00g &lt;2.00g\n<\/code><\/pre>\n\n\n\n<p>As you can see, our two physical volumes have no volume group assigned to them yet.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-volume-group\">Create Volume Group<\/h4>\n\n\n\n<p>Now, create a volume group that consists of the physical volumes created above. To create a volume group, run the command below;<\/p>\n\n\n\n<pre id=\"block-e614a52a-dd1d-4724-b609-b00af9c24ee0\" class=\"wp-block-preformatted\">vgcreate test_vol_group \/dev\/sdb1 \/dev\/sdc1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Volume group \"test_vol_group\" successfully created<\/code><\/pre>\n\n\n\n<p>where <strong>test_vol_group <\/strong>is the name of our volume group and <strong>\/dev\/sdb1<\/strong>, <strong>\/dev\/sdc1<\/strong> are our physical volumes created above.<\/p>\n\n\n\n<p>You can use the vgs command to display the attributes of the new volume group.<\/p>\n\n\n\n<pre id=\"block-556b8689-6394-4477-a149-f679d22c6189\" class=\"wp-block-preformatted\">vgs<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>VG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #PV&nbsp; #LV&nbsp; #SN&nbsp;&nbsp;&nbsp;&nbsp; Attr&nbsp;&nbsp;&nbsp; VSize&nbsp; VFree\ncentos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp; wz--n-&nbsp; &lt;9.00g&nbsp;&nbsp; 0\ntest_vol_group&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp; wz--n-&nbsp; 3.99g&nbsp; 3.99g<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-logical-volume\">Create Logical Volume<\/h4>\n\n\n\n<p>Now that we have the volume group, let us create a logical volume, <strong>test_log_volume<\/strong>, that will occupy 1G of the volume group space.<\/p>\n\n\n\n<pre id=\"block-40922a8d-e597-40d1-9518-9a13dcf8d17c\" class=\"wp-block-preformatted\">lvcreate -L 1G -n test_log_volume test_vol_group<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Logical volume \"test_log_group\" created.<\/code><\/pre>\n\n\n\n<p>where &#8211;<strong>L<\/strong> specifies the <strong>size<\/strong> and &#8211;<strong>n<\/strong> specifies the <strong>name<\/strong> of the logical volume. <strong>test_vol_group<\/strong> is our volume group created above.<br>You can use the <strong>lvs<\/strong> command to display the attributes of the new volume group.<\/p>\n\n\n\n<pre id=\"block-cf87fec0-116d-4b17-b0f3-d563999fd2dc\" class=\"wp-block-preformatted\">lvs<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>LV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Attr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert\nroot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; centos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -wi-ao----  &lt;8.00g\nswap&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; centos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -wi-ao----   1.00g\ntest_log_group test_vol_group -wi-a-----   1.00g<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-logical-volume-filesystem\">Create Logical Volume Filesystem<\/h4>\n\n\n\n<p>So we now have a 1G logical volume. Let us make it usable by creating a file system on it. The following command creates a <strong>xfs<\/strong> file system on the logical volume. We will use mkfs.xfs command in its simplest form.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkfs.xfs \/dev\/test_vol_group\/test_log_group<\/code><\/pre>\n\n\n\n<p>Next,create a mount point and mount the logical volume.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/tmp\/mnt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mount \/dev\/test_vol_group\/test_log_group \/tmp\/mnt\/<\/code><\/pre>\n\n\n\n<p>Let us check the logical volume filesystem and disk space usage.<\/p>\n\n\n\n<pre id=\"block-7ef5b3b4-d935-4b66-9af1-e94407c9915d\" class=\"wp-block-preformatted\">df -hT<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Filesystem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type&nbsp; Size Used Avail Use% Mounted on\n\/dev\/mapper\/centos-root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xfs&nbsp;&nbsp; 8.0G  1.1G 7.0G 14% \/\n...\n\/dev\/mapper\/test_vol_group-test_log_group xfs&nbsp;&nbsp; 1014M 33M  982M 4% \/tmp\/mnt<\/code><\/pre>\n\n\n\n<p>Upto there, we have created a usable LVM logical volume.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h2>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/setup-replicated-glusterfs-volume-on-ubuntu\/\">Setup Replicated GlusterFS Volume on Ubuntu<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-ceph-storage-cluster-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup Ceph Storage Cluster on Ubuntu 20.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we are going to learn about how to create LVM logical volumes in Linux. LVM is a standard feature in most modern<\/p>\n","protected":false},"author":1,"featured_media":9492,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[39,121,43],"tags":[5351,3797,3801,28,3800,3803,3798,3799,3802],"class_list":["post-298","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-storage","category-howtos","category-lvm","tag-create-logical-volume-ubuntu","tag-create-logical-volumes-in-linux","tag-create-physical-volumes-linux","tag-lvm","tag-lvs","tag-physical-volume","tag-pvs","tag-vgs","tag-volume-groups","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/298"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=298"}],"version-history":[{"count":6,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/298\/revisions"}],"predecessor-version":[{"id":20969,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/298\/revisions\/20969"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9492"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}