当前位置: 首页 > news >正文

使用xml文件创建虚拟机

一、安装相关软件

yum install virt-manager qemu libvirt -y 

启动libvirt服务

systemctl start libvirtd.service
systemctl status libvirtd.service

下载虚拟机相关iso并上传至/var/lib/libvirt/images/目录下

二、xml文件编写

编写一个node1.xml文件并放在/etc/libvirt/qemu目录下
xml文件参考:

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:virsh edit node1
or other application using the libvirt API.
--><domain type='kvm'><name>node1</name><memory unit='KiB'>5023744</memory><currentMemory unit='KiB'>5023744</currentMemory><vcpu placement='static'>4</vcpu><os firmware='efi'><type arch='loongarch64' machine='virt'>hvm</type></os><features><acpi/></features><clock offset='utc'/><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot><on_crash>destroy</on_crash><devices><emulator>/usr/bin/qemu-system-loongarch64</emulator><disk type='file' device='disk'><driver name='qemu' type='qcow2' discard='unmap'/><source file='/var/lib/libvirt/images/node1.qcow2'/><target dev='vda' bus='virtio'/><boot order='2'/></disk><disk type='file' device='cdrom'><driver name='qemu' type='raw'/><source file='/var/lib/libvirt/images/loongnix-23.1-GA-loongarch64-dvd.iso'/><target dev='sda' bus='scsi'/><readonly/><boot order='1'/></disk><interface type='network'><source network='default'/><model type='virtio'/></interface><serial type='pty'><target type='system-serial' port='0'><model name='16550a'/></target></serial><console type='pty'><target type='serial' port='0'/></console><channel type='unix'><target type='virtio' name='org.qemu.guest_agent.0'/></channel><input type='keyboard' bus='usb'><address type='usb' bus='0' port='1'/></input><input type='tablet' bus='usb'><address type='usb' bus='0' port='2'/></input><graphics type='vnc' port='-1' autoport='yes'><listen type='address'/></graphics></devices>
</domain>

注释:
需要加入keyboard和tablet/mouse的设备,否则在虚拟机安装启动过程中,鼠标和键盘无法正常使用

三、创建磁盘映像

qemu-img create -f qcow2 /var/lib/libvirt/images/node1.qcow2 20G

/var/lib/libvirt/images/为文件存放的路径(跟xml文件中的设置保持一致)
20G为磁盘映像镜像的大小

四、创建启动虚拟机

1、从xml配置文件定义一个虚拟机

virsh define node1.xml
  • 在执行该命令后,需要将node1.xml文件中的scsi的控制器model从lsilogic,修改为virtio-scsi,否则在安装启动虚拟机时,无法正常进入grub

scsi控制器示例如下:

 <controller type='scsi' index='0' model='lsilogic'><address type='pci' domain='0x0000' bus='0x04' slot='0x01' function='0x0'/></controller>

2、启动虚拟机

virsh start node1
virsh reboot node1

node1为xml文件中定义的虚拟机名称

3、安装虚拟机

在终端启动virt-manager图形管理工具进行虚拟机安装

virt-manager

4、删除虚拟机

virsh shutdown node1    #停止虚拟机(通过发送ACPI关机信号)
virsh undefine node1   #删除虚拟机(仅删除虚拟机定义,不删除磁盘文件)
virsh destroy node1   #强制关闭虚拟机
rm -rf node1.qcow2      #删除磁盘映像
rm -rf loongnix-23.1-GA-loongarch64-dvd.iso   #删除iso

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【C++】容器
  • 数据结构与算法图论 并查集
  • 【c++】类和对象详解
  • 智能优化算法-鼠群优化算法(RSO)(附源码)
  • Vue 获取参数
  • (20)docke容器
  • JDK22一些新特性
  • 空间数据库概述
  • JS获取URL参数的几种方法
  • swift:qwen2 VL 多模态图文模型lora微调swift
  • 在ros中进行无人机和无人车之间的通信(代码)
  • iframe详解和用途解读
  • WiFi性能测试是评估无线网络性能的重要环节,它涵盖了多个方面的指标,如信号强度、网络速度、延迟时间等。
  • C语言从头学55——学习头文件errno.h、float.h
  • 构建Vue项目的侧边栏组件:Aside
  • 【EOS】Cleos基础
  • Brief introduction of how to 'Call, Apply and Bind'
  • Fundebug计费标准解释:事件数是如何定义的?
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • Invalidate和postInvalidate的区别
  • Javascript设计模式学习之Observer(观察者)模式
  • Laravel5.4 Queues队列学习
  • Less 日常用法
  • Linux Process Manage
  • Linux快速配置 VIM 实现语法高亮 补全 缩进等功能
  • Logstash 参考指南(目录)
  • nodejs实现webservice问题总结
  • Python打包系统简单入门
  • Web设计流程优化:网页效果图设计新思路
  • 从零开始的webpack生活-0x009:FilesLoader装载文件
  • 浮现式设计
  • 高性能JavaScript阅读简记(三)
  • 基于遗传算法的优化问题求解
  • 解决jsp引用其他项目时出现的 cannot be resolved to a type错误
  • 面试题:给你个id,去拿到name,多叉树遍历
  • 区块链共识机制优缺点对比都是什么
  • 如何用Ubuntu和Xen来设置Kubernetes?
  • 三栏布局总结
  • 使用权重正则化较少模型过拟合
  • 数组大概知多少
  • 微服务入门【系列视频课程】
  • # Spring Cloud Alibaba Nacos_配置中心与服务发现(四)
  • $ git push -u origin master 推送到远程库出错
  • (ISPRS,2021)具有遥感知识图谱的鲁棒深度对齐网络用于零样本和广义零样本遥感图像场景分类
  • (MTK)java文件添加简单接口并配置相应的SELinux avc 权限笔记2
  • (Redis使用系列) Springboot 使用redis实现接口幂等性拦截 十一
  • (solr系列:一)使用tomcat部署solr服务
  • (六)库存超卖案例实战——使用mysql分布式锁解决“超卖”问题
  • (免费领源码)python#django#mysql校园校园宿舍管理系统84831-计算机毕业设计项目选题推荐
  • (四)c52学习之旅-流水LED灯
  • (转)程序员疫苗:代码注入
  • (轉貼) UML中文FAQ (OO) (UML)
  • ... fatal error LINK1120:1个无法解析的外部命令 的解决办法
  • .bat批处理(四):路径相关%cd%和%~dp0的区别
  • .NET Conf 2023 回顾 – 庆祝社区、创新和 .NET 8 的发布