Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Hot add and reduce operation of Qemu/KVM virtual machine hardware

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

What this article shares with you is the hot addition and reduction operation of Qemu/KVM virtual machine hardware. I believe most people have not learned this skill. In order to let you learn, I have summarized the following content.

I. basic environmental requirements

1. Software version requirements

Operating system: CentOS7 or above

QEMU version: 2.4 or above

two。 Virtual machine startup parameter requirements

For the Qemu virtual machine to perform hot add operation, you need to add the following configuration to the virtual machine startup command to enable the virtual machine console feature, so that you can log in to the virtual machine console later to perform hot add and reduction operations:

-monitor telnet:127.0.0.1:10001,server,nowait

II. CPU hot addition

1. CVM startup command

For the Qemu virtual machine to perform the CPU hot add operation, the following configuration needs to be added to the virtual machine startup command:

-smp 2 Maxc pushroom 32

# indicates that the virtual machine initially uses 2-core CPU and can be added to a maximum of 32 cores

two。 Hot add cpu operation

Execute the following command to hot add CPU to the virtual machine

(1) Log in to the virtual machine console

# telnet 127.0.0.1 10001

(2) execute the hot add CPU command

(qemu) cpu-add cpu-id

Note: cpu-id is the id number of the hot-added CPU in the system, with a range of 1 to 31. The maximum value is determined by the maxcpusu value configured by the startup parameter of the virtual machine. The cpu-id number added in the same virtual machine cannot be the same, otherwise it will lead to id conflicts.

(3) exit the virtual machine console

To exit the qemu console, press the ctrl+] key to exit the qemu console. When the prompt changes from (qemu) to telnet >, you can use the quit command to exit the telnet terminal. It is important to note that you cannot enter quit to exit directly in the qemu console, otherwise the current virtual machine system will be forced and completely shut down.

3. Log in to the virtual system, activate the newly added CPU and verify

(1) activate the newly added CPU

Log in to the virtual operating system and execute the following command to activate the newly added CPU. Here, take the CentOS system as an example

# echo 1 > / sys/devices/system/cpu/cpu-id/online

Note: cpu-id is the id number of the hot-added CPU in the system, ranging from 1 to 31, and the maximum value is determined by the maxcpuss value of the virtual machine startup parameter configuration.

The CentOS7 system already supports automatic online-added CPU, and there is no need to perform the above activation operations.

(2) verify whether the CPU hot add operation is successful

# cat / proc/interrupts

III. Memory hot addition

1. CVM startup command

To perform a memory hot add operation for the Qemu virtual machine, the following configuration needs to be added to the virtual machine boot command:

-m 2G _

# indicates that the virtual machine initially uses 2 GB of memory and can be added to a maximum of 64 GB of memory

two。 Hot add memory operation

Execute the following command to hot add Mem to the virtual machine

(1) Log in to the virtual machine console

# telnet 127.0.0.1 10001

(2) execute the hot add Mem command

(qemu) object_add memory-backend-ram,id=ram2,size=2G

(qemu) device_add pc-dimm,id=dimm2,memdev=ram2

Note: ram2 is the id number of the device with hot added memory, with a range of 1 to 31. The maximum value is determined by the slots value of the virtual machine startup parameter configuration. The mem-id number added in the same virtual machine cannot be the same, otherwise it will lead to id conflicts. It is best to add no more than 4 gigabytes of memory per block. Currently, a maximum of 5 gigabytes is supported.

(3) exit the virtual machine console

Refer to the CPU section to exit the console operation.

3. Log in to the virtual system, activate the newly added memory block and verify

(1) activate the newly added memory block

Log in to the virtual operating system and execute the following command to activate the newly added memory block. Here, take the CentOS system as an example:

a. View the existing memory block of the system

# ll / sys/devices/system/memory/

b. After you insert the new memory, you can see the extra memory blocks.

c. Activate the newly added memory block

# echo online > / sys/devices/system/memory/memory2/state

Note: memory2 is a hot added memory number in the operating system.

CentOS7.2 and above systems have supported automatic online to add memory quickly, there is no need to perform the above activation operations.

(2) verify whether the memory block hot add operation is successful

# free-m

Four. hot addition and reduction of disks

1. Hot add disk operation

Execute the following command to hot add disks to the virtual machine

(1) Log in to the virtual machine console

# telnet 127.0.0.1 10001

(2) execute the hot add disk command

(qemu) drive_add 0 file=/home/vm/vmdisk/datadisk02,format=qcow2,id=drive-virtio0-disk-01,if=none

(qemu) device_add virtio-blk-pci,scsi=on,drive=drive-virtio0-disk-01,id=disk-01

(3) execute the thermal reduction disk command

(qemu) device_del disk-01

Note: disk-01 is the hot add and reduce disk device id number, when performing the operation, the device id needs to be able to match.

(4) exit the virtual machine console

Refer to the CPU section to exit the console operation.

3. Log in to the virtual machine system to verify the disk operation

Execute the following command to see if the disk add and delete operation was successful

# parted-l

5. Hot addition and reduction of network cards

1. Hot add Nic operation

Execute the following command to hot add the network card to the virtual machine

(1) Log in to the virtual machine console

# telnet 127.0.0.1 10001

(2) execute the hot add Nic command

(qemu) netdev_add tap,ifname=tap-7e03bc209a,id=hostnet-7e03bc209a,vnet_hdr=on,vhost=on,script=/etc/init.d/kvmbr5,downscript=no

(qemu) device_add virtio-net-pci,netdev=hostnet-7e03bc209a,id=net-7e03bc209a,mac=52:54:00:00:01:29,bus=pci.0

(3) execute the order of hot reduction of network card

(qemu) device_del net-7e03bc209a

(qemu) netdev_del hostnet-7e03bc209a

Note: 7e03bc209a is the id number of the device that hot adds and reduces the network card. When performing the operation, the device id needs to be able to match.

(4) exit the virtual machine console

Refer to the CPU section to exit the console operation.

3. Log in to the virtual machine system to verify the operation of the network card

Execute the following command to see if the Nic add and delete operation was successful

# ip addr

What is described above is the hot addition and reduction operation of Qemu/KVM virtual machine hardware, and the specific usage needs to be used by everyone through hands-on experiments. If you want to know more about it, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report