配置并启动机密虚拟机
按照下述流程搭建好环境后,即可启动机密虚拟机。
libvirt方式启动
- 目标环境下载qcow2镜像。
cd /home wget https://repo.openeuler.org/openEuler-24.03-LTS-SP2/virtual_machine_img/aarch64/openEuler-24.03-LTS-SP2-aarch64.qcow2.xz xz -d openEuler-24.03-LTS-SP2-aarch64.qcow2.xz

- 首先启动普通虚拟机,修改guest内核启动参数,添加rodata=full。普通虚拟机配置nvm.xml内容如下。
<domain type='kvm' xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <name>nvm</name> <memory unit='GiB'>8</memory> <vcpu placement='static'>4</vcpu> <cputune> <vcpupin vcpu='0' cpuset='0'/> <vcpupin vcpu='1' cpuset='1'/> <vcpupin vcpu='2' cpuset='2'/> <vcpupin vcpu='3' cpuset='3'/> <emulatorpin cpuset='0-3'/> </cputune> <numatune> <memnode cellid='0' mode='strict' nodeset='0'/> </numatune> <os> <type arch='aarch64' machine='virt'>hvm</type> <loader readonly='yes' type='rom'>/home/edk2/Build/ArmVirtQemu-AARCH64/RELEASE_GCC5/FV/QEMU_EFI.fd</loader> <boot dev='hd'/> </os> <features> <acpi/> <gic version='3'/> </features> <cpu mode='host-passthrough'> <topology sockets='1' dies='1' clusters='1' cores='4' threads='1'/> <numa> <cell id='0' cpus='0-3' memory='8' unit='GiB'/> </numa> </cpu> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/home/qemu/build/qemu-system-aarch64</emulator> <console type='pty'/> <disk type='file' device='disk' model='virtio-non-transitional'> <driver name='qemu' type='qcow2' queues='2' cache='none' iommu='on'/> <source file='/home/openEuler-24.03-SP2-cvm-aarch64.qcow2'/> <target dev='vda' bus='virtio'/> </disk> <interface type='bridge'> <source bridge='virbr0'/> <driver iommu='on' event_idx='off'/> <rom bar='off' file=''/> <model type='virtio-non-transitional'/> </interface> </devices> </domain> - 启动普通虚拟机,登录到Guest OS。
virsh define nvm.xml virsh start nvm --console
- 在Guest OS中修改启动引导配置文件,目标内核的启动参数添加“rodata=full”。
vim /boot/efi/EFI/openEuler/grub.cfg

- 创建并编辑libvirt启动机密虚拟机的cvm.xml,编辑内容如下。
<domain type='kvm' xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <name>cvm</name> <memory unit='GiB'>8</memory> <vcpu placement='static'>4</vcpu> <cputune> <vcpupin vcpu='0' cpuset='0'/> <vcpupin vcpu='1' cpuset='1'/> <vcpupin vcpu='2' cpuset='2'/> <vcpupin vcpu='3' cpuset='3'/> <emulatorpin cpuset='0-3'/> </cputune> <numatune> <memnode cellid='0' mode='strict' nodeset='0'/> </numatune> <os> <type arch='aarch64' machine='virt'>hvm</type> <loader readonly='yes' type='rom'>/home/edk2/Build/ArmVirtQemu-AARCH64/RELEASE_GCC5/FV/QEMU_EFI.fd</loader> <boot dev='hd'/> </os> <features> <acpi/> <gic version='3'/> </features> <cpu mode='host-passthrough'> <topology sockets='1' dies='1' clusters='1' cores='4' threads='1'/> <numa> <cell id='0' cpus='0-3' memory='8' unit='GiB'/> </numa> </cpu> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/home/qemu/build/qemu-system-aarch64</emulator> <console type='pty'/> <disk type='file' device='disk' model='virtio-non-transitional'> <driver name='qemu' type='qcow2' queues='2' cache='none' iommu='on'/> <source file='/home/openEuler-24.03-SP2-cvm-aarch64.qcow2'/> <target dev='vda' bus='virtio'/> </disk> <interface type='bridge'> <source bridge='virbr0'/> <driver iommu='on' event_idx='off'/> <rom bar='off' file=''/> <model type='virtio-non-transitional'/> </interface> </devices> <launchSecurity type='cca'/> </domain>
在nvm.xml配置的基础上,cvm.xml新增:
<launchSecurity type='cca'/>
- cputune中emulatorpin的cpuset范围要与vcpupin的cpuset范围重合,否则会出现ttyAMA0超时问题。
- 对于频繁启动销毁机密虚拟机等压力测试场景,推荐关闭virtio-net的event_idx机制以提升virtio网络稳定性,配置示例如下。
<interface type='bridge'> <source bridge='virbr0'/> <driver iommu='on' event_idx='off'/> <model type='virtio-non-transitional'/> </interface>
- 使用virsh define定义虚拟机配置。
virsh define cvm.xml

- 执行以下命令查看虚拟机定义。
virsh list --all
Name与xml中<name>cvm</name>一致。

- 关闭SELinux,详情可参见SELinux配置。
- 执行以下命令启动机密虚拟机。
virsh start cvm

- 执行以下命令进入机密虚拟机串口。
virsh console cvm

镜像默认用户为root。
使能多NUMA
在libvirt方式启动的步骤2创建的机密虚拟机xml基础上修改配置。
- 支持虚拟NUMA node绑定一个物理NUMA范围。虚拟机安全内存将会在指定NUMA范围内分配,libvirt虚拟机配置中关于绑定物理NUMA范围示例如下。
<numatune> <memnode cellid='0' mode='strict' nodeset='1-3' /> </numatune>
对于上述配置,虚拟机安全内存将会尝试在NUMA 1、2、3上分配。等价写法为:nodeset='1,2,3'。
- 支持在多NUMA上分配安全内存,以支持启动大虚拟机,配置示例如下。
<numatune> <memnode cellid='0' mode='strict' nodeset='0' /> <memnode cellid='1' mode='strict' nodeset='3' /> </numatune> <cpu mode='host-passthrough'> <topology sockets='1' dies='1' clusters='1' cores='8' threads='1'/> <numa> <cell id='0' cpus='0-3' memory='4' unit='GiB'/> <cell id='1' cpus='4-7' memory='4' unit='GiB'/> </numa> </cpu>- 对于上述配置,机密虚拟机将在NUMA 0和NUMA 3上各分配4GB安全内存。
- 配置示例中vCPU的数量为8,cvm.xml中对应配置修改如下:<vcpu placement='static'>8</vcpu>。
父主题: 部署软件