kvm 修改虚拟机名称

kvm修改虚拟机名称

关闭虚拟机

注意:如果虚拟机有快照需要先删除快照!

virsh list --all

virsh shutdown test_66.124

正常关闭后,虚拟机状态state为:shut off

修改配置文件名称

cd /etc/libvirt/qemu 
mv test_66.124.xml wugang_test_66.124.xml

修改配置文件内容

<name>wugang_test_66.121</name> //虚拟机名称

删除原有的虚拟机

virsh undefine test_66.124

使用现有的文件创建虚拟机,其实就是改名

virsh define wugang_test_66.124.xml

然后启动虚拟机即可

virsh start wugang_test_66.124

启动后的虚拟机中的任何都不会做改变,只是虚拟机的名称发生了变化

xml 配置文件详情2

<domain type='kvm'>
    <name>wugang_test_66.121</name> //虚拟机名称
    <memory unit='MiB'>2300</memory> //最大内存,单位M
    <currentMemory unit='MiB'>2300</currentMemory> //可用内存,单位M
    <vcpu>3</vcpu> //虚拟cpu个数
    <os>
      <type arch='x86_64' machine='pc'>hvm</type>
      <boot dev='hd'/> //硬盘启动
   </os>
   <features>
      <acpi/>
      <apic/>
      <pae/>
   </features>
   <clock offset='localtime'/>
   <on_poweroff>destroy</on_poweroff>
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
     <emulator>/usr/libexec/qemu-kvm</emulator>
     <disk type='file' device='disk'>
       <driver name='qemu' type='raw'/>
       <source file='/home/kvm/images/vm64-1.raw'/> //目的镜像路径
       <target dev='vda' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> /*硬盘使用virtio驱动后识别为pci总线*/
     </disk>
     <disk type='file' device='disk'>
       <driver name='qemu' type='raw'/>
       <source file='/home/kvm/images/ex.img'/> //目的镜像路径
       <target dev='vdb' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/> /*硬盘使用virtio驱动后识别为pci总线*/
     </disk>
    <interface type='bridge'> //虚拟机网络连接方式
      <source bridge='vm1_br_debug'/> //当前主机网桥的名称 vm-eth0
      <virtualport type='openvswitch'/>
      <model type='virtio'/>
      <driver name='vhost' queues='8'/>
      <mac address="00:16:3E:64:01:00"/> //为虚拟机分配mac地址,务必唯一,否则dhcp获得同样ip,引起冲突
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </interface>
    <interface type='bridge'> //虚拟机网络连接方式
      <source bridge='vm1_br_protocol'/> //当前主机网桥的名称  vm-eth1
      <virtualport type='openvswitch'/>
      <model type='virtio'/>
      <driver name='vhost' queues='8'/>
      <mac address="00:16:3E:64:01:01"/> //为虚拟机分配mac地址,务必唯一,否则dhcp获得同样ip,引起冲突
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </interface>     
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>//vnc方式登录,端口号自动分配,自动加1,可以通过virsh vncdisplay来查询
   </devices>
</domain>
posted @ 2024-05-28 11:45  liwenchao1995  阅读(19)  评论(0编辑  收藏  举报