How can I Change amount of Ram and CPU cores for a virtual machine in KVM that is already created? Thanks
-
4IN run-time or with reboot? That would be really good to know BTW. – Andrew Smith Jun 29 '12 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 '12 at 01: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 '12 at 04:18
-
you can't change number of cores or amount of RAM on a running kernel. – Michael Martinez Sep 11 '15 at 17:28
4 Answers
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>
.
![](../../users/profiles/342593.webp)
- 411
- 4
- 5
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.
![](../../users/profiles/1293.webp)
- 60,515
- 14
- 113
- 148
![](../../users/profiles/125497.webp)
- 244
- 6
- 21
-
-
1You should check this out http://www.semanticlab.net/index.php/KVM_increase_CPU_and_RAM_during_runtime ;) – blacksoul Jun 30 '12 at 10:15
-
-
-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 '16 at 21:44
-
@MikeS: It should have been `virsh edit name_vhost`. I corrected the answer. – Dennis Williamson Sep 15 '16 at 16:31
-
Thanks. Although the answer was broken, it's now fixed. I removed the -1. – Mike S Sep 15 '16 at 20:47
You can edit the VM settings in virt-manager
or in cli by changing the XML in virsh edit VMNAME
![](../../users/profiles/13543.webp)
- 18,482
- 6
- 48
- 63
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:
http://earlruby.org/2014/05/increase-a-vms-available-memory-with-virsh/
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:
http://earlruby.org/2014/05/increase-a-vms-vcpu-count-with-virsh/
![](../../users/profiles/219985.webp)
- 369
- 3
- 5