安装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指令
管理已存在的qemu虚拟机
创建配置
<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> //arch指出系统架构类型,machine 则是机器类型,查看机器类型:qemu-system-x86_64 -M ?
<boot dev='hd'/> //启动介质,第一次需要装系统可以选择cdrom光盘启动
<bootmenu enable='yes'/> //表示启动按F12进入启动菜单
</os>
<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
<disk type='file' device='disk'> //硬盘
<driver name='qemu' type='qcow2'/>
<source file='/home/yeqiang/qemu-virtual-machine/redflag.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x00' function='0x0'/> //域、总线、槽、功能号,slot值同一虚拟机上唯一
</disk>
<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='hdc' bus='scsi'/>
<readonly/>
</disk>
</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='tablet' bus='usb'/>
<input type='keyboard' bus='usb'/>
USB is disabled for this domain, but USB devices are present in the domain XML
未完待续。。。
参考:
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博客