How to assign more disk space to existing Ubuntu VM
This guide will show you how to resize your Ubuntu virtual machine to e.g. add more storage
Ever been in a situation where your virtual machine runs out of disk space? This quick guide will show you how to easily assign more disk space to an existing virtual machine (VM) and how to let the VM partition utilize the extra space. Let’s go.
Step 1: Expand disk space assigned to VM from your host machine
The first step is to assign more disk space to your virtual Ubuntu machine from your host machine.
To do this, open the terminal on your host machine and run a command with the following syntax:
sudo qemu-img resize {path to virtual machine image} +{how many GB to add}G
For instance, if your virtual machine image is stored as var/lib/libvirt/images/my_vm.qcow2
and you want to add 30GB, your command should look like this:
sudo qemu-img resize var/lib/libvirt/images/my_image.qcow2 +30G
Step 2: Install gparted via terminal
Next step is to allow the VM disk partition to utilize the added disk space. To do this, we’ll use the gparted application. Open your VM, open the terminal and download and install gparted by running this command:
sudo apt-get install gparted
Step 3: Resize VM partition
Now, we’ll increase the disk space assigned to the VM aka we’ll resize the VM partition.
To do this, follow these steps:
- Open the gparted application on the VM
- Select the partition to resize in the bar (it could be named something like “/dev/vda3")
- Click the “resize” icon. It looks like an arrow pointing right towards a vertical line. A window will appear.
- In the window, enter how much of the available disk space you want to assign to the partition.
- Click the “Resize” button to close the window.
- Click the green check mark icon to apply the operation.
- Click “Fix” if a dialog box asks you if you want to allocate more blocks to the partition.
You’re now done.
This was how to resize an existing virtual machine on Ubuntu. I hope you found the guide helpful.
Follow me for articles on AI and sustainability and subscribe to get my stories via email when I publish.
I also sometimes write about time series forecasting.