How can I Change amount of Ram and CPU cores for a virtual machine in KVM that is already created? Thanks

  • 4
    IN run-time or with reboot? That would be really good to know BTW. Jun 29, 2012 at 22:11
  • +1 - Also would be worth clarifying whether this would be in virt-manager (as referenced in previous question) or from command line.
    – rnxrx
    Jun 30, 2012 at 1:44
  • Thanks, I think It's easier to change this in reboot and yes I created VMs in virt-manager but command-line is ok.
    – Zim3r
    Jun 30, 2012 at 4:18
  • you can't change number of cores or amount of RAM on a running kernel. Sep 11, 2015 at 17:28

4 Answers 4


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.

  • Really Thanks, Can I increase CPU cores with this method ?
    – Zim3r
    Jun 30, 2012 at 10:12
  • 1
    You should check this out semanticlab.net/index.php/… ;)
    – blacksoul
    Jun 30, 2012 at 10:15
  • Is there any other way ? besides what is explaing on semanticlab.net
    – Zim3r
    Jun 30, 2012 at 11:09
  • -1 because I simply get: "error: unknown command: name_vhost" . Note that I am using the name of my host instead of that literal string. I like Ahmed's answer in any event, more comprehensive.
    – Mike S
    Apr 27, 2016 at 21:44
  • @MikeS: It should have been virsh edit name_vhost. I corrected the answer. Sep 15, 2016 at 16:31

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>.


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


To increase the maximum amount of memory that can be allocated to the VM you have to increase the maximum memory limit, power off the VM, increase the memory allocated, the start the VM. There's a step-by-step guide here:


To get more VCPUs you have to edit the virsh XML file and restart the VM. There's a step-by-step guide to do this here:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.