{"id":982,"date":"2014-01-01T18:25:55","date_gmt":"2014-01-02T02:25:55","guid":{"rendered":"http:\/\/yan.lalife.net\/?p=982"},"modified":"2026-01-20T05:08:02","modified_gmt":"2026-01-20T05:08:02","slug":"resize-root-on-a-virtual-machine-on-vmware","status":"publish","type":"post","link":"http:\/\/www.lalife.net\/?p=982","title":{"rendered":"Resize root partition of a virtual machine on VMware"},"content":{"rendered":"<p>When it comes to a situation that the disk space is not enough on a virtual machine, it&#8217;s easy to extend the disk space if it&#8217;s on LVM, even the \/root partition.<\/p>\n<p>This <a href=\"https:\/\/nikino.net\/resizing-ext4-partitions-on-a-live-centos-virtual-machine\/\">post<\/a> is very helpful.<\/p>\n<p>For my own memo:<br \/>\nCase:<br \/>\nVM on VMware, installed with CentOS 6.x<br \/>\n#fdisk -l shows<br \/>\nDisk \/dev\/sda: 12GB &#8230;.<br \/>\n\/dev\/sda1 2 501 512000 83 Linux<br \/>\n\/dev\/sda2 502 12288 12069888 8e Linux LVM<\/p>\n<p>On \/dev\/sda2<br \/>\nDisk \/dev\/mapper\/vg_node1-lv_root: 7.5 GB<br \/>\nDisk \/dev\/mapper\/vg_node1-lv_swap: 4 GB<\/p>\n<p>Goal: Add 8G extra space to \/dev\/mapper\/vg_node1-lv_root<\/p>\n<p>Steps:<br \/>\n1. Using VMware GUI to add 8G to the virtual machine. Make sure it recognizes   the new size. <\/p>\n<p>2. Memo the current cylinder start number of \/dev\/sda2<br \/>\n   \/dev\/sda2 502 12288 12069888 8e Linux LVM<\/p>\n<p>3. Delete partition \/dev\/sda2 then recreate it with the new size<br \/>\n   <strong>fdisk \/dev\/sda<\/strong><br \/>\n   Use command &#8220;d&#8221;, then &#8220;2&#8221; to delete \/dev\/sda2<br \/>\n   Use &#8220;n&#8221; to create a new partition, partition number is &#8220;2&#8221;<br \/>\n   Use &#8220;t&#8221; to change partition type to 8e as &#8220;Linux LVM&#8221;<br \/>\n   Then &#8220;w&#8221; to save the change<\/p>\n<p>Reboot the VM<\/p>\n<p>Now the partition size is changed. I need to change the pv size and vg size.<\/p>\n<p>5. Change pv size<br \/>\n   <strong>pvsize \/dev\/sda2<\/strong><\/p>\n<p>6. Change vg size<br \/>\n   #<strong>vgdisplay<\/strong>  (found the free PE = 2048 )<br \/>\n   #<strong>lvextend \/dev\/mapper\/vg_node1-lv_root &#8211;extents +2048<\/strong><\/p>\n<p>7. Still need to increase file system size<br \/>\n   #<strong>resize2fs \/dev\/mapper\/vg_node1-lv_root<\/strong><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nAnother way to do it<\/p>\n<p>1. Add disk space from vmware GUI, however the following command didn&#8217;t work, so reboot<br \/>\necho &#8220;- &#8211; -&#8221; > \/sys\/class\/scsi_host\/host0\/scan<\/p>\n<p>2. frisk -l shows new disk space on \/dev\/sda<br \/>\ncreate a new partition on \/dev\/sda<br \/>\nfrisk \/dev\/sda -> n -> p -> 3 -> it will show the right start\/end block number automatically, so just hit enter,<br \/>\n-> t -> 8e -> w<\/p>\n<p>3. fdisk shows \/dev\/sda3, the new partition created.<br \/>\nHowever it warns the kernel won&#8217;t use the new table until reboot, so reboot for the 2nd time<\/p>\n<p>4. Create a new physical volume on lvm using sda3<br \/>\npvcreate \/dev\/sda3<\/p>\n<p>5. find vg name from vgdisplay, find vg name is using &#8220;centos&#8221;, add sda3 to virtual group<br \/>\nvgextend centos \/dev\/sda3<\/p>\n<p>6. pvscan shows sda3 as a member of vg &#8220;centos&#8221;<br \/>\n[root@mononoke ~]# pvscan<br \/>\n  PV \/dev\/sda2   VG centos   lvm2 [15.51 GiB \/ 0    free]<br \/>\n  PV \/dev\/sda3   VG centos   lvm2 [9.00 GiB \/ 0    free]<br \/>\n  Total: 2 [24.50 GiB] \/ in use: 2 [24.50 GiB] \/ in no VG: 0 [0   ] <\/p>\n<p>7. lvdisplay shows 2 logical volumes, \/dev\/centos\/root and \/dev\/centos\/swap,<br \/>\n   lvextend \/dev\/centos\/root \/dev\/sda3<\/p>\n<p>8. resize file system, since it&#8217;s using XFS on centos7,<br \/>\nxfs_growfs \/dev\/centos\/root<\/p>\n<p><a href=\"http:\/\/www.rootusers.com\/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-machine-disk\/\" title=\"Here\">Here<\/a>&#8216;s the reference<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n To check how much free space left in a physical volume, do pvdisplay, then find value of &#8220;Free PE&#8221;<\/p>\n<p> &#8212; Physical volume &#8212;<br \/>\n  PV Name               \/dev\/sdb2<br \/>\n  VG Name               test_vg<br \/>\n  PV Size               20.00 GiB \/ not usable 1.31 MiB<br \/>\n  Allocatable           yes<br \/>\n  PE Size               4.00 MiB<br \/>\n  Total PE              5120<br \/>\n  <strong>Free PE<\/strong>               <strong>2620<\/strong><br \/>\n  Allocated PE          2500<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When it comes to a situation that the disk space is not enough on a virtual machine, it&#8217;s easy to extend the disk space if it&#8217;s on LVM, even the \/root partition. This post is very helpful. For my own &hellip; <a href=\"http:\/\/www.lalife.net\/?p=982\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-982","post","type-post","status-publish","format-standard","hentry","category-vmware"],"_links":{"self":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=982"}],"version-history":[{"count":1,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/982\/revisions"}],"predecessor-version":[{"id":1851,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/982\/revisions\/1851"}],"wp:attachment":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}