was running a small server on my Ubuntu HPE server where I have installed couple of small virtual machines (of Ubuntu 20.04) using VMware workstation player 16. One day I ran out of space on my one virtual machine. I spent couple of hours and read around by googling here and there. There were many articles and every one was explaining their ( little bit different method). In my case none of them were fully compatible with my situation and therefore I felt the need to write this article.
In this article we walk through all the steps needed to successfully resize disk volume of an Ubuntu virtual machine running on VMware workstation player 16.
Although we have tested this using VMware but it should work ideally for any virtualization technology like virtual pc, virtual box etc because the actual key commands involve gparted & ubuntu.
The commands or tips related to VMware workstation might be a bit different from other virtual softwares but the idea is the same.
These are the steps that should be followed.
- Increase the disk space for your virtual machine using VMware workstation player.
- Downloading gparted iso file
- Increase the boot menu display time for virtual machine
- Bring up the bios setup of your virtual machine & boot from CD (gparted iso file)
- Using the gparted tool to increase the volume to cover the available space
- Booting into your virtual machine and running the magical commands
1. Increase the disk space for your virtual machine using VMware workstation player.
Shutdown your virtual machine and then open VMware workstation player > Click on the virtual machine name > Edit virtual machine settings.
Click on Disks and click expand button, enter a size for the new disk size and click ok. This will enable the workstation player to know the new hard disk size but the operating system ( Ubuntu ) running inside the vmware player doesn't know about it, therefore proceed to next step.
2. Downloading gparted iso file
The easiest step, just download from https://gparted.org/download.php the latest available version.
Now we want to boot the virtual machine from the gparted iso downloaded in step 2 above but the problem is that as soon as we start the virtual machine it goes to run the ubuntu installed operating system & we don't have enough time to goto bios settings and change boot order.
We need to increase the delay time boot menu is displayed for the virtual machine. While the virtual machine is stopped (must be), goto its directory on your host computer and open a file ending with .vmx extension (usually virtual machine name + vmx extention) and add the following line at the end.
bios.bootDepaly = "10000"
This will show the boot menu of your virtual machine for 10 seconds.
4. Bring up the bios setup of your virtual machine & boot from CD (gparted iso file)
Now again open the settings for your virtual machine and set the Optical disk to use iso file (instead of physical drive), check Connect on boot, save and start virtual machine.
Now you will see a timeout of 10s, just press F2 and you will see the famous bios setup screen, scroll to boot order and make CD/Drive the first option, F10.
5. Using the gparted tool to increase the volume to cover the available space
Now once you successfully start the VM following the previous step, you will see gparted screen, press OK unless you see the GUI screen, click the tool icon to open it. Now you will see two sections one a yellow coloured and the second gray colored. Here as you can guess the yellow is the used space while the gray is the unused. Simply right click the yellow area and select resize/move option. In the next screen drag either the arrow after the yellow area or place a 0 in the box saying leave space after.
This will make the operating system know that now the disk is increased and the volume can use the remaining free space. But not yet actually so proceed to the last practical step.
6. Booting into your virtual machine and running the magical commands
After the above step in gparted, exit gpart and reboot VM. Now once you login in the terminal or GUI of VM, open terminal and check disk space:
You will see the used space by your volume and in front of it the available space which is not yet increased. Therefore run the following command to see the free space of the Volume Group.
At the end of the output from the above command you will see something `FREE PE/SIZE ` and this is the fee space recognized by your VM. Now lets make use of it.
We need to display the Logical Volume information, run:
It will show how much spache the logical volume is using actually and note the LV path as we will use it in the following command:
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
This command tell VM to use all the available space for our logical volume. The path may differ so use the one that you see in the command above(lvdispaly).
Now run again command `df -h ` and note the disk path /dev/mapper/something and use this path in the following command as:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
And finally check by running `df -h` that the logical volume now successfully use the available space.
- 1. Increase the disk space for your virtual machine using VMware workstation player.
- 2. Downloading gparted iso file
- 3. Increase the boot menu display time for virtual machine
- 4. Bring up the bios setup of your virtual machine & boot from CD (gparted iso file)
- 5. Using the gparted tool to increase the volume to cover the available space
- 6. Booting into your virtual machine and running the magical commands