Header Ads

  • Latest

    [Step-by-Step Guide] Extending Storage Space in Running Linux VM on vmware (CentOS or RedHat)



    Few weeks back I noticed that one of the servers on vmware environment which I am maintaining will soon needs a storage expansion due to its fast growing behavior. This is how I extend its storage space.

    • Login to vmware environment, and take a complete backup of the VM prior to next steps.
    • Shutdown all the internal services and then shutdown(power off) the VM.
    • Go to "edit settings" of the powered off VM.
    • Change the hard disk space as you required on the selected hard disk and save.
    • Power on the VM.
    • Now login to the VMs console as root.
    • Enter command "fdisk -l"
    "fdisk -l" will display all the disk partitions of the VM. You can now check and confirm new size of the partition after the changes done on point "4"

    • Go though the response and find out the disk name which we need to expand with added space. It will be something like "/dev/sda: XXGB". Let's say the disk you want to expand is /dev/sda.
    • Now enter command "fdisk /dev/sda"
    "fdisk <diskName>" will open up a console where you can enter all the fdisk commands.

    • Enter "p"  -- View partition table
    • Enter "n"  --  Create new partition
    • Enter "p"  --  To make new partition a primary one
    • Enter the default partition number you see in the termial. For me it's 3.
    • Press enter 2 times to confirm systems default values for block info.
    • Enter "t"  --  Change partition ID
    • Enter <PartitionID>. Mine is 3 (the newly created).
    • Enter "8e"  -- Set the partition type to Linux LVM
    • Enter "w"  -- Save the changes.  
    • Enter "reboot" to reboot the VM to apply the changes made to the partition table.
    • Open up a terminal as root again
    • Enter command "fdisk -l" again. Now you can see the newly created partition on the partition table. Mine is /dev/sda3.
    • Issue "pvcreate /dev/sda3" command to the newly created partition. This will initiate new partition as a physical volume.
    • Now enter "vgdisplay" command and get the VG (volume group) name.
    • Enter "vgextend <VGname> /dev/sda3" to extend the VG with new valume. 
    • Enter "df -h" and find out which mount point you want to extend with newly added partition. For me, I want to extend root "/" mount point and its file system name is "/dev/mapper/vg-root"
    • Now extend the logical volume. "lvextend -l +100%FREE /dev/mapper/vg-root" (NOTE: Change the command according to your environment details taken from "df -h" command)
    • Now we have to expand the "ext3" file system.
    • If on Red Hat: "ext2online /dev/mapper/vg-root"
    • If on CentOs:  "resize2fs -p /dev/mapper/vg-root"
    • All Done. Now check and confirm the changes using "df -h". 
    That's All. 😀
    Comment below if you come across any issues. 👍 




    No comments