If you find yourself running out of disk space in your Ubuntu virtual machine, there are a few things you can do to free up some space.
One option is to delete any unnecessary files or programs that you don’t use. Another option is to increase the size of your virtual machine’s disk.
To increase the size of your Ubuntu virtual machine’s disk, you’ll first need to create a new virtual disk that is larger than your current one.
You can do this using the “Create New Disk” feature in your virtualization software’s management console.
Once you have created the new disk, attach it to your Ubuntu virtual machine and format it using the ext4 file system.
Finally, use the “dd” command to copy the contents of your old disk to the new one.
Once you have increased the size of your Ubuntu virtual machine’s disk, you should now have enough space to install any new programs or files that you need.

Contents
- 1 How to check if you’re running out of disk space in your Ubuntu virtual machine
- 2 How to increase disk space in your Ubuntu virtual machine
- 3 How to create a new virtual disk in your Ubuntu virtual machine
- 4 How to attach the new virtual disk to your Ubuntu virtual machine
- 5 How to extend your Ubuntu virtual machine’s filesystem to use the new virtual disk
How to check if you’re running out of disk space in your Ubuntu virtual machine
If you’re running an Ubuntu virtual machine, you may be wondering how to check if you’re running out of disk space. Here’s how:
- Log into your Ubuntu virtual machine.
- Open a terminal window and type the following command: df -h.
- This command will show you the amount of free disk space on your Ubuntu VM. If you see that you’re running low on disk space, you may need to increase the size of your VM’s disk.
How to increase disk space in your Ubuntu virtual machine
If you find that your Ubuntu virtual machine is running out of disk space, there are a few ways that you can increase the amount of available space.
One way is to add a new virtual disk to your machine. This can be done in the VirtualBox Manager by selecting your machine and clicking the “Storage” icon. From here, you can add a new virtual disk to your machine.
Another way to increase disk space is to resize your existing virtual disk. This can be done in the same storage settings menu in the VirtualBox Manager.
To resize your disk, first select it from the list and then click the “Resize Disk” button. You will then be able to enter in the new size for your disk.
If you are using an Ubuntu server virtual machine, you may also need to increase the size of your root filesystem.
This can be done by running the “resize2fs” command on your root filesystem. For more information on how to do this, see the following link:
How to create a new virtual disk in your Ubuntu virtual machine
If you find yourself running out of space in your Ubuntu virtual machine, you can add a new virtual disk to increase your storage capacity. This process is relatively simple and only requires a few steps.
First, you’ll need to open the “Disks” application from the Dash. Once open, select the “+” icon to create a new virtual disk.
Next, you’ll need to choose the size of your new disk. Make sure to leave enough room for your operating system and any other programs you plan on installing. Once you’ve chosen the size, click “Create.”
Your new disk will now be created and should appear in the “Disks” application. All that’s left to do is format it so that it can be used by your Ubuntu virtual machine.
To do this, right-click on the new disk and select “Format.” Choose the “ext4” file system and click “Format.”
Your new disk is now ready to be used! You can mount it by right-clicking on it and selecting “Mount.”
How to attach the new virtual disk to your Ubuntu virtual machine
Now that you have added the new virtual disk to your Ubuntu virtual machine, you need to attach it so that you can use the additional storage space. To do this, follow these steps:
- Open the Settings dialog for your Ubuntu virtual machine in VirtualBox.
- Select the Storage category.
- In the Storage Tree panel, select the controller to which you want to add the new disk (usually SATA or IDE).
- In the right panel, click the Add hard disk button (the icon with the plus sign and green arrow).
- In the Add Hardware Disk dialog, select Choose/Create a Disk Image and click the Create button.
- In the Create New Virtual Disk dialog, select Dynamically allocated and click Next.
- Specify a name and location for your new virtual disk image and click Next.
- Specify a size for your new virtual disk image and click Create.
- In the Add Hardware Disk dialog, select your new virtual disk image and click Add.
- Close the Settings dialog for your Ubuntu virtual machine in VirtualBox
How to format the new virtual disk in your Ubuntu virtual machine
Assuming you have a new, unformatted virtual disk attached to your Ubuntu VM, here’s how to format it so that you can use it for storage.
- Start by logging into your Ubuntu VM.
- Next, open a terminal window and run the following command: sudo fdisk /dev/sdb
- Enter ‘n’ to create a new partition.
- Enter ‘p’ to make this a primary partition.
- Press Enter to accept the default partition number (1).
- Press Enter again to accept the default starting sector.
- Enter ‘+100G’ to make this partition 100GB in size.
- Enter ‘w’ to write the changes and exit fdisk.
- Next, run the following command to format the new partition: sudo mkfs -t ext4 /dev/sdb1
- Finally, run the following command to mount the new partition: sudo mount /dev/sdb1 /mnt
How to mount the new virtual disk in your Ubuntu virtual machine - Start by allocating the new disk space in your Ubuntu virtual machine. For more information, see Allocate Disk Space for a Linux Virtual Machine.
- In the Ubuntu virtual machine, create a new directory to serve as the mount point for the new disk. For example:
sudo mkdir /mnt/newdisk
- Use the following command to format the new disk:
sudo mkfs -t ext4 /dev/sdb1
- Mount the new disk to the mount point you created in step 2:
sudo mount /dev/sdb1 /mnt/newdisk
How to extend your Ubuntu virtual machine’s filesystem to use the new virtual disk
Before we begin, you will need to have a new virtual disk added to your virtual machine.
This can be done through the management console of your hypervisor or through the command line interface.
Once you have the new virtual disk added, we will need to create a filesystem on it. We will use the ext4 filesystem for this example.
You can use any filesystem type that you like, but ext4 is a good choice for most purposes.
To create the filesystem on the new virtual disk, we will use the mkfs command. This command will initialize the filesystem on the given device and prepare it for use.
We will need to specify the -t option to tell mkfs which type of filesystem to create.
For ext4, we would use -t ext4 . We will also need to specify the -L option to give our new filesystem a label. This is optional, but it can be helpful for identifying the filesystem later on.
Once we have run the mkfs command, our new filesystem should be ready for use. We can now mount it so that it can be used by our Ubuntu virtual machine.
To do this, we will first need to create a mount point. A mount point is simply a directory where our new filesystem will be accessible. We can create a mount point anywhere, but for this example we will create it in /mnt .
Once we have created our mount point, we can use the mount command to mount our new filesystem there.
We will need to specify the -t option again so that mount knows which type of filesystem to expect.
We will also need to specify the device name or path of our new virtual disk. For this example, we will assume that our disk is located at /dev/sdb .
Finally, we need to specify the path of our mount point as well. In this case, it is /mnt .
Putting all of these together gives us the following command: sudo mount -t ext4 /dev/sdb /mnt . This mounts our new ext4 filesystem from /dev/sdb at /mnt .