{"id":116,"date":"2022-07-05T21:51:34","date_gmt":"2022-07-05T21:51:34","guid":{"rendered":"https:\/\/jasonisenhart.com\/?p=116"},"modified":"2023-06-02T21:26:20","modified_gmt":"2023-06-02T21:26:20","slug":"linux-lvm-explaind-source-https-shorturl-at-diksz","status":"publish","type":"post","link":"https:\/\/jasonisenhart.com\/index.php\/2022\/07\/05\/linux-lvm-explaind-source-https-shorturl-at-diksz\/","title":{"rendered":"Linux LVM Explained (Source: https:\/\/shorturl.at\/diksz )"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Linux LVM Briefly Explained<\/h1>\n\n\n\n<p>If you followed the default settings in the Ubuntu installation, then the storage for your Linux OS is probably using the Logical Volume Manager (LVM). LVM is an abstraction framework which exists between your physical (or virtual) disks and your Linux file system (which is likely&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Ext4\" target=\"_blank\" rel=\"noreferrer noopener\">ext4<\/a>). It is used to group separate block devices (partitions) together into Volume Groups (VGs), and then chop those VGs up into logical block devices, or Logical Volumes (LVs). LV\u2019s are the abstracted block devices upon which your usable file system resides.<\/p>\n\n\n\n<p>Below is good visualization of how LVM works. In this example, we have 5 different disks, each with a single partition mapped to Physical Volumes (PVs), all being grouped into a single Volume Group (VG). The Volume Group is chopped up into two different Logical Volumes (LVs) and each LV is being used for a filesystem.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/LogicalVolumenManager.jpg\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/LogicalVolumenManager.jpg\" alt=\"\" class=\"wp-image-51995\"\/><\/a><\/figure>\n\n\n\n<p>Using a similar visualization, the below diagram shows how the Ubuntu installer (using all default options) divided up my 100GB disk.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/LVM.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/LVM-590x426.png\" alt=\"\" class=\"wp-image-51996\"\/><\/a><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Ubuntu Installer Default Settings<\/h1>\n\n\n\n<p>When installing Ubuntu, it has you approve a storage layout in a couple different screens (shown below). By default this storage layout will have a couple small boot partitions, and a third partition, which will be used by your LVM to create your root filesystem. You should be able to see the consistency between the screens below and the diagram above.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/disks1.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/disks1-590x410.png\" alt=\"\" class=\"wp-image-52000\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/disks2.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/disks2-590x407.png\" alt=\"\" class=\"wp-image-52001\"\/><\/a><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Use Your Default Free Space<\/h1>\n\n\n\n<p>As you can see above: the Ubuntu installer (by default)&nbsp;<strong>left almost half of my disk space unusable by the root file system!<\/strong>&nbsp;I\u2019ve looked around to find an explanation on why these are the default settings, but can\u2019t find anything. Before extending your underlying hypervisor disk or storage volume, you may want to see if you have free space available and ready to be used to extend your existing file system. If you used the Ubuntu defaults during installation, then there is a good chance you have this free space.<\/p>\n\n\n\n<p>Start by checking your root filesystem free space with&nbsp;df -h. As you can see I am only using&nbsp;<strong>14%<\/strong>&nbsp;of my&nbsp;<strong>~49GB<\/strong>&nbsp;volume, but we\u2019ll pretend I\u2019m close to 100% and need to make that 49GB volume larger.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen1.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen1-590x258.png\" alt=\"\" class=\"wp-image-52002\"\/><\/a><\/figure>\n\n\n\n<p>To check for existing free space on your Volume Group (where it is left by the installer default settings), run the command&nbsp;vgdisplay&nbsp;and check for free space. Here you can see I have&nbsp;<strong>49.25GB<\/strong>&nbsp;of free space ready to be used. If you don\u2019t have any free space, move on to the next section to use some free space from an extended physical (or virtual) disk.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen2.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen2.png\" alt=\"\" class=\"wp-image-52005\"\/><\/a><\/figure>\n\n\n\n<p>To use up that free space on your Volume Group (VG) for your root Logical Volume (LV), first run the&nbsp;lvdisplay&nbsp;command and check the Logical Volume size, then run&nbsp;lvextend -l +100%FREE \/dev\/ubuntu-vg\/ubuntu-lv&nbsp;to extend the LV to the maximum size usable, then run&nbsp;lvdisplay&nbsp;one more time to make sure it changed.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen3.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen3-590x557.png\" alt=\"\" class=\"wp-image-52007\"\/><\/a><\/figure>\n\n\n\n<p>At this point you have increased the size of the block volume where your root filesystem resides, but you still need to extend the filesystem on top of it. First, run&nbsp;df -h&nbsp;to verify your (almost full) root file system, then run&nbsp;resize2fs \/dev\/mapper\/ubuntu&#8211;vg-ubuntu&#8211;lv&nbsp;to extend your filesystem, and run&nbsp;df -h&nbsp;one more time to make sure you\u2019re successful.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>resize2fs \/dev\/mapper\/ubuntu--vg-ubuntu--lv<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen4.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen4-577x590.png\" alt=\"\" class=\"wp-image-52009\"\/><\/a><\/figure>\n\n\n\n<p>And that\u2019s it. You just allocated the free space left behind by the Ubuntu installer to your root filesystem. If this is still not enough space, continue on to the next section to allocate more space by extending an underlying disk.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Use Space from Extended Physical (or Virtual) Disk<\/h1>\n\n\n\n<p>First you need to increase the size of the disk being presented to the Linux OS. This is most likely done by expanding the virtual disk in KVM\/VMWare\/Hyper-V or by adjusting your RAID controller \/ storage system to increase the volume size. You can often do this while Linux is running; without shutting down or restarting. I\u2019ve extended my&nbsp;<strong>100GB<\/strong>&nbsp;disk to&nbsp;<strong>200GB<\/strong>&nbsp;for my example machine.<\/p>\n\n\n\n<p>Once that is done, you may need to get Linux to rescan the disk for the new free space. Check for free space by running\u00a0cfdisk\u00a0and see if there is free space listed, use \u201cq\u201d to exit once you\u2019re done.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cfdisk<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen6.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen6-590x320.png\" alt=\"\" class=\"wp-image-52010\"\/><\/a><\/figure>\n\n\n\n<p>If you don\u2019t see free space listed, then initiate a rescan of\u00a0\/dev\/sda\u00a0 with\u00a0echo 1>\/sys\/class\/block\/sda\/device\/rescan. Once done, rerun\u00a0cfdisk\u00a0and you should see the free space listed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/dev\/sda\u00a0 with\u00a0echo 1>\/sys\/class\/block\/sda\/device\/rescan<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen7.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen7-590x336.png\" alt=\"\" class=\"wp-image-52013\"\/><\/a><\/figure>\n\n\n\n<p>Select your&nbsp;\/dev\/sda3&nbsp;partition from the list and then select \u201c<strong>Resize<\/strong>\u201d from the bottom menu. Hit&nbsp;<strong>ENTER<\/strong>&nbsp;and it will prompt you to confirm the new size. Hit&nbsp;<strong>ENTER<\/strong>&nbsp;again and you will now see the&nbsp;\/dev\/sda3&nbsp;partition with a new larger size.<\/p>\n\n\n\n<p>Select \u201c<strong>Write<\/strong>\u201d from the bottom menu, type&nbsp;<strong>yes<\/strong>&nbsp;to confirm, and hit&nbsp;<strong>ENTER<\/strong>. Then use \u201c<strong>q<\/strong>\u201d to exit the program.<\/p>\n\n\n\n<p>Now that the LVM partition backing the\u00a0\u00a0\/dev\/sda3\u00a0Physical Volume (PV) has been extended, we need to extend the PV itself. Run\u00a0pvresize \/dev\/sda3\u00a0to do this and then use\u00a0pvdisplay\u00a0to check the new size.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pvresize \/dev\/sda3<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen8.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen8-590x268.png\" alt=\"\" class=\"wp-image-52014\"\/><\/a><\/figure>\n\n\n\n<p>As you can see above, my PV has been increased from 98.5GB to 198.5GB. Now let\u2019s check the Volume Group (VG) free space with&nbsp;vgdisplay.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen10.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen10.png\" alt=\"\" class=\"wp-image-52019\"\/><\/a><\/figure>\n\n\n\n<p>We can see above that the VG has 100GB of free space. Now let\u2019s check the size of our upstream Logical Volume (LV) using\u00a0lvdisplay, extend the LV to use up all the VG\u2019s free space with\u00a0lvextend -l +100%FREE \/dev\/ubuntu-vg\/ubuntu-lv, and then check the LV one more time with\u00a0lvdisplay\u00a0to make sure it has been extended.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>lvextend -l +100%FREE \/dev\/ubuntu-vg\/ubuntu-lv<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen11.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen11-590x563.png\" alt=\"\" class=\"wp-image-52025\"\/><\/a><\/figure>\n\n\n\n<p>At this point, the block volume underpinning our root filesystem has been extended, but the filesystem itself has not been resized to fit that new volume. To do this, run\u00a0df -h\u00a0to check the current size of the file system, then run\u00a0resize2fs \/dev\/mapper\/ubuntu&#8211;vg-ubuntu&#8211;lv\u00a0to resize it, and\u00a0df -h\u00a0one more time to check the new file system available space.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>resize2fs \/dev\/mapper\/ubuntu--vg-ubuntu--lv<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen12.png\"><img decoding=\"async\" src=\"https:\/\/packetpushers.net\/wp-content\/uploads\/2021\/11\/screen12-583x590.png\" alt=\"\" class=\"wp-image-52020\"\/><\/a><figcaption class=\"wp-element-caption\">I decided to copy and paste the post for archiving purposes from https:\/\/packetpushers.net\/ubuntu-extend-your-default-lvm-space\/#:~:text=To%20do%20this%2C%20run%20df,new%20file%20system%20available%20space.<\/figcaption><\/figure>\n\n\n\n<p>This was purely because this walkthrough was so well done there is no need to rewrite it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux LVM Briefly Explained If you followed the default settings in the Ubuntu installation, then the storage for your Linux OS is\u2026<\/p>\n","protected":false},"author":1,"featured_media":119,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it-how-to"],"_links":{"self":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":7,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions\/148"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/media\/119"}],"wp:attachment":[{"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jasonisenhart.com\/index.php\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}