{"id":4128,"date":"2015-01-27T19:02:56","date_gmt":"2015-01-27T11:02:56","guid":{"rendered":"http:\/\/rmohan.com\/?p=4128"},"modified":"2015-01-27T19:02:56","modified_gmt":"2015-01-27T11:02:56","slug":"extending-root-partition-using-lvm","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4128","title":{"rendered":"Extending root partition using LVM"},"content":{"rendered":"<p>After deploying a VMware virtual machine via template, it may be necessary to extend the root file system based on use requirements as templates typically are minimal in their configuration.  In this example, I opted to add a virtual disk instead of increasing the size of the existing vmdk, and extend the LVM vg (volume group) and lv (logical volume), then the file system itself.<\/p>\n<p>In this particular example, the above description will be performed on a RedHat 6.3 OS.  Therefore, there is no need to manually add the disk as the kernel now does so automatically.<\/p>\n<p>The steps to be performed include:<\/p>\n<p>fdisk to verify presence of new disk<br \/>\npvcreate to initialize the new disk<br \/>\nIn this example, I do NOT create a partition on the new disk.  Instead, I&#8217;m just using the whole disk.  In the case of physical media (using a recycled disk from another system), and you opt to use the whole disk device only (instead of partitioning it first), the partition table must be erased, which will obviously destroy all data on that disk, so be sure this is what you want to do.  Refer to the pvcreate man page.  To erase the partition table on a previously used disk, zero out the first sector with:<br \/>\ndd if=\/dev\/zero of=PhysicalVolume bs=512 count=1<br \/>\nvgextend to add the newly created physical volume to a volume group<br \/>\nlvextend to extend the size of the logical volume<br \/>\nresize2fs to resize the root partition, which of course is mounted.  Refer to the resize2fs man page, citing &#8220;If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing.  (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.).&#8221;<br \/>\nReal life example:<\/p>\n<p>QAMAIN ctbapp2a ~ # df -Ph \/<br \/>\nFilesystem                       Size  Used Avail Use% Mounted on<br \/>\n\/dev\/mapper\/vg_ctbapp2a-lv_root   16G  2.7G   12G  19% \/<br \/>\nQAMAIN ctbapp2a ~ #<br \/>\nQAMAIN ctbapp2a ~ # fdisk -l \/dev\/sdb<\/p>\n<p>Disk \/dev\/sdb: 21.5 GB, 21474836480 bytes<br \/>\n64 heads, 32 sectors\/track, 20480 cylinders<br \/>\nUnits = cylinders of 2048 * 512 = 1048576 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisk identifier: 0x00000000<\/p>\n<p>QAMAIN ctbapp2a ~ # pvcreate \/dev\/sdb<br \/>\n  Physical volume &#8220;\/dev\/sdb&#8221; successfully created<br \/>\nQAMAIN ctbapp2a ~ #<br \/>\nQAMAIN ctbapp2a ~ # vgextend vg_ctbapp2a \/dev\/sdb<br \/>\n  Volume group &#8220;vg_ctbapp2a&#8221; successfully extended<br \/>\nQAMAIN ctbapp2a ~ #<br \/>\nQAMAIN ctbapp2a ~ # lvextend \/dev\/vg_ctbapp2a\/lv_root \/dev\/sdb<br \/>\n  Extending logical volume lv_root to 35.63 GiB<br \/>\n  Logical volume lv_root successfully resized<br \/>\nQAMAIN ctbapp2a ~ #<br \/>\nQAMAIN ctbapp2a ~ # resize2fs \/dev\/vg_ctbapp2a\/lv_root<br \/>\nresize2fs 1.41.12 (17-May-2010)<br \/>\nFilesystem at \/dev\/vg_ctbapp2a\/lv_root is mounted on \/; on-line resizing required<br \/>\nold desc_blocks = 1, new_desc_blocks = 3<br \/>\nPerforming an on-line resize of \/dev\/vg_ctbapp2a\/lv_root to 9339904 (4k) blocks.<br \/>\nThe filesystem on \/dev\/vg_ctbapp2a\/lv_root is now 9339904 blocks long.<\/p>\n<p>QAMAIN ctbapp2a ~ # df -Ph \/<br \/>\nFilesystem                       Size  Used Avail Use% Mounted on<br \/>\n\/dev\/mapper\/vg_ctbapp2a-lv_root   36G  2.7G   31G   8% \/<br \/>\nIn the case of physical disk storage, the process would be nearly identical when adding another physical hard disk.  If you do not have the option to add physical media, and there exists ample storage on the disk containing the root file system, you can extend said disk by adding another partition to it.  This would require a reboot for the changes to be seen, otherwise, the overall process would be the same except you&#8217;d specify the newly created partition in the place of \/dev\/sdb above from the pvcreate command on down.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After deploying a VMware virtual machine via template, it may be necessary to extend the root file system based on use requirements as templates typically are minimal in their configuration. In this example, I opted to add a virtual disk instead of increasing the size of the existing vmdk, and extend the LVM vg (volume [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4128"}],"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=4128"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4128\/revisions"}],"predecessor-version":[{"id":4129,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4128\/revisions\/4129"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}