How To Increase Virtualbox Disk Size For Fixed Size Disk
In this tutorial, I’m going to show you how to increase Virtualbox disk size for fixed size disks. I assume that your host OS is Linux. If you want to know how to increase the size of a fixed size disk, then read the previous article.
Find Out If Your Virtual Disk is Fixed Size
Open you virtual machine settings and click Storage on the left pane. Select your virtual disk under Storage Tree. You can see the information about your virtual disk on the right. You can see that my virtual disk is fixed size.
Backup Your Virtual Hard Disk
Before we increase the size of our virtual hard disk, it’s always a good idea to make a backup of it in case something go wrong.
First, right click on the location line and copy the location of your virtual hard disk.
Next open up a terminal on your host OS and run the following command to backup the virtual hard disk.
cp /location-of-virtual-disk /location-of-backup-of-virtual-disk
Repalce the location with the real location of your virtual disk. For example, I executed this command:
cp /media/matrix/sdb9/VMs/openSUSE.vdi /media/matrix/sdb9/VMs/openSUSE-bakcup.vdi
Make sure your backup disk name is different from the origial disk name.
Increase Virtualbox Disk Size For Fixed Size Disks
First we add a new virtual disk that is larger than the original virtual disk, then we will use the dd utility to copy the OS on the original virtual disk to the new virtual disk. Next, we will make the OS to use all disk space of the new virtual disk. Finally We can delete the original virtual disk from virtual machine.
Add a New Virtual Disk
Open virtual machine settings and click Storage on the left pane. Under Storage Tree, click Contorller: SATA, then click the plus icon at the bottom to add a new hard disk.
Select Create new disk on the next window.
You can choose whatever file type you like. I choose VDI for this tutorial.
In the next screen, I choose my hard disk to be dynamically allocated because it takes less time to create. You can choose fixed size if you like.
Give your new disk a name and select a size for it. Click create.
Now a new disk is created and is attached to your virtual machine.
Use dd to Copy Guest OS to the New Disk
In order to use dd to copy guest OS to the new disk, we need to boot virtual machine from a Linux Live image.
Click on Controller: IDE, then click on the optical disk icon to select a Linux live image from your computer.
After you save your settings, start the virtual machine. Once you are in a Linux Live OS, open up a terminal, run the following command to copy /dev/sda to /dev/sdb.
sudo dd if=/dev/sda of=/dev/sdb
Your old disk is /dev/sda and your new disk is /dev/sdb. If you are not sure, open Gparted in the Linux Live OS to know which is which.
The copy process can take quite a while. Once it’s done, open Gparted in Linux Live OS. Select your new disk, you can see that your guest OS has been copied to the new disk and there are some unallocated disk space because the old disk is smaller than the new disk.
Now you can resize your root file system to use the unallocated space. Once it’s done, shut down your virtual machine and open the settings window, remove your old disk and the live iso image from virtual machine.
Save your settings and start virtual machine again. You can use the following command to check the size of your new disk in the guest OS.
sudo fdisk -l