Monday, September 26, 2011

qemu-kvm: balloon driver

Qemu-kvm has a really neat feature called memory ballooning. This feature allows you to change the memory for your virtual guest doing runtime. Usually this feature is enabled by default, but the virtual guest also has to support this (By default my gentoo initi-script also turns it on). To make it work on the guest side you only have to enable the following feature in the kernel config (guest kernel):

CONFIG_VIRTIO_BALLOON=y (Virtualization -> Virtio balloon driver)

There are even drivers for Windows which are available here: Link
After turning on you can connect to the qemu monitor via netcat or telnet. Too see the actual memory of the guest you only have to type:

(qemu) info balloon

The syntax for increasing or decreasing the memory is:

(qemu) balloon 1024

This command will change the memory allocation to the specified amount in MB. Looking at the above example it would be 1024MB.