{"id":40852,"date":"2016-09-29T13:57:58","date_gmt":"2016-09-29T08:27:58","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=40852"},"modified":"2016-10-05T12:16:31","modified_gmt":"2016-10-05T06:46:31","slug":"extended-ebs-lvm-backed-volume-on-ec2","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/extended-ebs-lvm-backed-volume-on-ec2\/","title":{"rendered":"Create Extended EBS Backed LVM Volume on EC2"},"content":{"rendered":"<p style=\"text-align: justify\">Sharing one of my use-cases, Jenkins has been increasing \u00a0over past few weeks, and we were about to hit the 50GB capping for Elastic Block Storage volumes on the Amazon EC2. And this is a problem that is affecting a lot of our team\u00a0<a title=\"devops developers\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">developers<\/a> to test their build packages on the different environments. But, every time we have to increase it, a maintenance\/downtime window has to be scheduled where the Jenkins server service \u00a0is stopped, an EBS snapshot of the data volume is created and a newer volume with increase capacity is created and attached to the instance. And the network performance bottlenecks between EC2 instances and the EBS volume that generally impact the complete system performance.<\/p>\n<p style=\"text-align: justify\">To fix these issues, we decide to leverage existing Logical Volume Managers(LVM) feature which provides the option to easily expand the size of their volume by adding one or more EBS volumes. With multiple EBS volumes, network performance is increased between AWS resources like EC2 instances and EBS volumes.<\/p>\n<p style=\"text-align: justify\">In my post, I will walk through the procedure of setting up with the LVMs on Ubuntu in the <a title=\"devops in AWS\" href=\"http:\/\/www.tothenew.com\/devops-aws\">AWS EC2 environment<\/a>, and some time period for the maintenance to add and remove (where possible) storage to avoid the interruption or any downtime.<\/p>\n<h3><strong>Getting Started<\/strong><\/h3>\n<ul>\n<li>In my case, we are attaching three EBS volumes with 1GB SSD . The EBS volumes are given the following device names: <em>&#8216;\/dev\/xvdb<\/em>, <em>&#8216;\/dev\/xvdc&#8217;<\/em> and <em>&#8216;\/dev\/xvdd&#8217;<\/em>. (To Make LVM utilities installed):<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40856 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-155134.png\" alt=\"Screenshot from 2016-09-26 15:51:34\" width=\"646\" height=\"133\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-155134.png 646w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-155134-300x61.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-155134-624x128.png 624w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/li>\n<li>The first step, launch a base image Ubuntu EC2 instance launched with the IAM Role\/Profile; the root file system is an EBS Volume.<\/li>\n<li>Initialize &#8220;pvcreate&#8221;\u00a0on the additional volumes to use with LVM filesystem. In order to do this, we need to use the &#8220;pvcreate&#8221; command. And &#8220;pvcreate&#8221; command is mainly used to initialize disk or partitions that will be used by LVM. It can either initialize a whole disk or a partition on the physical disks.Syntax so &#8220;pvcreate &lt;device-a&gt; &lt;device-b&gt;\u00a0&lt;device-c&gt;\u00a0&lt;device-n&gt;&#8221;<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40865 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-160937.png\" alt=\"Screenshot from 2016-09-26 16:09:37\" width=\"623\" height=\"55\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-160937.png 623w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-160937-300x26.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/li>\n<li>Use the &#8220;pvdisplay&#8221; command utility to display information about mount physical disks:<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40867 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-162827.png\" alt=\"Screenshot from 2016-09-26 16:28:27\" width=\"625\" height=\"319\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-162827.png 625w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-162827-300x153.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-162827-624x318.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/li>\n<li>Then volume group called &#8220;vgebs&#8221; is created. This volume group includes our two disks:<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40874 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-163639.png\" alt=\"Screenshot from 2016-09-26 16:36:39\" width=\"625\" height=\"34\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-163639.png 625w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-163639-300x16.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-163639-624x33.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/li>\n<li>Once the LVM volume group is created, use the &#8220;vgdisplay&#8221; command to show its attributes.<\/li>\n<li>Create Logical Volumes. Once the LVM volume group is created, now it&#8217;s time to create logical volumes Syntax: \u00a0 \u00a0sudo lvcreate &#8211;name &lt;logical-volume-name&gt; &#8211;size &lt;size-of-volume&gt; &lt;lvm-volume-name&gt;\u00a0<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40880 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-164240.png\" alt=\"Screenshot from 2016-09-26 16:42:40\" width=\"623\" height=\"47\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-164240.png 623w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-164240-300x22.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/li>\n<li>This will create a new device located at &#8220;\/dev\/mapper\/vgebs-lvebs&#8221;. And this is our LVM volume, and we can now create a filesystem and mount it. Once the LVM volumes are created, then we can format them using any another type of filesystem like ext3, XFS, ext4 and more. If you are using the filesystem&#8221;ext3&#8243; :<br \/>\nmkfs.ext3 \u00a0&lt;logical-volume-path&gt;\u00a0<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40882 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-164549.png\" alt=\"Screenshot from 2016-09-26 16:45:49\" width=\"622\" height=\"348\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-164549.png 622w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-164549-300x167.png 300w\" sizes=\"(max-width: 622px) 100vw, 622px\" \/><\/li>\n<li>To mount the logical volumes using the mount command:<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40884 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-165056.png\" alt=\"Screenshot from 2016-09-26 16:50:56\" width=\"623\" height=\"15\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-165056.png 623w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-165056-300x7.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/li>\n<li>If we want then mount points to be available after reboot the system, we can add mount point entries in file\u00a0<em>&#8216;\/etc\/fstab&#8217;<\/em>.And check the status using mount volume:<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40885 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-165329.png\" alt=\"Screenshot from 2016-09-26 16:53:29\" width=\"620\" height=\"157\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-165329.png 620w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-165329-300x75.png 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/li>\n<li>Our first step is to create two more EBS volumes (1GB each) and attach to AWS ec2 instance. And now we are running out of disk space on EBS for our mount point? So we need to increase it out by now we initialize this as the Physical volume for the LVM. After the new volumes have been attached to our EC2 instance we check &#8220;dmesg&#8221; to check the exact mapping (EC2 instances may sometimes change the name of the devices):<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40889 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170408.png\" alt=\"Screenshot from 2016-09-26 17:04:08\" width=\"624\" height=\"31\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170408.png 624w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170408-300x14.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40890 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170537.png\" alt=\"Screenshot from 2016-09-26 17:05:37\" width=\"624\" height=\"481\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170537.png 624w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170537-300x231.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/li>\n<li>And then add this disk to our existing &#8220;vgebs&#8221; Volume Group:<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40891 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170738.png\" alt=\"Screenshot from 2016-09-26 17:07:38\" width=\"624\" height=\"38\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170738.png 624w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-170738-300x18.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/li>\n<li>Now we extend the LVM volume to use the whole size of the group. Please note that in theory, we should \u00a0&#8220;lvextend&#8221; to use 800Mb or 0.8G, but since the LVM needs to reserve some space for internal data we must leave a few GiB available:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40893 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-171043.png\" alt=\"Screenshot from 2016-09-26 17:10:43\" width=\"626\" height=\"76\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-171043.png 626w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-171043-300x36.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-171043-624x75.png 624w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/li>\n<li>We can now use &#8220;resize2fs&#8221; to extend the filesystem until the end of the LVM volume:<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40894 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-171217.png\" alt=\"Screenshot from 2016-09-26 17:12:17\" width=\"624\" height=\"66\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-171217.png 624w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-171217-300x31.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/li>\n<li>Check the status of the mount point &#8220;\/var\/lib\/jenkins&#8221;. Then we will find that the disk size of the device &#8220;\/dev\/mapper\/vgebs-lvebs&#8221; increased to 1.9GB to 2.7GB:<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40905 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-172101.png\" alt=\"Screenshot from 2016-09-26 17:21:01\" width=\"622\" height=\"129\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-172101.png 622w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Screenshot-from-2016-09-26-172101-300x62.png 300w\" sizes=\"(max-width: 622px) 100vw, 622px\" \/><\/li>\n<\/ul>\n<h3>Once the LVMs are created and mounted, we can use these as \u00a0normal volumes. However, LVM offers:<\/h3>\n<ul>\n<ul>\n<li><strong>With Better performance<\/strong> \u2013 If data is spread across all the multiple EBS volumes using LVM, we can leverage the dedicated network throughput \u00a0between AWS EC2 and EBS. This provides us better network throughput over a single network channel between EC2 instances and EBS volumes.<\/li>\n<li><strong>Ability to grow<\/strong> \u2013 We also expand volume at any time according to requirement. More EBS volumes can be added to existing LVM volume instead of creating a snapshot of an EBS volume and expanding it.<\/li>\n<li><strong>The EBS volume snapshots<\/strong> \u2013 Also, need to ensure that on disk there are no operations happening on EBS volume during snapshots. Also to suspend the operation (Read or Write) on the LVM volume by using \u00a0&#8220;dmsetup&#8221; command.<\/li>\n<\/ul>\n<\/ul>\n<p style=\"text-align: left;padding-left: 90px\">Syntax for the suspend : # dmsetup suspend &lt;lvm-volume-name&gt;<br \/>\nSyntax for the resume : # dmsetup resume &lt;lvm-volume-name&gt;<br \/>\nAs mentioned in my post, LVMs volume backup can be created using the EBS snapshot procedure, but need to ensure that LVM volume operations are suspended for that time duration .<\/p>\n<p>Hope my blog helps you in understanding the concept of the extended EBS backed LVM volume.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sharing one of my use-cases, Jenkins has been increasing \u00a0over past few weeks, and we were about to hit the 50GB capping for Elastic Block Storage volumes on the Amazon EC2. And this is a problem that is affecting a lot of our team\u00a0developers to test their build packages on the different environments. But, every [&hellip;]<\/p>\n","protected":false},"author":215,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":17},"categories":[1174,2348,1],"tags":[2366,4071,4068,3233,1892,4070,573,4074,4069,4072,4067],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40852"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/215"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=40852"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40852\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=40852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=40852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=40852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}