{"id":889,"date":"2011-05-26T13:48:10","date_gmt":"2011-05-26T18:48:10","guid":{"rendered":"http:\/\/www.gamescheat.ca\/?p=889"},"modified":"2019-09-04T19:57:39","modified_gmt":"2019-09-05T00:57:39","slug":"how-to-extend-the-filesystem-on-a-vmware-esx-guest-red-hat-linux-server","status":"publish","type":"post","link":"http:\/\/www.gamescheat.ca\/?p=889","title":{"rendered":"How to extend the filesystem on a Vmware ESX guest Red Hat Linux server"},"content":{"rendered":"<p>Being the administrator of a large Linux shop, I have had to extend the filesystems on the Red Hat Linux server a few times.  Each time I had the opportunity to extend  the filesystem, I found that I struggled to remember the commands and steps.  This is because Linx is a very command line driven operating system.  All right that is not completely true anymore, some variants of Linux have graphical interfaces.  Such as Red Hat has the graphical Logical Volume Manager (LVM), but I find the LVM to be buggy and unreliable at times. Personally I find it more reliable and easier to extend the filesystem using the command line interface.<\/p>\n<p><strong>The sequence to extend the filesystem is as follow.<\/strong><br \/>\n(1) Add the new disk.  In my case I was running Red Hat Enterprise 5 Linux as a guest operating system in Vmware ESX server.  I simply had to increase the disk size using the Vmware Vcenter interface, under edit setting, disk provisioning.  You will need to reboot the guest OS after to recognize the new disk size.<\/p>\n<p>(2) Partition the new disk space using fdisk.<\/p>\n<p>(3) Initialize the new partition, using the command pvcreate.  Run partprobe to update the kernel.<\/p>\n<p>(4) Extend the existing volume group with the new partition using the command vgextend.<\/p>\n<p>(5) Extend the existing logical volume group using lvextend.<\/p>\n<p>(6) Grow the filesystem with the command resize2fs.<\/p>\n<p><strong>Take a snapshot of the existing disks and to understand how they are partitioned.<\/strong><br \/>\nThe fdisk command will display the configuration of the existing disks. In this example there are two disks, a 10.7 GB \/dev\/sda and \/dev\/sdb which is 21.4 GB.  Disk sda has two partitions, sda1 and sda2. The second disk sdb has only one partition sdb1.<\/p>\n<blockquote><p>\n[root@linux_server ~]# fdisk -l<\/p>\n<p>Disk \/dev\/sda: 10.7 GB, 10737418240 bytes<br \/>\n255 heads, 63 sectors\/track, 1305 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<\/p>\n<p>  ice Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sda1   *           1          13      104391   83  Linux<br \/>\n\/dev\/sda2              14        1305    10377990   8e  Linux LVM<\/p>\n<p>Disk \/dev\/sdb: 21.4 GB, 21475491840 bytes<br \/>\n255 heads, 63 sectors\/track, 2610 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<\/p>\n<p>  ice Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sdb1               1        2610    20964793+  8e  Linux LVM<\/p><\/blockquote>\n<p>You also need to take a snapshot of how the partitions are allocated to the volume groups.  In the below example, the result of pvscan indicates that sda2 is mapped to the volume group VolGroup00.  But where is sda1?  Well sda1 is mapped to the \/boot filesystem, you will see it when you issue the mount command.  You can also use the command pvs or pvdisplay instead of pvscan.<\/p>\n<blockquote><p>[root@linux_server ~]# pvscan<br \/>\n  PV \/dev\/sdb1   VG gfs_vg       lvm2 [19.99 GB \/ 8.99 GB free]<br \/>\n  PV \/dev\/sda2   VG VolGroup00   lvm2 [9.88 GB \/ 0    free]<br \/>\n  Total: 2 [29.84 GB] \/ in use: 2 [29.84 GB] \/ in no VG: 0 [0   ]<\/p><\/blockquote>\n<p>The mount command will show you that \/dev\/sda1 is mounted as \/boot.  In this example we will be extending the \/ (root) filesystem.<\/p>\n<blockquote><p>[root@linux_server ~]# mount<br \/>\n\/dev\/mapper\/VolGroup00-LogVol00 on \/ type ext3 (rw)<br \/>\nproc on \/proc type proc (rw)<br \/>\nsysfs on \/sys type sysfs (rw)<br \/>\ndevpts on \/dev\/pts typepts (rw,gid=5,mode=620)<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw)<br \/>\ntmpfs on \/dev\/shm type tmpfs (rw)<br \/>\nnone on \/proc\/sys\/fs\/binfmt_misc type binfmt_misc (rw)<br \/>\nsunrpc on \/var\/lib\/nfs\/rpc_pipefs type rpc_pipefs (rw)<br \/>\nnone on \/sys\/kernel\/config type configfs (rw)<br \/>\n\/dev\/mapper\/gfs_vg-gfs_lv on \/mnt\/gfs type gfs2 (rw,noatime,nodiratime,hostdata=jid=0:id=196609:first=0)<\/p><\/blockquote>\n<p><strong>Add the new disk or extend the existing disk in Vmware.<\/strong><br \/>\nExpand the disk sda using the VMware Vcenter management console.  Under the summary tab of the guest server, go to edit settings \u2013 disk provisioning. Simply increase the disk size and then reboot the guest OS.<\/p>\n<p><strong>Partition the disk<\/strong><br \/>\nAfter the guest server has been rebooted it should see the size increment in sda.  You now need to partition the new disk space using the command fdisk.<\/p>\n<blockquote><p>[root@linux_server ~]# fdisk \/dev\/sda<\/p>\n<p>The number of cylinders for this disk is set to 2610.<br \/>\nThere is nothing wrong with that, but this is larger than 1024,<br \/>\nand could in certain setups cause problems with:<br \/>\n1) software that runs at boot time (e.g., old versions of LILO)<br \/>\n2) booting and partitioning software from other OSs<br \/>\n   (e.g., DOS FDISK, OS\/2 FDISK)<\/p>\n<p>Command (m for help): m  <strong>(select m to display the help screen)<\/strong><br \/>\nCommand action<br \/>\n   a   toggle a bootable flag<br \/>\n   b   edit bsd disklabel<br \/>\n   c   toggle the dos compatibility flag<br \/>\n   d   delete a partition<br \/>\n   l   list known partition types<br \/>\n   m   print this menu<br \/>\n   n   add a new partition<br \/>\n   o   create a new empty DOS partition table<br \/>\n   p   print the partition table<br \/>\n   q   quit without saving changes<br \/>\n   s   create a new empty Sun disklabel<br \/>\n   t   change a partition\u2019s system id<br \/>\n   u   change display\/entry units<br \/>\n   v   verify the partition table<br \/>\n   w   write table to disk and exit<br \/>\n   x   extra functionality (experts only)<\/p>\n<p>Command (m for help): n <strong>(select n to add a new partition)<\/strong><\/p>\n<p>Command action<br \/>\n   e   extended<br \/>\n   p   primary partition (1-4)<br \/>\np <strong>(select p to create a primary partition)<\/strong><br \/>\nPartition number (1-4): 3 (enter 3 for partition number, we already know from the output of fdisk -l that sda1 and sda2 already exist, therefore the new partition will be sda3)<\/p>\n<p>First cylinder (1306-2610, default 1306): <strong>(hit the enter key to accept the default)<\/strong><br \/>\nUsing default value 1306<br \/>\nLast cylinder or +size or +sizeM or +sizeK (1306-2610, default 2610): <strong>(press the enter key to accept the default. You can also select something lower than 2610, if you do not want to use all available free disk space)<\/strong><br \/>\nUsing default value 2610<\/p>\n<div style=\"float: right;\"><div style=\"margin: 15px 15px 15px 15px\";><script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"pub-3319935785736004\";\ngoogle_alternate_color = \"FFFFFF\";\ngoogle_ad_width = 200;\ngoogle_ad_height = 200;\ngoogle_ad_format = \"200x200_as\";\ngoogle_ad_type = \"text_image\";\ngoogle_ad_channel =\"\";\ngoogle_color_border = \"cccccc\";\ngoogle_color_link = \"cc0000\";\ngoogle_color_bg = \"ffffff\";\ngoogle_color_text = \"000000\";\ngoogle_color_url = \"008000\";\n\/\/--><\/script>\n<script type=\"text\/javascript\"\n  src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><\/div><\/div><p>Command (m for help): t <strong>(select t to change the system id)<\/strong><br \/>\nPartition number (1-4): 3 <strong>(select the new partition number)<\/strong><br \/>\nHex code (type L to list codes): 8e <strong>(Enter 8e which is the code for Linux LVM)<\/strong><br \/>\nChanged system type of partition 3 to 8e <strong>(Linux LVM)<\/strong><\/p>\n<p>Command (m for help): p <strong>(this will print the partition table, verify the changes you made)<\/strong><\/p>\n<p>Disk \/dev\/sda: 21.4 GB, 21474836480 bytes<br \/>\n255 heads, 63 sectors\/track, 2610 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<\/p>\n<p>  ice Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sda1   *           1          13      104391   83  Linux<br \/>\n\/dev\/sda2              14        1305    10377990   8e  Linux LVM<br \/>\n\/dev\/sda3            1306        2610    10482412+  8e  Linux LVM<\/p>\n<p>Command (m for help): w <strong>(this will write the table tto disk committing it)<\/strong><br \/>\nThe partition table has been altered!<br \/>\nCalling ioctl() to re-read partition table.<br \/>\nWARNING: Re-reading the partition table failed with error 16:ice or resource busy.<br \/>\nThe kernel still uses the old table.<br \/>\nThe new table will be used at the next reboot.<br \/>\nSyncing disks.<\/p>\n<p>Note: <strong>(May have to hit enter to get command prompt back)<\/strong><\/p><\/blockquote>\n<p><strong>Initialize the physical volume<\/strong><br \/>\nInitialize the new physical volume with the command pvcreate \/dev\/sda3. If you have not rebooted the operating system after creating the new partition, then you will need to run partprobe for the kernel to recognize the new partition. Or else you will get an error.<\/p>\n<blockquote><p>[root@linux_server ~]# pvcreate \/dev\/sda3<br \/>\n ice \/dev\/sda3 not found (or ignored by filtering).<\/p><\/blockquote>\n<p>Run partrobe to update the kernel.<\/p>\n<blockquote><p>[root@linux_server]# partprobe -s<br \/>\n\/dev\/sda: msdos partitions 1 2 3<br \/>\n\/dev\/sdb: msdos partitions 1<\/p><\/blockquote>\n<p>Initialize the partition.<\/p>\n<blockquote><p>[root@linux_server]# pvcreate \/dev\/sda3<br \/>\n  Physical volume \u201c\/dev\/sda3\u201d successfully created<\/p><\/blockquote>\n<p><strong>Add new physical volume to the volume group VolGroup00<\/strong><br \/>\nThe command vgdisplay will show you the specifics of the existing volume groups. Note the VG size is 9.88 GB. You can also use vgs and vgscan to display a different view of all volume groups.<\/p>\n<blockquote><p>[root@linux_server ~]# vgdisplay<br \/>\n  \u2014 Volume group \u2014<br \/>\n  VG Name               gfs_vg<br \/>\n  System ID<br \/>\n  Format                lvm2<br \/>\n  Metadata Areas        1<br \/>\n  Metadata Sequence No  7<br \/>\n  VG Access             read\/write<br \/>\n  VG Status             resizable<br \/>\n  Clustered             yes<br \/>\n  Shared                no<br \/>\n  MAX LV                0<br \/>\n  Cur LV                2<br \/>\n  Open LV               2<br \/>\n  Max PV                0<br \/>\n  Cur PV                1<br \/>\n  Act PV                1<br \/>\n  VG Size               19.99 GB<br \/>\n  PE Size               4.00 MB<br \/>\n  Total PE              5118<br \/>\n  Alloc PE \/ Size       2816 \/ 11.00 GB<br \/>\n  Free  PE \/ Size       2302 \/ 8.99 GB<br \/>\n  VG UUID               ws74W5-bejg-UUqe-ReFJ-ip6i-4Ixy-CAKkDC<\/p>\n<p>  \u2014 Volume group \u2014<br \/>\n  VG Name               VolGroup00<br \/>\n  System ID<br \/>\n  Format                lvm2<br \/>\n  Metadata Areas        1<br \/>\n  Metadata Sequence No  3<br \/>\n  VG Access             read\/write<br \/>\n  VG Status             resizable<br \/>\n  MAX LV                0<br \/>\n  Cur LV                2<br \/>\n  Open LV               2<br \/>\n  Max PV                0<br \/>\n  Cur PV                1<br \/>\n  Act PV                1<br \/>\n  VG Size               9.88 GB<br \/>\n  PE Size               32.00 MB<br \/>\n  Total PE              316<br \/>\n  Alloc PE \/ Size       316 \/ 9.88 GB<br \/>\n  Free  PE \/ Size       0 \/ 0<br \/>\n  VG UUID               KxKjSV-yOQl-T0gR-vse1-Z0RO-nJfM-FQxMZ0<\/p><\/blockquote>\n<p>Add sda3 to VolGroup00<\/p>\n<blockquote><p>[root@linux_server]# vgextend \/dev\/VolGroup00 \/dev\/sda3<br \/>\n  Volume group \u201cVolGroup00\u201d successfully extended<\/p>\n<p>Note that the VG size has increased to 19.84 GB.<br \/>\n[root@linux_server]# vgdisplay<br \/>\n  \u2014 Volume group \u2014<br \/>\n  VG Name               gfs_vg<br \/>\n  System ID<br \/>\n  Format                lvm2<br \/>\n  Metadata Areas        1<br \/>\n  Metadata Sequence No  7<br \/>\n  VG Access             read\/write<br \/>\n  VG Status             resizable<br \/>\n  Clustered             yes<br \/>\n  Shared                no<br \/>\n  MAX LV                0<br \/>\n  Cur LV                2<br \/>\n  Open LV               2<br \/>\n  Max PV                0<br \/>\n  Cur PV                1<br \/>\n  Act PV                1<br \/>\n  VG Size               19.99 GB<br \/>\n  PE Size               4.00 MB<br \/>\n  Total PE              5118<br \/>\n  Alloc PE \/ Size       2816 \/ 11.00 GB<br \/>\n  Free  PE \/ Size       2302 \/ 8.99 GB<br \/>\n  VG UUID               ws74W5-bejg-UUqe-ReFJ-ip6i-4Ixy-CAKkDC<\/p>\n<p>  \u2014 Volume group \u2014<br \/>\n  VG Name               VolGroup00<br \/>\n  System ID<br \/>\n  Format                lvm2<br \/>\n  Metadata Areas        2<br \/>\n  Metadata Sequence No  4<br \/>\n  VG Access             read\/write<br \/>\n  VG Status             resizable<br \/>\n  MAX LV                0<br \/>\n  Cur LV                2<br \/>\n  Open LV               2<br \/>\n  Max PV                0<br \/>\n  Cur PV                2<br \/>\n  Act PV                2<br \/>\n  VG Size               19.84 GB<br \/>\n  PE Size               32.00 MB<br \/>\n  Total PE              635<br \/>\n  Alloc PE \/ Size       316 \/ 9.88 GB<br \/>\n  Free  PE \/ Size       319 \/ 9.97 GB<br \/>\n  VG UUID               KxKjSV-yOQl-T0gR-vse1-Z0RO-nJfM-FQxMZ0<\/p><\/blockquote>\n<p><strong>Extend the Logical Volume Group \/dev\/VolGroup00\/LogVol00 which is mounted as the root filesystem.<\/strong><br \/>\nDisplay the specifics for all logical volume with lvdisplay.  You can also use lvscan or lvs to display a summarized view.<\/p>\n<blockquote><p>[root@linux_server]# lvdisplay<br \/>\n  \u2014 Logical volume \u2014<br \/>\n  LV Name                \/dev\/gfs_vg\/gfs_lv<br \/>\n  VG Name                gfs_vg<br \/>\n  LV UUID                NZrcfq-6Shf-z5cZ-fWJM-fQVi-wOTa-kPhUVG<br \/>\n  LV Write Access        read\/write<br \/>\n  LV Status              available<br \/>\n  # open                 1<br \/>\n  LV Size                10.00 GB<br \/>\n  Current LE             2560<br \/>\n  Segments               1<br \/>\n  Allocation             inherit<br \/>\n  Read ahead sectors     auto<br \/>\n  \u2013 currently set to     256<br \/>\n  Blockice           253:2<\/p>\n<p>  \u2014 Logical volume \u2014<br \/>\n  LV Name                \/dev\/gfs_vg\/quorum_lv<br \/>\n  VG Name                gfs_vg<br \/>\n  LV UUID                Pr27bq-X1AM-U6WC-ceJd-dlIu-AipK-pFRfAE<br \/>\n  LV Write Access        read\/write<br \/>\n  LV Status              available<br \/>\n  # open                 1<br \/>\n  LV Size                1.00 GB<br \/>\n  Current LE             256<br \/>\n  Segments               1<br \/>\n  Allocation             inherit<br \/>\n  Read ahead sectors     auto<br \/>\n  \u2013 currently set to     256<br \/>\n  Blockice           253:3<\/p>\n<p>  \u2014 Logical volume \u2014<br \/>\n  LV Name                \/dev\/VolGroup00\/LogVol00<br \/>\n  VG Name                VolGroup00<br \/>\n  LV UUID                n4QGnw-R9Wj-RHXU-Q1QO-X2aa-vKdx-Js3fwp<br \/>\n  LV Write Access        read\/write<br \/>\n  LV Status              available<br \/>\n  # open                 1<br \/>\n  LV Size                8.88 GB<br \/>\n  Current LE             284<br \/>\n  Segments               1<br \/>\n  Allocation             inherit<br \/>\n  Read ahead sectors     auto<br \/>\n  \u2013 currently set to     256<br \/>\n  Blockice           253:0<\/p>\n<p>  \u2014 Logical volume \u2014<br \/>\n  LV Name                \/dev\/VolGroup00\/LogVol01<br \/>\n  VG Name                VolGroup00<br \/>\n  LV UUID                qqyXcr-nys3-K7MO-LsbU-5CL8-d2hR-MyliKF<br \/>\n  LV Write Access        read\/write<br \/>\n  LV Status              available<br \/>\n  # open                 1<br \/>\n  LV Size                1.00 GB<br \/>\n  Current LE             32<br \/>\n  Segments               1<br \/>\n  Allocation             inherit<br \/>\n  Read ahead sectors     auto<br \/>\n  \u2013 currently set to     256<br \/>\n  Blockice           253:1<\/p><\/blockquote>\n<p>Extend \/dev\/VolGroup00\/LogVol00 using lvextend. The option -l +100%FREE will use up all available disk space.  You can also specify the size with the option -L18G, which will extend the logical volume to 18 GB. The option -L+1G will add another gigabyte to the logical volume.<\/p>\n<blockquote><p>[root@linux_server]# lvextend -l +100%FREE \/dev\/VolGroup00\/LogVol00<br \/>\n  Extending logical volume LogVol00 to 18.84 GB<br \/>\n  Logical volume LogVol00 successfully resized<\/p><\/blockquote>\n<p><strong>Extend the filesystem<\/strong><br \/>\nWe are almost done, the last step is to extend the filesystem.<\/p>\n<p>Record the size of the existing filesystems with the df -h command.<\/p>\n<blockquote><p>[root@linux_server]# df -h<br \/>\nFilesystem            Size  Used Avail Use% Mounted on<br \/>\n\/dev\/mapper\/VolGroup00-LogVol00<br \/>\n                      8.6G  8.0G  205M  98% \/<br \/>\n\/dev\/sda1              99M   19M   75M  21% \/boot<br \/>\ntmpfs                 490M     0  490M   0% \/dev\/shm<br \/>\n\/dev\/mapper\/gfs_vg-gfs_lv<br \/>\n                      9.8G  584M  9.2G   6% \/mnt\/gfs<\/p><\/blockquote>\n<p>Expand the filesystem \/dev\/mapper\/VolGroup00-LogVol00 which is mounted on \/. The command resize2fs can be used to enlarge or shrink ext2 or ext3 filesystems that are unmounted. On Linux kernel version that is equal or greater than 2.6, resize2fs can expand a mounted ext3 filesystem only.<\/p>\n<blockquote><p>[root@linux_server]# resize2fs \/dev\/mapper\/VolGroup00-LogVol00<br \/>\nresize2fs 1.39 (29-May-2006)<br \/>\nFilesystem at \/dev\/mapper\/VolGroup00-LogVol00 is mounted on \/; on-line resizing required<br \/>\nPerforming an on-line resize of \/dev\/mapper\/VolGroup00-LogVol00 to 4939776 (4k) blocks.<br \/>\nThe filesystem on \/dev\/mapper\/VolGroup00-LogVol00 is now 4939776 blocks long.<\/p><\/blockquote>\n<p>Verify that \/dev\/mapper\/VolGroup00-LogVol00 has increased in size.<\/p>\n<blockquote><p>[root@linux_server]# df -h<br \/>\nFilesystem            Size  Used Avail Use% Mounted on<br \/>\n\/dev\/mapper\/VolGroup00-LogVol00<br \/>\n                       19G  8.0G  9.4G  46% \/<br \/>\n\/dev\/sda1              99M   19M   75M  21% \/boot<br \/>\ntmpfs                 490M     0  490M   0% \/dev\/shm<br \/>\n\/dev\/mapper\/gfs_vg-gfs_lv<br \/>\n                      9.8G  584M  9.2G   6% \/mnt\/gfs<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Being the administrator of a large Linux shop, I have had to extend the filesystems on the Red Hat Linux server a few times. Each time I had the opportunity to extend the filesystem, I found that I struggled to&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.gamescheat.ca\/?p=889\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[55,77,61],"_links":{"self":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/889"}],"collection":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=889"}],"version-history":[{"count":1,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/889\/revisions"}],"predecessor-version":[{"id":890,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/889\/revisions\/890"}],"wp:attachment":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=889"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}