centos KVM

  1. 安装对应软件包

root@etxtest2 \~\]# yum -y install qemu-kvm \[root@etxtest2 \~\]# yum -y install libvirt-daemon \[root@etxtest2 \~\]# yum -y install libvirt-client \[root@etxtest2 \~\]# yum -y install libvirt-daemon-driver-qemu.x86_64 \[root@etxtest2 \~\]# yum -y install virt-manager

2.安装后可以通过virt-manager来启动图

  • 新建一台虚拟机,安装OS即可,此步骤忽略
  • virsh命令,进入交互模式

root@etxtest2 \~\]# virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # > 纯命令模式: > > 常用命令: > > virsh list #正在运行的虚拟机 > > virsh list --all > > virsh dominfo xxx #查看虚拟机信息 > > virsh autostart xxx > > virsh autostart --disable xxx > > virsh shutdown xxx > > virsh destroy xxx #强制关闭 > > virsh reboot xxx > > virsh start xxx > > 虚拟机的配置文件及磁盘文件 > > ![](https://i-blog.csdnimg.cn/direct/80a9dbf1b13044ab8781ece0fd379e45.png) > > 使用virsh查看虚拟机的xml描述信息 > > virsh dumpxml xxx > 3.新建一台虚拟机:需要准备两个文件,一个xml文件,一个磁盘文件 > root@build:/global/softwaredata/kvm/ubuntu# cp 2504-clone.qcow2 wenwutest.qcow2 > > root@build:/etc/libvirt/qemu# cp ubuntu25.04-clone.xml wenwutest.xml xml文件里面有**四个**地方需要修改 其中uuid可以通过三中方法来实现 网卡可以通过1和3来实现 1.直接修改里面的值 2.uuidgen命令来生成一个uuid 3.直接删除这行,系统启动的时候会自动生成uuid > \wenwutest\ > > \349bfeae-bb1f-4105-ba11-f508bd923222\ > > \ > > \ 把新建的虚拟机导入: root@build:/etc/libvirt/qemu# virsh define /etc/libvirt/qemu/wenwutest.xml #导入 root@build:\~# virsh list --all Id Name State -------------------------------------------------- 1 zhangchengyue-virtual-usb-clone running 2 linan running 3 zhangyongliang running 9 fanwenyang running - fanwenyang-virtual-usb shut off - flower shut off - ubuntu25.04-clone shut off **- wenwutest shut off** - wll shut off root@build:\~# virsh start wenwutest #启动虚拟机 取消导入:仅仅删除xml文件 root@build:/etc/libvirt/qemu# virsh undefine /etc/libvirt/qemu/wenwutest.xml 但是磁盘镜像没有删除 4.COW写时复制 ![](https://i-blog.csdnimg.cn/direct/85b7b98978f344bfa5be581398bb632e.png) ![](https://i-blog.csdnimg.cn/direct/f3f4cc0219e14cbea23ec33834294061.png) > root@build:/global/softwaredata/kvm/ubuntu# qemu-img create -f qcow2 -b /global/softwaredata/kvm/ubuntu/2504-clone.qcow2 /global/softwaredata/kvm/ubuntu/test01.qcow2 -F qcow2 100G > > root@build:/global/softwaredata/kvm/ubuntu# qemu-img info test01.qcow2 #可以看到实际占用大小不到1M > root@build:/etc/libvirt/qemu# virsh edit ubuntu25.04-clone #修改四个地方 > > root@build:\~# virsh start test01 > > Domain 'test01' started ![](https://i-blog.csdnimg.cn/direct/440e5bd13487451bad314764512fdc14.png) 删除: > root@build:/global/softwaredata/kvm/ubuntu# virsh shutdown test01 > > Domain 'test01' is being shutdown > > root@build:/global/softwaredata/kvm/ubuntu# virsh undefine test01 > > Domain 'test01' has been undefined > > rm -rf /global/softwaredata/kvm/ubuntu/test01.qcow2 5.虚拟机关机的时候,离线访问里面的资源 guestmount ![](https://i-blog.csdnimg.cn/direct/8302572ec38e4c9c973f619254792042.png) ![](https://i-blog.csdnimg.cn/direct/b97ee0adafd84f56a2d21ca50b3e103d.png)

相关推荐
t198751286 小时前
在Ubuntu 22.04系统上安装libimobiledevice
linux·运维·ubuntu
skywalk81636 小时前
linux安装Code Server 以便Comate IDE和CodeBuddy等都可以远程连上来
linux·运维·服务器·vscode·comate
@游子7 小时前
内网渗透笔记-Day5
运维·服务器
晚风吹人醒.7 小时前
缓存中间件Redis安装及功能演示、企业案例
linux·数据库·redis·ubuntu·缓存·中间件
记得记得就1517 小时前
【Nginx 性能优化与防盗链】
运维·nginx·性能优化
Yawesh_best7 小时前
告别系统壁垒!WSL+cpolar 让跨平台开发效率翻倍
运维·服务器·数据库·笔记·web安全
roman_日积跬步-终至千里7 小时前
【Docker】Docker Stop 后到底发生了什么?——从信号机制到优雅停机
运维·docker·容器
喵手7 小时前
云端智变:基于 DevUI 与 MateChat 打造下一代云原生智能运维中台实战教学!
运维·云原生·devui·matechat
Hard but lovely7 小时前
linux: pthread库的使用和理解
linux
小五传输8 小时前
常用的文件摆渡系统:让数据安全高效跨越网络界限
大数据·运维·安全