使用命令创建虚拟机uos,自动化创建

1、qemu-img create -f qcow2 ./1020uos.qcow2 70G    (1)生成硬盘镜像文件     用qemu创建一块硬盘,作为系统盘用来装OS
  qemu-img create -f  raw 1020-uos-2.img 70G     (1)生成硬盘镜像文件     用qemu创建一块硬盘,作为系统盘用来装OS
qemu-img info 1020uos.qcow2 查看你的镜像文件 2、编写xml配置文件1020-uos-2.xml
<domain type='kvm'> <name>test1-1020</name> //虚拟机名称 <memory>1048576</memory> //最大内存,单位k <currentMemory>1048576</currentMemory> //可用内存,单位k <vcpu>1</vcpu> //虚拟cpu个数 <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='cdrom'/> //光盘启动 </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/bin/qemu-system-x86_64</emulator> <disk type='file' device='cdrom'> <source file='/home/tarzan/Downloads/image/uniontechos-20-desktop-professional-1020-amd64.iso'/> //光盘镜像路径 <target dev='hdb' bus='ide'/> </disk> <disk type="file" device="disk"> <driver name="qemu" type="raw"/> <source file="/home/tarzan/Downloads/image/virsh_test/1020-uos-2.img"/> //这里把硬盘位置放上 <target dev="sda" bus="virtio"/> <alias name="virtio-disk0"/> </disk> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' listen = '0.0.0.0' keymap='en-us'/>//vnc方式登录,端口号自动分配,自动加1,可以通过virsh vncdisplay来查询 </devices> </domain> 3、创建并运行虚拟机 sudo apt-get install qemu-kvm virsh create ./1020-uos-2.xml //创建虚拟机 3.1 查看虚拟机 $ virsh list Id Name State ---------------------------- 1 test1-1020 running 4、查看你的虚拟机端口 virsh vncdisplay --domain test1-1020 :0 //我们刚查到虚拟机的vnc端口为0,qemu会给端口补个590也就是,我们这里链接5900 这里还有一个方法查看: $ virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # list Id Name State ---------------------------- 1 test1-1020 running virsh # vncdisplay 1 :0 5、连接虚拟机 vncviewer localhost:0
(1)生成硬盘镜像文件     用qemu创建一块硬盘,作为系统盘用来装OS
原文地址:https://www.cnblogs.com/tarzen213/p/13643874.html