Kvm命令集管理虚拟机
KVM虚拟机配置文件位置
[root@localhost ~]# ll /etc/libvirt/qemu/ 总用量 4 drwxr-xr-x 2 root root 23 12月 14 20:23 autostart drwx------ 3 root root 42 12月 14 19:38 networks -rw------- 1 root root 4074 12月 14 20:23 test2.xml
修改KVM虚拟机配置的方法
[root@localhost ~]# virsh edit test2
备份与恢复
备份虚拟机配置(关机时备份):
[root@localhost ~]# virsh dumpxml test2 > test2.xml
删除虚拟机配置
[root@localhost ~]# virsh list --all Id 名称 状态 ---------------------------------------------------- 2 test01 running 4 test2 running [root@localhost ~]# virsh undefine test01
导入虚拟机
[root@localhost ~]# virsh define test2.xml
定义域 test2(从 test2.xml)
修改虚拟机名称
[root@localhost ~]# virsh domrename test2 liujunjun
虚拟机挂起与恢复
[root@localhost ~]# virsh suspend test2 域 test2 被挂起 [root@localhost ~]# virsh list --all Id 名称 状态 ---------------------------------------------------- 2 test01 running 4 test2 暂停 [root@localhost ~]# virsh resume test2 域 test2 被重新恢复
查询虚拟机vnc端口
[root@localhost ~]# virsh vncdisplay test2 :10050
开机自启动设置
[root@localhost ~]# systemctl is-enabled libvirtd.service
enabled
设置宿主机开机虚拟机开机
[root@localhost ~]# virsh autostart test2
域 test2标记为自动开始
取消开机自启动
[root@localhost ~]# virsh autostart --disable test2
域 test2取消标记为自动开始
kvm虚拟机console登录
CentOS 7.X 版本console登录
配置console登录
在test2虚拟机内操作(该操作仅限centos7):
[root@localhost ~]# grubby --update-kernel=ALL --args="console=ttyS0,115200n8"
[root@localhost ~]# reboot
[root@localhost ~]# virsh console test2
连接到域 test2
换码符为 ^]
创建一块qcow2的虚拟硬盘为2GB
[root@localhost ~]# qemu-img create -f qcow2 qcow2-ceshi 2GB qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suffixes for qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
查看当前虚拟机硬盘信息
[root@localhost kvm-bak2]# qemu-img info /home/kvm-bak2/test2.img image: /home/kvm-bak2/test2.img file format: qcow2 virtual size: 10G (10737418240 bytes) disk size: 1.2G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: true
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?