averainy's Blog

averainy

17 Jan 2024

kvm虚拟机迁移操作手册(从Fedora39到Redhat9)

kvm虚拟机迁移操作手册(从Fedora39到Redhat9)

查看要迁移的虚拟机名

[root@kvm-179 ~]# virsh list --all
 Id   Name               State
-----------------------------------
 1    a            running
 3    b       running
 4    c     running
 5    d       running
 6    e                running
 7    f            running
 8    g            running
 9    g     running
 10   d     running
 12   f         running
 13   d            running
 14   f     running
 -    a              shut off
 -    b              shut off
 -    test   shut off
 -    a             shut off

导出 xml文件

[root@kvm-179 ~]# virsh dumpxml test > test.xml

将xml复制到目标服务器

scp test.xml [email protected]:~/

查看需要迁移的虚拟机硬盘文件

[root@kvm-179 ~]# virsh domblklist test
 Target   Source
----------------------------------------------------------------
 vda      /home/kvm/data/test/test-sda
 sda      -

将虚拟机硬盘文件复制到目标机器

scp /home/kvm/data/test/test-sda [email protected]:/home/kvm/data_store2/

修改xml文件

  • 修改domain->devices->emulator
    修改前:
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    修改后:
    <emulator>/usr/libexec/qemu-kvm</emulator>
    
  • 修改domain->os->type
    修改前:
    <type arch='x86_64' machine='pc-q35-6.1'>hvm</type>
    修改后:
    <type arch='x86_64' machine='pc-q35-rhel9.0.0'>hvm</type>
    
  • 修改domain->os->loader(如果有这个标签的话)
    修改前:
    <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
    修改后:
    <loader readonly='yes' type='pflash'>/usr/share/edk2/ovmf/OVMF_CODE.fd</loader>
    
  • 修改domain->devices->disk->source
    修改前:
    <source file='/home/kvm/data/test/test-sda'/>
    修改后:
    <source file='/home/kvm/data_store2/test-sda'/>
    
  • 注册虚拟机
    [root@kvm-150 ~]# virsh define test.xml
    Domain 'test' defined from test.xml