libvirt创建KVM虚拟机

1 安装虚拟化相关组件

yum -y install qemu-img qemu-kvm  libvirt

2 启动libvirt服务

systemctl  start libvirtd

3 配置xml,创建空镜像

qemu-img create -f qcow2  test.qcow2  20G
复制代码
<domain type='kvm'> 
    <name>test_jkk</name> 
    <memory>1048576</memory> 
    <currentMemory>1048576</currentMemory>
    <vcpu>1</vcpu>
    <os> 
      <type arch='x86_64' machine='pc'>hvm</type> 
      <boot dev='cdrom'/>
<boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='localtime'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/home/kvm/test.qcow2'/> <target dev='hda' bus='ide'/> </disk> <disk type='file' device='cdrom'> <source file='/home/kvm/centos_minimal.iso'/> <target dev='hdb' bus='ide'/> </disk> <interface type='bridge'> <source bridge='virbr0'/> </interface> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/> </devices> </domain>
复制代码

4  定义启动虚拟机

virsh define test.xml
virsh start  test_jkk
virsh  vncdisplay   test_jkk  查看虚拟机vnc串口
virsh domblklist demo 查看虚拟机的磁盘文件
virsh dumpxml demo 查看虚拟机xml

 

posted on   思此狂  阅读(881)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示