searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

使用virsh edit命令修改虚拟机内存不生效问题

2023-09-27 08:23:58
93
0

今天遇到一个问题,使用virsh edit <vm>命令调整了虚拟机的内存大小后, 保存退出,再次使用virsh edit <vm>命令查看虚拟机配置文件,发现内存又改回了先前的值。

 

我的原始配置文件是:

 

<domain type='kvm'>

  <name>vm21</name>

  <uuid>81a67c14-ae40-4c86-8b1a-0b19dfb4575b</uuid>

  <memory unit='KiB'>2029144</memory>

  <currentMemory unit='KiB'>2029144</currentMemory>

  <memoryBacking>

    <hugepages>

      <page size='2048' unit='KiB'/>

    </hugepages>

    <access mode='shared'/>

  </memoryBacking>

  <vcpu placement='static' cpuset='8,10,12,14'>4</vcpu>

  <cputune>

    <vcpupin vcpu='0' cpuset='8'/>

    <vcpupin vcpu='1' cpuset='10'/>

    <vcpupin vcpu='2' cpuset='12'/>

    <vcpupin vcpu='3' cpuset='14'/>

  </cputune>

  <resource>

    <partition>/machine</partition>

  </resource>

  <os>

    <type arch='x86_64' machine='pc-i440fx-2.2'>hvm</type>

    <boot dev='hd'/>

  </os>

  <features>

    <acpi/>

    <apic/>

  </features>

  <cpu mode='host-passthrough' check='none'>

    <topology sockets='1' cores='4' threads='1'/>

    <numa>

      <cell id='0' cpus='0-3' memory='4194304' unit='KiB' memAccess='shared'/>

    </numa>

  </cpu>

  <clock offset='utc'>

    <timer name='rtc' tickpolicy='catchup'/>

    <timer name='pit' tickpolicy='delay'/>

    <timer name='hpet' present='no'/>

  </clock>

  <on_poweroff>destroy</on_poweroff>

  <on_reboot>restart</on_reboot>

  <on_crash>destroy</on_crash>

  <pm>

    <suspend-to-mem enabled='no'/>

    <suspend-to-disk enabled='no'/>

  </pm>

  <devices>

    <emulator>/usr/local/bin/qemu-system-x86_64</emulator>

    <disk type='file' device='disk'>

      <driver name='qemu' type='qcow2'/>

      <source file='/data/vms/vm21.img'/>

      <target dev='vda' bus='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>

    </disk>

    <disk type='file' device='cdrom'>

      <driver name='qemu' type='raw'/>

      <target dev='hda' bus='ide'/>

      <readonly/>

      <address type='drive' controller='0' bus='0' target='0' unit='0'/>

    </disk>

    <controller type='usb' index='0' model='ich9-ehci1'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci1'>

      <master startport='0'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci2'>

      <master startport='2'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci3'>

      <master startport='4'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>

    </controller>

    <controller type='pci' index='0' model='pci-root'/>

    <controller type='ide' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>

    </controller>

    <controller type='virtio-serial' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>

    </controller>

    <interface type='network'>

      <mac address='52:54:00:77:1d:e0'/>

      <source network='default'/>

      <model type='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

    </interface>

    <interface type='vhostuser'>

      <mac address='52:54:00:00:24:6b'/>

      <source type='unix' path='/tmp/vm21.sock' mode='server'/>

      <model type='virtio'/>

      <driver name='vhost' queues='4' rx_queue_size='1024' tx_queue_size='1024'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>

    </interface>

    <serial type='pty'>

      <target type='isa-serial' port='0'>

        <model name='isa-serial'/>

      </target>

    </serial>

    <console type='pty'>

      <target type='serial' port='0'/>

    </console>

    <channel type='unix'>

      <target type='virtio' name='org.qemu.guest_agent.0'/>

      <address type='virtio-serial' controller='0' bus='0' port='1'/>

    </channel>

    <input type='tablet' bus='usb'>

      <address type='usb' bus='0' port='1'/>

    </input>

    <input type='mouse' bus='ps2'/>

    <input type='keyboard' bus='ps2'/>

    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>

      <listen type='address' address='0.0.0.0'/>

    </graphics>

    <video>

      <model type='cirrus' vram='16384' heads='1' primary='yes'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>

    </video>

    <memballoon model='virtio'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>

    </memballoon>

    <rng model='virtio'>

      <backend model='random'>/dev/urandom</backend>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>

    </rng>

  </devices>

</domain>

我想把虚拟机内存改为2M,于是找到下面两行:

  <memory unit='KiB'>2029144</memory>

  <currentMemory unit='KiB'>2029144</currentMemory>

将其修改为:

  <memory unit='KiB'>4194304</memory>

  <currentMemory unit='KiB'>4194304</currentMemory>

保存退出,virsh显示一切OK:

[root@t620 SourceCode]# virsh edit vm21   
Domain vm21 XML configuration edited.

但是再次查看VM21的XML配置文件,发现这两行又恢复为原值。

经过仔细观察,发现在文档中还有一处配置:

  <cpu mode='host-passthrough' check='none'>

    <topology sockets='1' cores='4' threads='1'/>

    <numa>

      <cell id='0' cpus='0-3' memory='2029144' unit='KiB' memAccess='shared'/>

    </numa>

  </cpu>

同时修改这三处,问题解决。

 

根因: 虚拟机的XML文件要上下一致。上面定义2G内存,那么在CPU的设置中也需要用完这2G内存。否则,系统会自动恢复成自认为正确的值。

 

 

0条评论
0 / 1000
李****一
10文章数
2粉丝数
李****一
10 文章 | 2 粉丝
李****一
10文章数
2粉丝数
李****一
10 文章 | 2 粉丝
原创

