{"id":7158,"date":"2018-01-09T14:10:19","date_gmt":"2018-01-09T06:10:19","guid":{"rendered":"http:\/\/rmohan.com\/?p=7158"},"modified":"2018-01-09T14:10:19","modified_gmt":"2018-01-09T06:10:19","slug":"how-to-extend-a-root-lvm-partition-online","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7158","title":{"rendered":"How-to extend a root LVM partition online"},"content":{"rendered":"<h1 class=\"post-title\">How-to extend a root LVM partition online<\/h1>\n<p>This guide will explain you how to extend a root LVM partition online.<\/p>\n<p>There is also a quick remedy for the emergency situation when your root partition runs out of disk space. There is a feature specific to ext3 and ext4 that can help the goal of resolving the full disk situation. Unless explicitly changed during filesystem creation, both by default reserve five percent (5%) of a volume capacity to the superuser (root).<\/p>\n<pre><code><span style=\"font-size: large;\"># df -Th<\/span>\r\n<span style=\"font-size: large;\">Filesystem    Type    Size  Used Avail Use% Mounted on<\/span>\r\n<span style=\"font-size: large;\">\/dev\/mapper\/vg_main-lv_root<\/span>\r\n<span style=\"font-size: large;\">              ext4    8.4G  8.0G  952K 100% \/<\/span>\r\n<span style=\"font-size: large;\">tmpfs        tmpfs    499M     0  499M   0% \/dev\/shm<\/span>\r\n<span style=\"font-size: large;\">\/dev\/vda1     ext4    485M   33M  428M   8% \/boot<\/span>\r\n\r\n<span style=\"font-size: large;\"># dumpe2fs \/dev\/vg_main\/lv_root | grep 'Reserved block count'<\/span>\r\n<span style=\"font-size: large;\">dumpe2fs 1.41.12 (17-May-2010)<\/span>\r\n<span style=\"font-size: large;\">Reserved block count:     111513\r\n<\/span><\/code><\/pre>\n<p>It turned out 111513 of 4KB blocks were reserved for the superuser, which was exactly five percent of the volume capacity.<\/p>\n<p><strong>How to enable it?<\/strong><\/p>\n<pre><code><span style=\"font-size: large;\"># tune2fs -m 0 \/dev\/vg_main\/lv_root <\/span>\r\n<span style=\"font-size: large;\">tune2fs 1.41.12 (17-May-2010)<\/span>\r\n<span style=\"font-size: large;\">Setting reserved blocks percentage to 0% (0 blocks)\r\n<\/span><\/code><\/pre>\n<pre><code><span style=\"font-size: large;\"># df -Th<\/span>\r\n<span style=\"font-size: large;\">Filesystem    Type    Size  Used Avail Use% Mounted on<\/span>\r\n<span style=\"font-size: large;\">\/dev\/mapper\/vg_main-lv_root<\/span>\r\n<span style=\"font-size: large;\">              ext4    8.4G  8.0G  437M  95% \/<\/span>\r\n<span style=\"font-size: large;\">tmpfs        tmpfs    499M     0  499M   0% \/dev\/shm<\/span>\r\n<span style=\"font-size: large;\">\/dev\/vda1     ext4    485M   33M  428M   8% \/boot\r\n<\/span><\/code><\/pre>\n<p>Now that we have some free space on the root partition to work on we can extend the LVM partition:<\/p>\n<p>Create a new partition of appropriate size using fdisk<\/p>\n<pre><code><span style=\"font-size: large;\">fdisk \/dev\/sdb1\r\n<\/span><\/code><\/pre>\n<p>This is a key sequence on the keyboard to create a new LVM type (8e) partition:<\/p>\n<p>n, p, 1, enter (accept default first sector), enter (accept default last sector), t, 8e, w<\/p>\n<p>Create a new Physical Volume<\/p>\n<pre><code><span style=\"font-size: large;\"># pvcreate \/dev\/sdb1<\/span>\r\n<span style=\"font-size: large;\">  Writing physical volume data to disk \"\/dev\/sdb1\"<\/span>\r\n<span style=\"font-size: large;\">  Physical volume \"\/dev\/sdb1\" successfully created\r\n<\/span><\/code><\/pre>\n<p>Extend a Volume Group<\/p>\n<pre><code><span style=\"font-size: large;\"># vgextend vg_main \/dev\/sdb1<\/span>\r\n<span style=\"font-size: large;\">  Volume group \"vg_main\" successfully extended\r\n<\/span><\/code><\/pre>\n<p>Extend your LVM<\/p>\n<p>&#8211; extend the size of your LVM by the amount of free space on PV<\/p>\n<pre><code><span style=\"font-size: large;\"># lvextend \/dev\/vg_main\/lv_root \/dev\/sdb1<\/span>\r\n<span style=\"font-size: large;\">  Extending logical volume lv_root to 18.50 GiB<\/span>\r\n<span style=\"font-size: large;\">  Logical volume lv_root successfully resized\r\n<\/span><\/code><\/pre>\n<p>&#8211; or with a given size<\/p>\n<pre><code><span style=\"font-size: large;\">lvextend -L +10G \/dev\/vg_main\/lv_root\r\n<\/span><\/code><\/pre>\n<p>Finally resize the file system online<\/p>\n<pre><code><span style=\"font-size: large;\"># resize2fs \/dev\/vg_main\/lv_root<\/span>\r\n<span style=\"font-size: large;\">resize2fs 1.41.12 (17-May-2010)<\/span>\r\n<span style=\"font-size: large;\">Filesystem at \/dev\/vg_main\/lv_root is mounted on \/; on-line resizing required<\/span>\r\n<span style=\"font-size: large;\">old desc_blocks = 1, new_desc_blocks = 2<\/span>\r\n<span style=\"font-size: large;\">Performing an on-line resize of \/dev\/vg_main\/lv_root to 4850688 (4k) blocks.<\/span>\r\n<span style=\"font-size: large;\">The filesystem on \/dev\/vg_main\/lv_root is now 4850688 blocks long.\r\n<\/span><\/code><\/pre>\n<p>Now we can set the reserved blocks back to the default percentage &#8211; 5%<\/p>\n<pre><code><span style=\"font-size: large;\">tune2fs -m 5 \/dev\/mapper\/vg_main-lv_root\r\n<\/span><\/code><\/pre>\n<p>Results:<\/p>\n<pre><code><span style=\"font-size: large;\"># df -Th<\/span>\r\n<span style=\"font-size: large;\">Filesystem    Type    Size  Used Avail Use% Mounted on<\/span>\r\n<span style=\"font-size: large;\">\/dev\/mapper\/vg_main-lv_root<\/span>\r\n<span style=\"font-size: large;\">              ext4     19G  8.0G  9.4G  46% \/<\/span>\r\n<span style=\"font-size: large;\">tmpfs        tmpfs    499M     0  499M   0% \/dev\/shm<\/span>\r\n<span style=\"font-size: large;\">\/dev\/vda1     ext4    485M   33M  428M   8% \/boot\r\n<\/span><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How-to extend a root LVM partition online <\/p>\n<p>This guide will explain you how to extend a root LVM partition online.<\/p>\n<p>There is also a quick remedy for the emergency situation when your root partition runs out of disk space. There is a feature specific to ext3 and ext4 that can help the goal of resolving [&#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\/7158"}],"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=7158"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7158\/revisions"}],"predecessor-version":[{"id":7159,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7158\/revisions\/7159"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}