Last active
August 19, 2022 01:09
-
-
Save amshinde/dfec8265db5571754b4183ed23297f05 to your computer and use it in GitHub Desktop.
Hotplugging cpu, memory and host devices to a running virtual machine with QMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hotplugging cpu: | |
Start QEMU with QMP socket available and with startup amount of CPUs less than maxcpus: | |
./qemu-system-x86_64 -qmp unix:/tmp/qmp-sock,server,nowait -smp 2,maxcpus=8 | |
Connect to qmp socket and add cpu: | |
socat /tmp/qmp-sock - | |
{ "execute": "cpu-add", "arguments": { "id": 2 } } | |
Hotpluggable Cpu's can be queried as: | |
{ "execute": "query-hotpluggable-cpus" } | |
Online newly added CPU as : | |
echo 1 > /sys/devices/system/cpu/cpu1/online | |
Hotplugging memory: | |
Existing memory can be queried with : | |
{ "execute": "query-memory-devices" } | |
{"return": [{"type": "dimm", "data": {"memdev": "/objects/mem0", "hotplugged": false, "addr": 4294967296, "hotpluggable": true, "size": 23592 | |
9600, "slot": 0, "node": 0, "id": "nv0"}}]} | |
To add memory, start qemu with startup memory less than max: | |
./qemu-system-x86_64 -qmp unix:/tmp/qmp-sock,server,nowait -m 2G,slots=2,maxmem=3G | |
Add memory with following qmp command: | |
{ "execute": "object-add", "arguments": { "qom-type": "memory-backend-ram", "id": "mem3", "props": { "size": 1048576 } } } | |
The above command creates a memory backend device.To create a front-end pc-dimm device and insert it into the first empty slot, | |
use command: | |
{ "execute": "device_add", "arguments": { "memdev" : "mem3", "id" :"dimm3", "driver": "pc-dimm"}} | |
{"return": {}} | |
Hotplugging virtio disk: | |
The following add a backend disk: | |
{"execute":"blockdev-add","arguments":{"driver":"raw","node-name":"disk1","file":{"driver":"file","filename":"/dev/mapper/docker-8:2-3016900"}}} | |
{"return": {}} | |
To add guest visible frontend virtio-block device: | |
{ "execute": "device_add", "arguments": { "driver": "virtio-blk", "drive": "disk1", "id": "virtio0" } } | |
Block devices can be queried as: | |
{"execute" :"query-block"} | |
Note: For hot-plugging disks, kernel needs to be compiled with CONFIG_HOTPLUG_PCI=y,CONFIG_HOTPLUG_PCI_ACPI=y | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment