Change amount of Ram and CPU cores in KVM

Solution 1:

For offline configuration:

To increase the number of CPUs:

virsh setvcpus <vm_name> <vcpu_count> --config

If you get an error that you exceeded the maximum number, first do:

virsh setvcpus <vm_name> <vcpu_count> --config --maximum

Then repeat the above:

virsh setvcpus <vm_name> <vcpu_count> --config

To increase the memory size:

virsh setmaxmem <vm_name> <memsize> --config
virsh setmem <vm_name> <memsize> --config

For online configuration:

You can set the vCPU and memory while the VM is running with --current instead of --config, but the new numbers has to be within the maximum values already set. You can not set these maximum numbers while the VM is running. You will have to shutdown the VM with virsh shutdown <vm_name>, use the above command and start back the VM with virsh start <vm_name>.

Solution 2:

You can edit its XML from command-line with:

virsh edit name_vhost

Then, you only have to search the <memory> tag and modify it

Keep in mind that the memory allocation is in kilobytes, so to allocate 512MB of memory, use 512 * 1024, or 524288.


Solution 3:

You can edit the VM settings in virt-manager or in cli by changing the XML in virsh edit VMNAME