How to Expand a Hard Disk on a Linux VM in VMware Online

If you’re using a virtual machine (VM) in VMware and you need to expand the hard disk due to space constraints, you can do so online without having to shut down the VM. Here’s a step-by-step guide on how to expand your hard disk on a Linux VM online.

Step 1: Change the Size of the Hard Disk

  1. Open the VMware vSphere Client and log in.
  2. Select the virtual machine you want to expand the hard disk for.
  3. Click the “Edit Settings” button to open the VM settings.
  4. Click on the hard disk you want to expand and select “Edit”.
  5. Change the size of the hard disk and click “OK”.

Step 2: Expand the Partition Online

  1. Notify the kernel that the hard disk size has changed by running the following command:

    sudo partprobe
    

    This command updates the kernel’s partition tables to recognize the new size of the hard disk, enabling the partition to be expanded online.

  2. Install the “cloud-utils” package by running the following command:

    sudo apt-get install cloud-utils
    
  3. Use the “growpart” tool to expand the partition online. To do so, enter the following command, where “/dev/sda1” is the partition to expand:

    sudo growpart /dev/sda 1
    
  4. Verify that the partition has been successfully expanded by running the following command:

    lsblk
    

    The output should show the expanded partition.

  5. Expand the file system to use the new size of the partition by running the following command:

    sudo resize2fs /dev/sda1
    

Step 3: Verify the Size

  1. Run the command df -h to display the size of the partition.
  2. Verify that the size of the partition is displayed correctly.

Congratulations! You have successfully expanded the size of your hard disk on a Linux VM in VMware online, without having to shut down the VM.