VirtualBox - Managing Virtual Drives

J

Jarret W. Buse

Guest
VirtualBox - Managing Virtual Drives

When dealing with VirtualBox virtual drives, there can be a lot of useful tips and tricks which can make life a lot easier.

In this article, I will cover the following areas of managing a virtual drive:

  • Viewing details about a Virtual Disk
  • Changing the UUID of a Virtual Disk
  • Cloning a Virtual Disk
  • Changing a Fixed Size disk to a Dynamic Size
  • Changing the size of a Dynamic Size disk
  • Allocating extra space on a Dynamic Disk

Most times, a Virtual Disk is created and used for quite a while. Sometimes, a person may not recall all the details about the Virtual Disk when it was created. Other times, a Virtual Disk is downloaded or copied from somewhere else and the details are not known. So, to find the details about the Virtual Disk you need to have the file on the same system as VirtualBox. In the terminal, it can be best to change to the directory where the Virtual Disk is located. If not, you will need to type in the whole path to the Virtual Disk file. The syntax is:

vboxmanage showhdinfo <uuid | path/filename>

If I run the command on a Virtual Disk made to hold DOS, I get the following information:

UUID: b38f5793-5f3f-42fb-be4b-e16fb6f07e5e
Parent UUID: base
State: created
Type: normal (base)
Location: /media/jarret/TOSHIBA EXT/VirtualBox/Windows/DOS/DOS.vdi
Storage format: VDI
Format variant: fixed default
Capacity: 500 MBytes
Size on disk: 502 MBytes
In use by VMs: DOS (UUID: ae1a2e87-5f9c-45df-8917-f98a799fff49)


Here, the important information given is the “UUID”, “Storage format”, “Format variant”, “Capacity” and the “In use by Vms”. If you want to show the information by the UUID, then the ID given is what you use. Sometimes, you may receive an error which only gives you the UUID. Once you have the UUID, you can run this “showhdinfo” subcommand to get more information.

The “Format variant” shows that when the VDI file was created, it was created as a Fixed Disk size of 500 MB (Capacity). If the Virtual Disk needs to be made larger, then it must be converted into a Dynamic Disk.

The “In use by Vms” can be handy if the same VDI is being used in multiple places. If you copy a VDI file and load it in another Machine, you can get a UUID error since another VDI is used which has the same UUID. An error can occur as follows:

Failed to open the hard disk file /media/jarret/TOSHIBA EXT/VirtualBox/Windows/DOS/DOS (copy).vdi.
Cannot register the hard disk '/media/jarret/TOSHIBA EXT/VirtualBox/Windows/DOS/DOS (copy).vdi' {b38f5793-5f3f-42fb-be4b-e16fb6f07e5e} because a hard disk '/media/jarret/TOSHIBA EXT/VirtualBox/Windows/DOS/DOS.vdi' with UUID {b38f5793-5f3f-42fb-be4b-e16fb6f07e5e} already exists.

Result Code:

NS_ERROR_INVALID_ARG (0x80070057)

Component:

VirtualBox

Interface:

IVirtualBox {fafa4e17-1ee2-4905-a10e-fe7c18bf5554}

Callee Rc:

VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)


The error can be fixed by changing the UUID of the copied VDI. To do this, use the syntax:

vboxmanage internalcommands sethduuid <path/VDI-file>

Once the UUID has been changed, the VDI file can be added to the Machine without causing an issue.

To properly copy a VDI and have the UUID changed at the same time, you need to clone the VDI. To clone a Virtual Disk, use the following syntax:

vboxmanage clonehd (options) <path/old-file.vdi> <path/new-file.vdi>

There are two options which can be used as follows:

  1. --variant standard
  2. --variant fixed
If I have a file called “DOS2.vdi” that I will clone to a file called “DOS2-750.vdi” and also convert it to Dynamic, the command would be “vboxmanage clonehd DOS2.vdi DOS2-750.vdi”.

The default is “--variant standard” which means a Dynamic Disk size. By this means you can convert a Fixed Disk to a Dynamic Disk. When cloned, the UUID will also be changed and you will not have to manually perform the task.

NOTE: The cloning of a disk takes as long as creating a Fixed Disk or manually copying the VDI file.

Once a disk has been cloned and made Dynamic, you can change the size of it by using the following syntax:

vboxmanage modifyhd <path/file.vdi> --resize <size-in-MB>

Let's assume I have a file named “DOS2-750.vdi” which is 500 MB and I need to resize it to 750 MB. The command would be “vboxmanage modifyhd DOS2-750.vdi --resize 750”.

Now, the new file is 750 MB, but the OS will not see the new size. To manage the new size to be recognized, you need an OS which can resize the partition to include the unused size. If the OS cannot do this, you can boot the Machine from an ISO of a supported version of a “GParted Live CD”. Using GParted, you can resize the partition and then reboot into the Machine's OS.

NOTE: If the format is less than FAT32, such as FAT 16, then the partition must be updated to FAT32. This may cause issues with certain OS's.

These tips should be handy for handling issues which may commonly arise with VirtualBox.
 

Attachments

  • slide.png
    slide.png
    33.4 KB · Views: 122,800

Members online


Latest posts

Top