FT2000+ openEuler 20.03 virsh创建qemu kvm虚拟机 启动qemu kvm

安装qemu、libvirt

yum install libvirt libvirt-client -y
yum install qemu -y

安装固件包

yum install edk2-aarch64

固件文件

配置/etc/libvirt/libvirtd.conf 

auth_tcp = "sasl"
listen_tcp = 1
listen_tls = 0
tcp_port = "16509"
unix_sock_dir = "/run/libvirt"

配置/etc/libvirt/qemu.conf

nvram = [
   "/usr/share/edk2/aarch64/QEMU_EFI.fd:/usr/share/edk2/aarch64/QEMU_VARS.fd",
   "/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw:/usr/share/edk2/aarch64/vars-template-pflash.raw"
]

启动服务

systemctl enable libvirtd --now
systemctl enable libvirt-guests --now

其中libvirt-client提供了virsh指令

使用原来的镜像

创建过程失败,采用原来的镜像。后续在研究

FT2000+ openEuler 20.03 LTS SP3 yum install qemu手动创建虚拟机 图形界面安装openEuler 20.03系统_hkNaruto的博客-CSDN博客

创建配置

<domain type='kvm'>  //如果是Xen,则type=‘xen’
  
    
    <name>redflag1</name> //虚拟机名称,同一物理机唯一
  
    
    <uuid>44748c15-7c00-4817-8724-675a27c3f821</uuid>  //同一物理机唯一,可用uuidgen生成
  
    
    <memory>67108864</memory>
    <currentMemory>67108864</currentMemory>  //memory这两个值最好设成一样
  
    
    <vcpu>64</vcpu>
    <cpu mode="host-passthrough"/>
    <os>
        <type arch='aarch64' machine='virt'>hvm</type>
        <loader readonly='yes' type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw</loader>
        <nvram template='/usr/share/edk2/aarch64/vars-template-pflash.raw'>/usr/share/edk2/aarch64/QEMU_VARS.fd</nvram>
    </os>
    <features>
        <acpi/>
        <apic/>
        <pae/>
    </features>
    <clock offset='localtime'/>  //虚拟机时钟设置,这里表示本地本机时间
  
    
    <on_poweroff>destroy</on_poweroff>  //突发事件动作
  
    
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <devices>   //设备配置
        
        <emulator>/usr/bin/qemu-kvm</emulator> //如果是Xen则是/usr/lib/xen/binqemu-dm            
        
        <controller type="scsi" index="0" model="virtio-scsi"/>
        <controller type='usb' index='0' model='qemu-xhci' ports='15'/>
        <input type='keyboard' bus='usb'/>
        <input type='mouse' bus='usb'/>
        <input type='tablet' bus='usb'/>

        <disk type='file' device='cdrom'>//光盘
      
            
            <driver name='qemu' type='raw'/>
            <source file='/home/yeqiang/RedFlag-Asianux-Server-7.5-aarch64-for-Phytium-dvddisc-20210701.iso'/>
            <target dev='hda' bus='scsi'/>
            <readonly/>
        </disk>

        <disk type='file' device='disk'> //硬盘      
            
            <driver name='qemu' type='qcow2'/>
            <source file='/home/yeqiang/qemu-virtual-machine/redflag.qcow2'/>
            <target dev='vda' bus='virtio'/>
        </disk>
                <graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0' keymap='en-us'>  //配置vnc,windows下可以使用vncviewer登录,获取vnc端口号:virsh vncdisplay vm0
     
            
            <listen type='address' address='0.0.0.0'/>
        </graphics>
    </devices>
</domain>

define

virsh define redflag.xml

查看

 启动虚拟机

virsh start redflag1

再次查看状态

 

故障

错误:unsupported configuration: ACPI requires UEFI on this architecture

<cpu mode="host-passthrough"/>

vnc无输出,虚拟机未正常启动

制定bios

<os>
    <type arch='aarch64' machine='virt'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw</loader>
    <nvram template='/usr/share/edk2/aarch64/vars-template-pflash.raw'>/usr/share/edk2/aarch64/QEMU_VARS.fd</nvram>
  </os> 

错误:internal error: qemu unexpectedly closed the monitor: 2023-04-18T08:05:31.354981Z qemu-kvm: Initialization of device cfi.pflash01 failed: device requires 67108864 bytes, block backend provides 786432 bytes

备份,修改大小 

cp /usr/share/edk2/aarch64/QEMU_VARS.fd /usr/share/edk2/aarch64/QEMU_VARS.fd.bak
qemu-img resize -f raw /usr/share/edk2/aarch64/QEMU_VARS.fd 64M

修改效果

没有键盘鼠标

 

 配置

<devices>节点添加

<input type='keyboard' bus='virtio'/>
<input type='tablet' bus='virtio'/>

USB is disabled for this domain, but USB devices are present in the domain XML

 参考官方文档

https://libvirt.org/formatdomain.html#input-devices

虚拟硬盘还未装系统时,卡在UEFI SHELL

实测无效

 参考

https://libvirt.org/formatdomain.html#operating-system-booting

<os>
  <type>hvm</type>
  <boot dev='cdrom'/>
  <bootmenu enable='yes' timeout='3000'/>
  <smbios mode='sysinfo'/>
  <bios useserial='yes' rebootTimeout='0'/>
</os>

BIOS阶段键盘无响应

  <bootmenu enable='yes' timeout='30000'/>

此时,键盘F12无响应。

参考:ARM服务器创建虚机遇到的坑 - 简书

解决:以下配置只能在内核启动后生效,需要内核驱动

        <input type='keyboard' bus='virtio'/>
        <input type='tablet' bus='virtio'/>

改为

    <controller type="scsi" index="0" model="virtio-scsi"/>
    <controller type='usb' index='0' model='qemu-xhci' ports='15'/>
    <input type='keyboard' bus='usb'/>
    <input type='mouse' bus='usb'/>
    <input type='tablet' bus='usb'/>

参考:

从QEMU到libvirt(virsh) - 添加USB端口 - VoidCC

virsh命令来创建虚拟机

ARM虚拟化环境搭建_edk2-aarch64_享乐主的博客-CSDN博客

https://www.cnblogs.com/winstom/p/15074737.html

关于虚拟化:KVM和libvirt:虚拟主机中的CPU类型错误 | 码农家园

qemu-kvm: Initialization of device cfi.pflash01 failed_whz-emm的博客-CSDN博客​​​​​​

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值