Ubuntu – How to limit disk access bandwidth for a Virtual Machine guest

disk-usagevirtualboxvirtualization

I have a Virtualbox on my Ubuntu (host) that serves few Windows guest OS.
Sometimes the running Windows virtual machine starts massive access to the disk which blocks me in my host environment. I would like to limit the read/write of data access to the physical harddisk.

How can I do it?

Best Answer

Starting from version 4.0 we are able to limit Virtual Box bandwith for acess to disk images (see Virtual Box Manual for details)

We need to create a bandwith group first (in the example below named "Limit" for 20 MB/s):

VBoxManage bandwidthctl "VM name" add Limit --type disk --limit 20M
VBoxManage storageattach "VM name" --storagectl "SATA" --port 0 --device 0 --type hdd
                                   --medium disk1.vdi --bandwidthgroup Limit
VBoxManage storageattach "VM name" --storagectl "SATA" --port 1 --device 0 --type hdd
                                   --medium disk2.vdi --bandwidthgroup Limit

If you get this error:

VBoxManage: error: Cannot register the hard disk '.../foo.vdi' {...} because a hard disk '.../foo.vdi' with UUID {...} already exists

then replace the path to the disk image with the UUID given in the error (both should be the same) including the {}

To further limit disk access to 10 MB/s we can then issue

VBoxManage bandwidthctl "VM name" set Limit --limit 10M 

This can even be done during runtime.