使用virsh edit命令修改虚拟机内存不生效问题

2023-09-27 08:23:58
93
0

今天遇到一个问题,使用virsh edit <vm>命令调整了虚拟机的内存大小后, 保存退出,再次使用virsh edit <vm>命令查看虚拟机配置文件,发现内存又改回了先前的值。

 

我的原始配置文件是:

 

<domain type='kvm'>

  <name>vm21</name>

  <uuid>81a67c14-ae40-4c86-8b1a-0b19dfb4575b</uuid>

  <memory unit='KiB'>2029144</memory>

  <currentMemory unit='KiB'>2029144</currentMemory>

  <memoryBacking>

    <hugepages>

      <page size='2048' unit='KiB'/>

    </hugepages>

    <access mode='shared'/>

  </memoryBacking>

  <vcpu placement='static' cpuset='8,10,12,14'>4</vcpu>

  <cputune>

    <vcpupin vcpu='0' cpuset='8'/>

    <vcpupin vcpu='1' cpuset='10'/>

    <vcpupin vcpu='2' cpuset='12'/>

    <vcpupin vcpu='3' cpuset='14'/>

  </cputune>

  <resource>

    <partition>/machine</partition>

  </resource>

  <os>

    <type arch='x86_64' machine='pc-i440fx-2.2'>hvm</type>

    <boot dev='hd'/>

  </os>

  <features>

    <acpi/>

    <apic/>

  </features>

  <cpu mode='host-passthrough' check='none'>

    <topology sockets='1' cores='4' threads='1'/>

    <numa>

      <cell id='0' cpus='0-3' memory='4194304' unit='KiB' memAccess='shared'/>

    </numa>

  </cpu>

  <clock offset='utc'>

    <timer name='rtc' tickpolicy='catchup'/>

    <timer name='pit' tickpolicy='delay'/>

    <timer name='hpet' present='no'/>

  </clock>

  <on_poweroff>destroy</on_poweroff>

  <on_reboot>restart</on_reboot>

  <on_crash>destroy</on_crash>

  <pm>

    <suspend-to-mem enabled='no'/>

    <suspend-to-disk enabled='no'/>

  </pm>

  <devices>

    <emulator>/usr/local/bin/qemu-system-x86_64</emulator>

    <disk type='file' device='disk'>

      <driver name='qemu' type='qcow2'/>

      <source file='/data/vms/vm21.img'/>

      <target dev='vda' bus='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>

    </disk>

    <disk type='file' device='cdrom'>

      <driver name='qemu' type='raw'/>

      <target dev='hda' bus='ide'/>

      <readonly/>

      <address type='drive' controller='0' bus='0' target='0' unit='0'/>

    </disk>

    <controller type='usb' index='0' model='ich9-ehci1'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci1'>

      <master startport='0'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci2'>

      <master startport='2'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci3'>

      <master startport='4'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>

    </controller>

    <controller type='pci' index='0' model='pci-root'/>

    <controller type='ide' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>

    </controller>

    <controller type='virtio-serial' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>

    </controller>

    <interface type='network'>

      <mac address='52:54:00:77:1d:e0'/>

      <source network='default'/>

      <model type='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

    </interface>

    <interface type='vhostuser'>

      <mac address='52:54:00:00:24:6b'/>

      <source type='unix' path='/tmp/vm21.sock' mode='server'/>

      <model type='virtio'/>

      <driver name='vhost' queues='4' rx_queue_size='1024' tx_queue_size='1024'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>

    </interface>

    <serial type='pty'>

      <target type='isa-serial' port='0'>

        <model name='isa-serial'/>

      </target>

    </serial>

    <console type='pty'>

      <target type='serial' port='0'/>

    </console>

    <channel type='unix'>

      <target type='virtio' name='org.qemu.guest_agent.0'/>

      <address type='virtio-serial' controller='0' bus='0' port='1'/>

    </channel>

    <input type='tablet' bus='usb'>

      <address type='usb' bus='0' port='1'/>

    </input>

    <input type='mouse' bus='ps2'/>

    <input type='keyboard' bus='ps2'/>

    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>

      <listen type='address' address='0.0.0.0'/>

    </graphics>

    <video>

      <model type='cirrus' vram='16384' heads='1' primary='yes'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>

    </video>

    <memballoon model='virtio'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>

    </memballoon>

    <rng model='virtio'>

      <backend model='random'>/dev/urandom</backend>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>

    </rng>

  </devices>

</domain>

我想把虚拟机内存改为2M,于是找到下面两行:

  <memory unit='KiB'>2029144</memory>

  <currentMemory unit='KiB'>2029144</currentMemory>

将其修改为:

  <memory unit='KiB'>4194304</memory>

  <currentMemory unit='KiB'>4194304</currentMemory>

保存退出,virsh显示一切OK:

[root@t620 SourceCode]# virsh edit vm21   
Domain vm21 XML configuration edited.

但是再次查看VM21的XML配置文件,发现这两行又恢复为原值。

经过仔细观察,发现在文档中还有一处配置:

  <cpu mode='host-passthrough' check='none'>

    <topology sockets='1' cores='4' threads='1'/>

    <numa>

      <cell id='0' cpus='0-3' memory='2029144' unit='KiB' memAccess='shared'/>

    </numa>

  </cpu>

同时修改这三处,问题解决。

 

根因: 虚拟机的XML文件要上下一致。上面定义2G内存,那么在CPU的设置中也需要用完这2G内存。否则,系统会自动恢复成自认为正确的值。

 

 

文章来自个人专栏
小试牛刀
7 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0